Rapl node capping daemon #21
|
@ -10,7 +10,7 @@ import (
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
|
|
||||||
const powercapDir = "/sys/class/powercap/"
|
const powercapDir = "/sys/class/powercap/"
|
||||||
|
|
||||||
// Cap is a payload that is expected from Elektron to cap a node
|
// Cap is a payload that is expected from Elektron to cap a node.
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
type Cap struct {
|
type Cap struct {
|
||||||
Percentage int
|
Percentage int
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,13 @@ func main() {
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
log.Fatal(http.ListenAndServe(":9090", nil))
|
log.Fatal(http.ListenAndServe(":9090", nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler powercapping HTTP API endpoint
|
// Handler for the powercapping HTTP API endpoint.
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() error messages should be lowercase. error messages should be lowercase.
![]() In this case this is some http content being served back to to the client that made the request. I did make it lower case though. In this case this is some http content being served back to to the client that made the request. I did make it lower case though.
|
|||||||
func powercapEndpoint(w http.ResponseWriter, r *http.Request) {
|
func powercapEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload Cap
|
var payload Cap
|
||||||
decoder := json.NewDecoder(r.Body)
|
decoder := json.NewDecoder(r.Body)
|
||||||
err := decoder.Decode(&payload)
|
err := decoder.Decode(&payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Error parsing payload: "+err.Error(), 400)
|
http.Error(w, "error parsing payload: "+err.Error(), 400)
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,5 +40,5 @@ func powercapEndpoint(w http.ResponseWriter, r *http.Request) {
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "Capped node at %d percent", payload.Percentage)
|
fmt.Fprintf(w, "capped node at %d percent", payload.Percentage)
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
|||||||
}
|
}
|
||||||
|
|
||||||
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
![]() missing period at the end of the sentence. missing period at the end of the sentence.
![]() missing period at end of sentence. missing period at end of sentence.
|
missing period at the end of the sentence.
missing period at end of sentence.