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

Collect info commandstats from redis #5874

Closed
wants to merge 1 commit into from

Conversation

wingyplus
Copy link
Contributor

Redis has an info type "commandstats" that can be collect each command
statistics inside redis. To make this work, I call info with commandstats
argument after called info (default information), append it and then parse
metrics.

Closes #5774

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@@ -188,7 +188,10 @@ func (r *Redis) gatherServer(client Client, acc telegraf.Accumulator) error {
return err
}

rdr := strings.NewReader(info)
// skip for commandstats if we can't retrieve it.
cmdstats, _ := client.Info("commandstats").Result()
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems this isn't skipping if you can't retrieve, line 194 would be affected as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure that which ways is better betwen log an error and let info return default information if we cannot collect command stats and returns an error.

// db0:keys=2,expires=0,avg_ttl=0
// And there is one for each db on the redis instance
//
// TODO: write code comments
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove or do TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

tags["cmdstat"] = strings.TrimPrefix(name, "cmdstat_")
stats := strings.Split(line, ",")
for _, stat := range stats {
kv := strings.Split(stat, "=")
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 to avoid a panic later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

ival interface{}
err error
)
// only calls that always be int
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: rephrase this comment

fields[kv[0]] = ival
}
}
acc.AddFields("redis_commandstats", fields, tags)
Copy link
Contributor

Choose a reason for hiding this comment

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

What if fields is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It’s hard to be empty because redis are not returns any line if it has no any command calls. Except that commandstats return the result incorrectly.

@glinton glinton added area/redis feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin labels May 17, 2019
Redis has an info type "commandstats" that can be collect each command
statistics inside redis. To make this work, I call info with commandstats
argument after called info (default information), append it and then parse
metrics.

Closes influxdata#5774
@danielnelson
Copy link
Contributor

This functionality was merged in #5926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redis feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gatherCommandstatsLine
3 participants