Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change from INFO to INFO ALL to get Commandstats statistics) #2894 #2902

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions plugins/inputs/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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], ",")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for the length of the splits before indexing, just in case the input is bad for some reason. In the case of not having a ":", call acc.AddError and continue.

for _, element := range tmp_metrics {
mdata := strings.Split(element, "=")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check length here too

if ival, err := strconv.ParseInt(mdata[1], 10, 64); err == nil {
fields[tmp[0]+mdata[0]] = ival
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to separate tmp[0] & mdata[0] with a delimiter, such as _.

} 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),
"redis_version": "2.8.9",
}

Expand Down Expand Up @@ -186,6 +213,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