Skip to content

Commit

Permalink
Change from INFO to INFO ALL to get Commandstats statistics) #2894
Browse files Browse the repository at this point in the history
Added tests for #2894
Added documentation for #2894
  • Loading branch information
marek-knappe committed Jun 9, 2017
1 parent 4c53443 commit 2ff54cb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
29 changes: 29 additions & 0 deletions plugins/inputs/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 19 additions & 1 deletion plugins/inputs/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down
38 changes: 38 additions & 0 deletions plugins/inputs/redis/redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2ff54cb

Please sign in to comment.