-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
A collector for DRBD #365
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please catch scanner.Scan()
errors. See https://github.com/prometheus/node_exporter/blob/master/collector/meminfo_numa_linux.go#L164-L181 for a good example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
There was a problem hiding this 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) |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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.
There was a problem hiding this 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]) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
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.", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
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.
Looks good to me now, thanks! I'll let fish approve + merge. |
Looking great! Thanks a lot @EdSchouten! |
…freebsd Mark sysfs as Linux-only
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.