Skip to content

Commit

Permalink
use json template in iowait example, as it's clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Apr 12, 2016
1 parent a9aaac0 commit 3865e0f
Showing 1 changed file with 30 additions and 36 deletions.
66 changes: 30 additions & 36 deletions examples/plugins/iowait/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"encoding/json"
"flag"
"fmt"
"log"
Expand Down Expand Up @@ -75,41 +74,36 @@ func (p *Plugin) Report(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = json.NewEncoder(w).Encode(map[string]interface{}{
"Host": map[string]interface{}{
"nodes": map[string]interface{}{
p.HostID + ";<host>": map[string]interface{}{
"metrics": map[string]interface{}{
"iowait": map[string]interface{}{
"samples": []interface{}{
map[string]interface{}{
"date": nowISO,
"value": value,
},
},
},
},
},
},
"metric_templates": map[string]interface{}{
"iowait": map[string]interface{}{
"id": "iowait",
"label": "IO Wait",
"format": "percent",
"priority": 0.1, // low number so it shows up first
},
},
},
"Plugins": []interface{}{
map[string]interface{}{
"id": "iowait",
"label": "iowait",
"description": "Adds a graph of CPU IO Wait to hosts",
"interfaces": []string{"reporter"},
"api_version": "1",
},
},
})
fmt.Fprintf(w, `{
"Host": {
"nodes": {
%q: {
"metrics": {
"iowait": {
"samples": [ {"date": %q, "value": %f} ]
}
}
}
},
"metric_templates": {
"iowait": {
"id": "iowait",
"label": "IO Wait",
"format": "percent",
"priority": 0.1
}
}
},
"Plugins": [
{
"id": "iowait",
"label": "iowait",
"description": "Adds a graph of CPU IO Wait to hosts",
"interfaces": ["reporter"],
"api_version": "1"
}
]
}`, p.HostID+";<host>", nowISO, value)
if err != nil {
log.Printf("error: %v", err)
}
Expand Down

0 comments on commit 3865e0f

Please sign in to comment.