From 521261ff0fa0010bfb11f92351ea66fb5e5a9d54 Mon Sep 17 00:00:00 2001 From: Marek Knappe Date: Thu, 8 Jun 2017 16:23:14 +0200 Subject: [PATCH] Change from INFO to INFO ALL to get Commandstats statistics) #2894 Added tests for #2894 Added documentation for #2894 --- plugins/inputs/redis/README.md | 29 +++++++++++++++++++++++ plugins/inputs/redis/redis.go | 20 +++++++++++++++- plugins/inputs/redis/redis_test.go | 38 ++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 1 deletion(-) diff --git a/plugins/inputs/redis/README.md b/plugins/inputs/redis/README.md index b9d216779429a..86cef605f7660 100644 --- a/plugins/inputs/redis/README.md +++ b/plugins/inputs/redis/README.md @@ -84,6 +84,35 @@ Additionally the plugin also calculates the hit/miss ratio (keyspace\_hitrate) a - latest_fork_usec(int, microseconds) - migrate_cached_sockets(int, number) + **Commands statistic** + - cmdstat_delcalls(int, number) + - cmdstat_delusec(int, number) + - cmdstat_delusec_per_call(float, number) + - cmdstat_expirecalls(int, number) + - cmdstat_expireusec(int, number) + - cmdstat_expireusec_per_call(float, number) + - cmdstat_getcalls(int, number) + - cmdstat_getusec(int, number) + - cmdstat_getusec_per_call(float, number) + - cmdstat_infocalls(int, number) + - cmdstat_infousec(int, number) + - cmdstat_infousec_per_call(float, number) + - cmdstat_mgetcalls(int, number) + - cmdstat_mgetusec(int, number) + - cmdstat_mgetusec_per_call(float, number) + - cmdstat_msetcalls(int, number) + - cmdstat_msetusec(int, number) + - cmdstat_msetusec_per_call(float, number) + - cmdstat_selectcalls(int, number) + - cmdstat_selectusec(int, number) + - cmdstat_selectusec_per_call(float, number) + - cmdstat_setexcalls(int, number) + - cmdstat_setexusec(int, number) + - cmdstat_setexusec_per_call(float, number) + - cmdstat_setnxcalls(int, number) + - cmdstat_setnxusec(int, number) + - cmdstat_setnxusec_per_call(float, number) + **Replication** - connected_slaves(int, number) - master_repl_offset(int, number) diff --git a/plugins/inputs/redis/redis.go b/plugins/inputs/redis/redis.go index cb976cadac071..f39a66f6a7a85 100644 --- a/plugins/inputs/redis/redis.go +++ b/plugins/inputs/redis/redis.go @@ -132,7 +132,7 @@ func (r *Redis) gatherServer(addr *url.URL, acc telegraf.Accumulator) error { } } - c.Write([]byte("INFO\r\n")) + c.Write([]byte("INFO ALL\r\n")) c.Write([]byte("EOF\r\n")) rdr := bufio.NewReader(c) @@ -189,6 +189,24 @@ func gatherInfoOutput( } } + if section == "Commandstats" { + //#cmdstat_get:calls=63102137,usec=166854619,usec_per_call=2.64 + tmp := strings.Split(line, ":") + tmp_metrics := strings.Split(tmp[1], ",") + for _, element := range tmp_metrics { + mdata := strings.Split(element, "=") + if ival, err := strconv.ParseInt(mdata[1], 10, 64); err == nil { + fields[tmp[0]+mdata[0]] = ival + } else if fval, err := strconv.ParseFloat(mdata[1], 64); err == nil { + fields[tmp[0]+mdata[0]] = fval + } else { + fields[tmp[0]+mdata[0]] = mdata[1] + } + + } + continue + } + if name == "mem_allocator" { continue } diff --git a/plugins/inputs/redis/redis_test.go b/plugins/inputs/redis/redis_test.go index 904a80d3720bb..59ed1cb11cc46 100644 --- a/plugins/inputs/redis/redis_test.go +++ b/plugins/inputs/redis/redis_test.go @@ -91,6 +91,33 @@ func TestRedis_ParseMetrics(t *testing.T) { "used_cpu_sys_children": float64(0.00), "used_cpu_user_children": float64(0.00), "keyspace_hitrate": float64(0.50), + "cmdstat_delusec_per_call": float64(7.89), + "cmdstat_expireusec_per_call": float64(1.55), + "cmdstat_getusec_per_call": float64(4.35), + "cmdstat_infousec_per_call": float64(145.92), + "cmdstat_mgetusec_per_call": float64(7.72), + "cmdstat_msetusec_per_call": float64(7.03), + "cmdstat_selectusec_per_call": float64(1.47), + "cmdstat_setexusec_per_call": float64(5.15), + "cmdstat_setnxusec_per_call": float64(4.42), + "cmdstat_delcalls": int64(28393), + "cmdstat_delusec": int64(224118), + "cmdstat_expirecalls": int64(524193), + "cmdstat_expireusec": int64(811227), + "cmdstat_getcalls": int64(18708243), + "cmdstat_getusec": int64(81317810), + "cmdstat_infocalls": int64(7734), + "cmdstat_infousec": int64(1128518), + "cmdstat_mgetcalls": int64(3136449), + "cmdstat_mgetusec": int64(24200188), + "cmdstat_msetcalls": int64(118074), + "cmdstat_msetusec": int64(830158), + "cmdstat_selectcalls": int64(252265), + "cmdstat_selectusec": int64(371753), + "cmdstat_setexcalls": int64(1342574), + "cmdstat_setexusec": int64(6917848), + "cmdstat_setnxcalls": int64(12), + "cmdstat_setnxusec": int64(53), } // We have to test rdb_last_save_time_offset manually because the value is based on the time when gathered @@ -185,6 +212,17 @@ pubsub_channels:0 pubsub_patterns:0 latest_fork_usec:0 +# Commandstats +cmdstat_get:calls=18708243,usec=81317810,usec_per_call=4.35 +cmdstat_setnx:calls=12,usec=53,usec_per_call=4.42 +cmdstat_setex:calls=1342574,usec=6917848,usec_per_call=5.15 +cmdstat_del:calls=28393,usec=224118,usec_per_call=7.89 +cmdstat_mget:calls=3136449,usec=24200188,usec_per_call=7.72 +cmdstat_mset:calls=118074,usec=830158,usec_per_call=7.03 +cmdstat_select:calls=252265,usec=371753,usec_per_call=1.47 +cmdstat_expire:calls=524193,usec=811227,usec_per_call=1.55 +cmdstat_info:calls=7734,usec=1128518,usec_per_call=145.92 + # Replication role:master connected_slaves:0