From cfb92e0e37405ad86f04fef2652d72cd4b2f4385 Mon Sep 17 00:00:00 2001 From: madz Date: Fri, 3 Jul 2015 16:17:49 +0800 Subject: [PATCH] modified as commented on code review --- plugins/ceph/ceph.go | 14 ++++---- plugins/ceph/ceph_test.go | 72 +++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/plugins/ceph/ceph.go b/plugins/ceph/ceph.go index 197756a8f..5e567a589 100644 --- a/plugins/ceph/ceph.go +++ b/plugins/ceph/ceph.go @@ -136,11 +136,11 @@ func (ceph *CephMetrics) getCommon(acc plugins.Accumulator) { quorumValueMap["members"] = strings.Join(quorum_name, ",") //clientIOs - sumOps := int64(0) - sumWrs := int64(0) + var sumOps int64 = 0 + var sumWrs int64 = 0 for _, stat := range poolStatsList { - sumOps += int64(stat.ClientIoRate.OpsPerSec) - sumWrs += int64(stat.ClientIoRate.WriteBytesPerSecond) / 1024 + sumOps += stat.ClientIoRate.OpsPerSec + sumWrs += stat.ClientIoRate.WriteBytesPerSecond / 1024 } // OSD Epoch @@ -269,7 +269,7 @@ func (ceph *CephMetrics) getPg(acc plugins.Accumulator) { } for poolId, osdPgMap := range poolOsdPgMap { - poolPg := int64(0) + var poolPg int64 = 0 for osdId, pgs := range osdPgMap { tags := map[string]string{"cluster": ceph.Cluster, "pool": fmt.Sprintf("%d", poolId), "osd": fmt.Sprintf("%d", osdId)} poolPg += pgs @@ -346,8 +346,8 @@ func (ceph *CephMetrics) getOSDDaemon(acc plugins.Accumulator) { tag := map[string]string{"cluster": ceph.Cluster, "osd": fmt.Sprintf("%d", osdNum)} acc.Add("osd_utilization", utilized, tag) - acc.Add("osd_used", utilized, tag) - acc.Add("osd_total", total, tag) + acc.Add("osd_used_storage", used, tag) + acc.Add("osd_total_storage", total, tag) } //OSD Commit and Apply Latency diff --git a/plugins/ceph/ceph_test.go b/plugins/ceph/ceph_test.go index c0762cd4f..39f2855f6 100644 --- a/plugins/ceph/ceph_test.go +++ b/plugins/ceph/ceph_test.go @@ -24,46 +24,52 @@ func TestCephGenerateMetrics(t *testing.T) { assert.Equal(t, p.Cluster, "ceph", "Same Cluster") intMetrics := []string{ + "total_storage", + "used_storage", + "available_storage", + "client_io_kbs", + "client_io_ops", + + "pool_used", + "pool_usedKb", + "pool_maxbytes", + "pool_objects", + + "osd_epoch", + "op_in_bytes", + "op_out_bytes", + "op_r", + "op_w", + "op_w_in_bytes", + "op_rw", + "op_rw_in_bytes", + "op_rw_out_bytes", + + "pg_map_count", "pg_data_bytes", - "pg_data_avail", - // "osd_count", - // "osd_utilization", - // "total_storage", - // "used", - // "available", - // "client_io_kbs", - // "client_io_ops", - // "pool_used", - // "pool_usedKb", - // "pool_maxbytes", - // "pool_utilization", - // "osd_used", - // "osd_total", - // "osd_epoch", - // "osd_latency_commit", - // "osd_latency_apply", - // "op", - // "op_in_bytes", - // "op_out_bytes", - // "op_r", - // "op_r_out_byes", - // "op_w", - // "op_w_in_bytes", - // "op_rw", - // "op_rw_in_bytes", - // "op_rw_out_bytes", - // "pool_objects", - // "pg_map_count", - "pg_data_bytes", - "pg_data_avail", - "pg_data_total", - "pg_data_used", + "pg_data_total_storage", + "pg_data_used_storage", + "pg_distribution", + "pg_distribution_pool", + "pg_distribution_osd", + } + + floatMetrics := []string{ + "osd_utilization", + "pool_utilization", + "osd_used_storage", + "osd_total_storage", } for _, metric := range intMetrics { + assert.True(t, acc.HasIntValue(metric)) } + for _, metric := range floatMetrics { + assert.True(t, acc.HasFloatValue(metric)) + } + } func TestCephGenerateMetricsDefault(t *testing.T) {