Page MenuHomeFreeBSD

prometheus_sysctl_exporter(8): filter output using a regex
ClosedPublic

Authored by rew on Oct 1 2021, 10:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 11, 3:56 PM
Unknown Object (File)
Oct 2 2024, 6:11 AM
Unknown Object (File)
Sep 30 2024, 7:28 AM
Unknown Object (File)
Sep 30 2024, 7:27 AM
Unknown Object (File)
Sep 30 2024, 7:20 AM
Unknown Object (File)
Sep 30 2024, 5:29 AM
Unknown Object (File)
Sep 23 2024, 3:57 AM
Unknown Object (File)
Sep 22 2024, 4:41 AM
Subscribers

Details

Summary

Add two options, '-i' and '-I', that each accept a regular expression as
an argument. The provided regular expression is used to filter output
when printing prometheus metrics.

The '-i' option will print metrics that match the regular expression.
The '-I' option will not print metrics that match the regular expression.

Note, all metrics printed by prometheus_sysctl_exporter(8) are preceded
with 'sysctl_', so that's one thing to keep in mind when writing a regex
to filter the output. The regular expression will try matching on the
final form of the metric name as one would see when using
prometheus_sysctl_exporter on the command-line.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

rew requested review of this revision.Oct 1 2021, 10:29 PM

I wonder if we should follow the model of grep(1) in this case that is being able to specify multiple --include and --exclude flags and have the last matching regex decide if the metric is printed out or not.

usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8
90
  1. Perhaps we should note in the manual that the exclude regex is processed first. Also, it's probably worth noting that the first matching regex wins in contrast to other utilities like grep(1).
  2. I wonder if the manual page should be a bit more verbose about the fact that the regular expressions are filtering final metrics instead of the sysctl nodes. What do you think?

I noticed that there are several places where a phrase is entirely or almost entirely repeated, and in my experience that's the sort of thing that makes it hard to scan through a manual page quickly - so I think it might be a good idea to rephrase things a bit.
Ideally I'd also really like to see the words include and exclude be used, as they're the kind of keywords that one would look for when dealing with this kind of thing.

address feedback from 0mp and debdrup

mention that the provided pattern is expected to be a regular expression

Did the item macros disappear by choice? Just checking.

Did the item macros disappear by choice? Just checking.

Which item macros are you referring to?

In D32269#728549, @rew wrote:

Which item macros are you referring to?

No idea, I must've read the diff wrong. Looks good to me now. :)

This revision is now accepted and ready to land.Oct 3 2021, 7:16 PM

For the record, the mdoc looks good to me now.
I can't speak to the code.

0mp requested changes to this revision.Oct 4 2021, 8:56 PM

I've spotted a couple of minor style issues.

Other than that, I wonder if there should be a way to have ERE over here.

When it comes to the existing patch, however:

  • perhaps -e for exclude is slightly more intuitive?
  • I've tested the patch. It seems to work just fine.
usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.8
35

This should be sorted like this for consistency with style(9):

.Op Fl I Ar pattern
.Op Fl i Ar pattern
90

Please put the definition of the -I flag first.

usr.sbin/prometheus_sysctl_exporter/prometheus_sysctl_exporter.c
48

All the comments seem to end with a period in this file.

378

For consistency with the rest of the file.

561

Sort flags.

579

style(9)

599

case 'i' and case 'I' should be sorted.

This revision now requires changes to proceed.Oct 4 2021, 8:56 PM

address feedback from 0mp

rew marked 7 inline comments as done.Oct 5 2021, 4:25 PM
In D32269#728893, @0mp wrote:

Other than that, I wonder if there should be a way to have ERE over here.

What's ERE?

  • perhaps -e for exclude is slightly more intuitive?

Glad you mentioned this, I was thinking -I wasn't the best choice for the exclude flag, I've switched it to -e instead.

In D32269#729373, @rew wrote:
In D32269#728893, @0mp wrote:

Other than that, I wonder if there should be a way to have ERE over here.

What's ERE?

Extended regular expressions as in "grep -E".

In D32269#728893, @0mp wrote:

Other than that, I wonder if there should be a way to have ERE over here.

It's already setup to use extended regular expressions.

OK from manpages. I do not have a src bit to approve the src change.

This revision is now accepted and ready to land.Oct 6 2021, 9:18 PM