Implement os stats.

This commit is contained in:
Orne Brocaar 2015-07-09 20:01:59 +02:00
parent c6a9335bf2
commit 9cd1344740
3 changed files with 56 additions and 2 deletions

View File

@ -16,6 +16,7 @@ type node struct {
Name string `json:"name"`
Attributes map[string]string `json:"attributes"`
Indices interface{} `json:"indices"`
Os interface{} `json:"os"`
}
const sampleConfig = `
@ -99,6 +100,9 @@ func (e *Elasticsearch) gatherUrl(url string, acc plugins.Accumulator) error {
if err := e.parseInterface(acc, "indices", tags, n.Indices); err != nil {
return err
}
if err := e.parseInterface(acc, "os", tags, n.Os); err != nil {
return err
}
}
return nil
@ -114,8 +118,8 @@ func (e *Elasticsearch) parseInterface(acc plugins.Accumulator, prefix string, t
}
case float64:
acc.Add(prefix, t, tags)
case bool, string:
// ignored bool and string
case bool, string, []interface{}:
// ignored types
return nil
default:
return fmt.Errorf("elasticsearch: got unexpected type %T with value %v (%s)", t, t, prefix)

View File

@ -54,4 +54,8 @@ func TestElasticsearch(t *testing.T) {
for key, val := range indicesExpected {
assert.NoError(t, acc.ValidateTaggedValue(key, val, tags))
}
for key, val := range osExpected {
assert.NoError(t, acc.ValidateTaggedValue(key, val, tags))
}
}

View File

@ -126,6 +126,34 @@ const statsResponse = `
"current_as_target": 0,
"throttle_time_in_millis": 0
}
},
"os": {
"timestamp": 1436460392944,
"uptime_in_millis": 25092,
"load_average": [
0.01,
0.04,
0.05
],
"cpu": {
"sys": 0,
"user": 0,
"idle": 99,
"usage": 0,
"stolen": 0
},
"mem": {
"free_in_bytes": 477761536,
"used_in_bytes": 1621868544,
"free_percent": 74,
"used_percent": 25,
"actual_free_in_bytes": 1565470720,
"actual_used_in_bytes": 534159360
},
"swap": {
"used_in_bytes": 0,
"free_in_bytes": 487997440
}
}
}
}
@ -203,3 +231,21 @@ var indicesExpected = map[string]float64{
"indices_segments_version_map_memory_in_bytes": 611844,
"indices_segments_fixed_bit_set_memory_in_bytes": 0,
}
var osExpected = map[string]float64{
"os_swap_used_in_bytes": 0,
"os_swap_free_in_bytes": 487997440,
"os_timestamp": 1436460392944,
"os_uptime_in_millis": 25092,
"os_cpu_sys": 0,
"os_cpu_user": 0,
"os_cpu_idle": 99,
"os_cpu_usage": 0,
"os_cpu_stolen": 0,
"os_mem_free_percent": 74,
"os_mem_used_percent": 25,
"os_mem_actual_free_in_bytes": 1565470720,
"os_mem_actual_used_in_bytes": 534159360,
"os_mem_free_in_bytes": 477761536,
"os_mem_used_in_bytes": 1621868544,
}