Skip to content

Conversation

@pgier
Copy link
Contributor

@pgier pgier commented Oct 12, 2018

Handles new stats added in 4.19, along with some minor cleanup/refactoring
changes are base on proposal from @hhoffstaette in issue #1049 with some minor changes
fixes #1049

@pgier pgier force-pushed the update-diskstats-for-linux-kernel-4.19 branch 3 times, most recently from 9f7590e to 6e691d7 Compare October 12, 2018 21:43
pgier added 3 commits October 12, 2018 16:53
Use a constant for the diskstats filename and for the iostats doc URL.
Append the iostats doc URL consistently to the metric doc strings.

Signed-off-by: Paul Gier <pgier@redhat.com>
The format of /proc/diskstats is changing in linux-4.19 to include some
additional fields.  See: https://www.kernel.org/doc/Documentation/iostats.txt

Signed-off-by: Paul Gier <pgier@redhat.com>
@pgier pgier force-pushed the update-diskstats-for-linux-kernel-4.19 branch from 6e691d7 to 9141986 Compare October 12, 2018 21:53
@SuperQ
Copy link
Member

SuperQ commented Oct 13, 2018

Nice, thanks.

I'm not sure adding the link to the kernel docs on every help line is necessary.

@pgier
Copy link
Contributor Author

pgier commented Oct 13, 2018

@SuperQ The link to the kernel docs seemed kind of randomly placed before. I wasn't sure which metrics should/shouldn't include it so I just decided to add it to all of them, but I'm happy to change it back if that's better.

@discordianfish
Copy link
Member

Nice!

Agree with @SuperQ, let's remove the URL completely and add it as code comment.
If we feel like this needs to be more user facing, I'd rather put it in the README.

Beside that, LGTM

@SuperQ
Copy link
Member

SuperQ commented Oct 15, 2018

I've been thinking now that this exporter is getting closer to 1.0, we could start adding a per-collector documentation page.

@discordianfish
Copy link
Member

That might make sense. Maybe though we should use code comments and refer to godoc in the README? Might make it easier to keep it up to date.

@SuperQ
Copy link
Member

SuperQ commented Oct 15, 2018

Yea, Godoc might be ok too. In theory some people use the collector package as a library.

Signed-off-by: Paul Gier <pgier@redhat.com>
@pgier
Copy link
Contributor Author

pgier commented Oct 15, 2018

Thanks for the feedback! I added a commit to remove the doc url from the individual metrics.

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.

LGTM

@SuperQ SuperQ self-assigned this Oct 15, 2018
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

@SuperQ SuperQ merged commit e8d8199 into prometheus:master Oct 15, 2018

if len(stats) != len(c.descs) {
return fmt.Errorf("invalid line for %s for %s", procDiskStats, dev)
if len(stats) > len(c.descs) {
Copy link

Choose a reason for hiding this comment

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

I would suggest to have a more future proof version. It's ok to have stats that are not know to node_exporter (new kernel, old exporter), it's also on for node_exporter to know about more stats than kernel can report (old kernel, new exporter). Currently only the latter is supported.

How about something like this:

diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go
index 8c1e5cc..e8a2237 100644
--- a/collector/diskstats_linux.go
+++ b/collector/diskstats_linux.go
@@ -164,7 +164,6 @@ func NewDiskstatsCollector() (Collector, error) {
 }

 func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
-       procDiskStats := procFilePath("diskstats")
        diskStats, err := getDiskStats()
        if err != nil {
                return fmt.Errorf("couldn't get diskstats: %s", err)
@@ -176,16 +175,19 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
                        continue
                }

-               if len(stats) != len(c.descs) {
-                       return fmt.Errorf("invalid line for %s for %s", procDiskStats, dev)
-               }
+               // Iterate over all known stats
+               for i, desc := range c.descs {
+                       // Stop if this stat is not reported
+                       if i >= len(stats) {
+                               break
+                       }

-               for i, value := range stats {
-                       v, err := strconv.ParseFloat(value, 64)
+                       v, err := strconv.ParseFloat(stats[i], 64)
                        if err != nil {
-                               return fmt.Errorf("invalid value %s in diskstats: %s", value, err)
+                               return fmt.Errorf("invalid value %s in diskstats: %s", stats[i], err)
                        }
-                       ch <- c.descs[i].mustNewConstMetric(v, dev)
+
+                       ch <- desc.mustNewConstMetric(v, dev)
                }
        }
        return nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This sounds reasonable to me, see #1125

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I ended up having to be a little more "future proof" with NFS metrics. The list of NFSv4 metrics varies wildly with kernel versions.

{
desc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, diskSubsystem, "discarded_sectors_total"),
"The total number of sectors discard successfully.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Should that be "discarded" instead of "discard" ?

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 catch, I've updated pr #1125

ciil added a commit to mayflower/nixpkgs that referenced this pull request Nov 21, 2018
fixes, among others,
prometheus/node_exporter#1109. Just backporting
the patch failed on basically all hunks, so this was far easier.
Seems to run stable.
@pgier pgier deleted the update-diskstats-for-linux-kernel-4.19 branch January 18, 2019 16:13
@pgier pgier restored the update-diskstats-for-linux-kernel-4.19 branch January 18, 2019 16:13
gordan-bobic added a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 25, 2021
…ormat of /proc/diskstats.

Modified version of the upstream patch backported for the older node_exporter base:
prometheus#1109
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
The format of /proc/diskstats is changing in linux-4.19 to include some
additional fields.  See: https://www.kernel.org/doc/Documentation/iostats.txt

* collector/diskstats: use constants for some hard coded strings
* collector/diskstats: update diskstats for linux-4.19
* collector/diskstats: remove kernel doc url from individual metrics

Signed-off-by: Paul Gier <pgier@redhat.com>
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.

Linux 4.19 will break /proc/diskstats parsing

5 participants