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

A collector for DRBD #365

Merged
merged 7 commits into from
Dec 25, 2016
Merged

A collector for DRBD #365

merged 7 commits into from
Dec 25, 2016

Conversation

EdSchouten
Copy link
Contributor

In addition to the NFS stats collector, we also wrote a similar one for parsing /proc/drbd to extract DRBD replication stats. This allows us to keep an eye on whether our systems are still in sync with each other, the amount of network/disk I/O, etc.

Ed Schouten added 2 commits December 11, 2016 11:55
This collector exposes most of the useful information that can be found
in /proc/drbd. Sizes are normalised to be in bytes, as /proc/drbd uses
kibibytes.
log.Infof("Don't know how to process string %s", field)
}
}
return nil
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM.


func (c *drbdCollector) Update(ch chan<- prometheus.Metric) (err error) {
statsFile := procFilePath("drbd")
f, err := os.Open(statsFile)
Copy link
Member

Choose a reason for hiding this comment

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

Just a nit, but the collectors tend to use the full variable name file for these type of uses.

var (
drbdNumericalMetrics = map[string]drbdNumericalMetric{
"ns": newDrbdNumericalMetric(
"network_sent_bytes",
Copy link
Member

Choose a reason for hiding this comment

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

Counter metrics should always get prefixed with _total, see: https://prometheus.io/docs/practices/naming/. This applies to all other counters too.

Also think that something like "Total bytes sent via network." might be a better help string (same for similar metrics).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding the _total suffix: yes! That sounds like a good idea.

Regarding changing the documentation string: I made sure that all of the documentation strings are literal copies of how they are officially documented, except that I dropped the "in Kibyte" part. I've now restored those parts to say "in bytes".

To summarize: the strings are now the same as upstream | sed -e 's/Kibyte/bytes/'

multiplier float64
}

func newDrbdNumericalMetric(name string, desc string, valueType prometheus.ValueType, multiplier float64) drbdNumericalMetric {
Copy link
Member

Choose a reason for hiding this comment

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

newDrbdNumericalMetric -> newDRBDNumericalMetric (keep case consistent within acronyms, see https://github.com/golang/go/wiki/CodeReviewComments#initialisms)

Same for other occurrences below.

1),
"oos": newDrbdNumericalMetric(
"out_of_sync_bytes",
"Amount of data known to be out of sync.",
Copy link
Member

Choose a reason for hiding this comment

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

Include the unit (bytes) in the help string as well.

file, err := os.Open(statsFile)
if err != nil {
if os.IsNotExist(err) {
log.Debugf("Not collecting DRBD statistics, as %s does not exist: %s", statsFile)
Copy link
Member

Choose a reason for hiding this comment

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

This has two %s placeholders, but only one argument.

Copy link
Member

Choose a reason for hiding this comment

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

(btw., either golint or go vet will complain about things like this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch! Thanks for pointing me to golint. Will use that from now on. :+1

log.Infof("Don't know how to process key-value pair [%s: %s]", kv[0], kv[1])
}
} else {
log.Infof("Don't know how to process string %s", field)
Copy link
Member

Choose a reason for hiding this comment

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

Pro tip: use %q if you want the string to be automatically quoted in the output.

@juliusv
Copy link
Member

juliusv commented Dec 21, 2016

Thanks, looks pretty cool to me besides mine and @discordianfish's comments!

- Use the right number of printf() arguments. Use %q where it makes sense.
- Use "DRBD" instead of "Drbd", per Go's style guide.
- Add _total suffixes to counter metrics.
- Mention the unit (bytes) in documentation strings once more.
Copy link
Member

@discordianfish discordianfish left a comment

Choose a reason for hiding this comment

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

Looking good, just some nitpicks.

if kv[1] == "Connected" {
connected = 1
}
ch <- prometheus.MustNewConstMetric(
drbdConnected, prometheus.GaugeValue,
connected, device)
} else {
log.Infof("Don't know how to process key-value pair [%s: %s]", kv[0], kv[1])
log.Infof("Don't know how to process key-value pair [%s: %q]", kv[0], kv[1])
Copy link
Member

Choose a reason for hiding this comment

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

Just a question: Is this unexpected? Than info is okay, if this is expected and might happen everytime it should be logged with Debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good that you've brought this up. The /proc file does expose some tags that we don't process at all. Changing this to Debugf().

"Volume of net data sent to the partner via the network connection.",
"ns": newDRBDNumericalMetric(
"network_sent_bytes_total",
"Volume of net data sent to the partner via the network connection; in bytes.",
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for nitpicking, but I find the wording a bit odd and redundant. What do you think about

"Total number of bytes sent via the network"?

Same for received and similar for disk_ metrics ("Total number of bytes read from/written to disk")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, sounds good. Fixed!

"local_pending",
"Number of open requests to the local I/O sub-system.",
prometheus.GaugeValue,
1),
"pe": newDrbdNumericalMetric(
"pe": newDRBDNumericalMetric(
"remote_pending",
"Number of requests sent to the partner, but that have not yet been answered by the latter.",
Copy link
Member

Choose a reason for hiding this comment

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

I'd say peer instead of partner, that's more common.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Ed Schouten added 2 commits December 23, 2016 15:55
They get printed all the time, as there are some tokens in the /proc
file that we simply don't support. It's better to keep these as
debugging messages, which may come in useful if new tags start to
appear.
@juliusv
Copy link
Member

juliusv commented Dec 23, 2016

Looks good to me now, thanks! I'll let fish approve + merge.

@discordianfish discordianfish merged commit 71ea379 into prometheus:master Dec 25, 2016
@discordianfish
Copy link
Member

Looking great! Thanks a lot @EdSchouten!

@SuperQ SuperQ mentioned this pull request Jan 15, 2017
tamcore pushed a commit to gitgrave/node_exporter that referenced this pull request Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants