From 9cd1344740034efbc92afb64468648674942871c Mon Sep 17 00:00:00 2001 From: Orne Brocaar Date: Thu, 9 Jul 2015 20:01:59 +0200 Subject: [PATCH] Implement os stats. --- plugins/elasticsearch/elasticsearch.go | 8 +++- plugins/elasticsearch/elasticsearch_test.go | 4 ++ plugins/elasticsearch/testdata_test.go | 46 +++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/plugins/elasticsearch/elasticsearch.go b/plugins/elasticsearch/elasticsearch.go index 0e388d72c..fc0f6e6fb 100644 --- a/plugins/elasticsearch/elasticsearch.go +++ b/plugins/elasticsearch/elasticsearch.go @@ -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) diff --git a/plugins/elasticsearch/elasticsearch_test.go b/plugins/elasticsearch/elasticsearch_test.go index 4e1ca8575..8bd5d56ca 100644 --- a/plugins/elasticsearch/elasticsearch_test.go +++ b/plugins/elasticsearch/elasticsearch_test.go @@ -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)) + } } diff --git a/plugins/elasticsearch/testdata_test.go b/plugins/elasticsearch/testdata_test.go index 521a36938..750636428 100644 --- a/plugins/elasticsearch/testdata_test.go +++ b/plugins/elasticsearch/testdata_test.go @@ -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, +}