diff options
author | Peter Nicholson <petergoods@hotmail.com> | 2019-12-30 01:36:10 +0100 |
---|---|---|
committer | Ben Kochie <superq@gmail.com> | 2019-12-30 01:36:10 +0100 |
commit | a80b7d0bc5ee93e704bab22e7592ed8b7d65899e (patch) | |
tree | e535e50150d90de1bcc372e6d88bec7adada67a7 | |
parent | cafb12dc59f5b853bdd1167547056428eaddd353 (diff) | |
download | prometheus_node_collector-a80b7d0bc5ee93e704bab22e7592ed8b7d65899e.tar.bz2 prometheus_node_collector-a80b7d0bc5ee93e704bab22e7592ed8b7d65899e.tar.xz prometheus_node_collector-a80b7d0bc5ee93e704bab22e7592ed8b7d65899e.zip |
Add softnet collector (#1576)
Signed-off-by: Peter Nicholson <petergoods@hotmail.com>
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | collector/fixtures/e2e-64k-page-output.txt | 19 | ||||
-rw-r--r-- | collector/fixtures/e2e-output.txt | 19 | ||||
-rw-r--r-- | collector/fixtures/proc/net/softnet_stat | 4 | ||||
-rw-r--r-- | collector/softnet_linux.go | 99 |
6 files changed, 143 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9094c4d..b65a300 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md | |||
@@ -21,6 +21,7 @@ | |||
21 | * [FEATURE] Add new metric node_cpu_info #1489 | 21 | * [FEATURE] Add new metric node_cpu_info #1489 |
22 | * [FEATURE] Add new thermal_zone collector #1425 | 22 | * [FEATURE] Add new thermal_zone collector #1425 |
23 | * [FEATURE] Add new cooling_device metrics to thermal zone collector #1445 | 23 | * [FEATURE] Add new cooling_device metrics to thermal zone collector #1445 |
24 | * [FEATURE] Add new softnet collector #1576 | ||
24 | * [ENHANCEMENT] Collect InfiniBand port state and physical state #1357 | 25 | * [ENHANCEMENT] Collect InfiniBand port state and physical state #1357 |
25 | * [ENHANCEMENT] Include additional XFS runtime statistics. #1423 | 26 | * [ENHANCEMENT] Include additional XFS runtime statistics. #1423 |
26 | * [ENHANCEMENT] Report non-fatal collection errors in the exporter metric. #1439 | 27 | * [ENHANCEMENT] Report non-fatal collection errors in the exporter metric. #1439 |
@@ -53,6 +53,7 @@ nfsd | Exposes NFS kernel server statistics from `/proc/net/rpc/nfsd`. This is t | |||
53 | pressure | Exposes pressure stall statistics from `/proc/pressure/`. | Linux (kernel 4.20+ and/or [CONFIG\_PSI](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/accounting/psi.txt)) | 53 | pressure | Exposes pressure stall statistics from `/proc/pressure/`. | Linux (kernel 4.20+ and/or [CONFIG\_PSI](https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/accounting/psi.txt)) |
54 | schedstat | Exposes task scheduler statistics from `/proc/schedstat`. | Linux | 54 | schedstat | Exposes task scheduler statistics from `/proc/schedstat`. | Linux |
55 | sockstat | Exposes various statistics from `/proc/net/sockstat`. | Linux | 55 | sockstat | Exposes various statistics from `/proc/net/sockstat`. | Linux |
56 | softnet | Exposes statistics from `/proc/net/softnet_stat`. | Linux | ||
56 | stat | Exposes various statistics from `/proc/stat`. This includes boot time, forks and interrupts. | Linux | 57 | stat | Exposes various statistics from `/proc/stat`. This includes boot time, forks and interrupts. | Linux |
57 | textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_ | 58 | textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_ |
58 | thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`. | Linux | 59 | thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`. | Linux |
diff --git a/collector/fixtures/e2e-64k-page-output.txt b/collector/fixtures/e2e-64k-page-output.txt index 9f75f08..0e8e1e2 100644 --- a/collector/fixtures/e2e-64k-page-output.txt +++ b/collector/fixtures/e2e-64k-page-output.txt | |||
@@ -2547,6 +2547,7 @@ node_scrape_collector_success{collector="processes"} 1 | |||
2547 | node_scrape_collector_success{collector="qdisc"} 1 | 2547 | node_scrape_collector_success{collector="qdisc"} 1 |
2548 | node_scrape_collector_success{collector="schedstat"} 1 | 2548 | node_scrape_collector_success{collector="schedstat"} 1 |
2549 | node_scrape_collector_success{collector="sockstat"} 1 | 2549 | node_scrape_collector_success{collector="sockstat"} 1 |
2550 | node_scrape_collector_success{collector="softnet"} 1 | ||
2550 | node_scrape_collector_success{collector="stat"} 1 | 2551 | node_scrape_collector_success{collector="stat"} 1 |
2551 | node_scrape_collector_success{collector="textfile"} 1 | 2552 | node_scrape_collector_success{collector="textfile"} 1 |
2552 | node_scrape_collector_success{collector="thermal_zone"} 1 | 2553 | node_scrape_collector_success{collector="thermal_zone"} 1 |
@@ -2596,6 +2597,24 @@ node_sockstat_UDP_mem_bytes 0 | |||
2596 | # HELP node_sockstat_sockets_used Number of sockets sockets in state used. | 2597 | # HELP node_sockstat_sockets_used Number of sockets sockets in state used. |
2597 | # TYPE node_sockstat_sockets_used gauge | 2598 | # TYPE node_sockstat_sockets_used gauge |
2598 | node_sockstat_sockets_used 229 | 2599 | node_sockstat_sockets_used 229 |
2600 | # HELP node_softnet_dropped_total Number of dropped packets | ||
2601 | # TYPE node_softnet_dropped_total counter | ||
2602 | node_softnet_dropped_total{cpu="0"} 0 | ||
2603 | node_softnet_dropped_total{cpu="1"} 41 | ||
2604 | node_softnet_dropped_total{cpu="2"} 0 | ||
2605 | node_softnet_dropped_total{cpu="3"} 0 | ||
2606 | # HELP node_softnet_processed_total Number of processed packets | ||
2607 | # TYPE node_softnet_processed_total counter | ||
2608 | node_softnet_processed_total{cpu="0"} 299641 | ||
2609 | node_softnet_processed_total{cpu="1"} 916354 | ||
2610 | node_softnet_processed_total{cpu="2"} 5.577791e+06 | ||
2611 | node_softnet_processed_total{cpu="3"} 3.113785e+06 | ||
2612 | # HELP node_softnet_times_squeezed_total Number of times processing packets ran out of quota | ||
2613 | # TYPE node_softnet_times_squeezed_total counter | ||
2614 | node_softnet_times_squeezed_total{cpu="0"} 1 | ||
2615 | node_softnet_times_squeezed_total{cpu="1"} 10 | ||
2616 | node_softnet_times_squeezed_total{cpu="2"} 85 | ||
2617 | node_softnet_times_squeezed_total{cpu="3"} 50 | ||
2599 | # HELP node_textfile_mtime_seconds Unixtime mtime of textfiles successfully read. | 2618 | # HELP node_textfile_mtime_seconds Unixtime mtime of textfiles successfully read. |
2600 | # TYPE node_textfile_mtime_seconds gauge | 2619 | # TYPE node_textfile_mtime_seconds gauge |
2601 | # HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise | 2620 | # HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise |
diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt index e915f92..463de43 100644 --- a/collector/fixtures/e2e-output.txt +++ b/collector/fixtures/e2e-output.txt | |||
@@ -2568,6 +2568,7 @@ node_scrape_collector_success{collector="processes"} 1 | |||
2568 | node_scrape_collector_success{collector="qdisc"} 1 | 2568 | node_scrape_collector_success{collector="qdisc"} 1 |
2569 | node_scrape_collector_success{collector="schedstat"} 1 | 2569 | node_scrape_collector_success{collector="schedstat"} 1 |
2570 | node_scrape_collector_success{collector="sockstat"} 1 | 2570 | node_scrape_collector_success{collector="sockstat"} 1 |
2571 | node_scrape_collector_success{collector="softnet"} 1 | ||
2571 | node_scrape_collector_success{collector="stat"} 1 | 2572 | node_scrape_collector_success{collector="stat"} 1 |
2572 | node_scrape_collector_success{collector="textfile"} 1 | 2573 | node_scrape_collector_success{collector="textfile"} 1 |
2573 | node_scrape_collector_success{collector="thermal_zone"} 1 | 2574 | node_scrape_collector_success{collector="thermal_zone"} 1 |
@@ -2635,6 +2636,24 @@ node_sockstat_UDP_mem_bytes 0 | |||
2635 | # HELP node_sockstat_sockets_used Number of IPv4 sockets in use. | 2636 | # HELP node_sockstat_sockets_used Number of IPv4 sockets in use. |
2636 | # TYPE node_sockstat_sockets_used gauge | 2637 | # TYPE node_sockstat_sockets_used gauge |
2637 | node_sockstat_sockets_used 229 | 2638 | node_sockstat_sockets_used 229 |
2639 | # HELP node_softnet_dropped_total Number of dropped packets | ||
2640 | # TYPE node_softnet_dropped_total counter | ||
2641 | node_softnet_dropped_total{cpu="0"} 0 | ||
2642 | node_softnet_dropped_total{cpu="1"} 41 | ||
2643 | node_softnet_dropped_total{cpu="2"} 0 | ||
2644 | node_softnet_dropped_total{cpu="3"} 0 | ||
2645 | # HELP node_softnet_processed_total Number of processed packets | ||
2646 | # TYPE node_softnet_processed_total counter | ||
2647 | node_softnet_processed_total{cpu="0"} 299641 | ||
2648 | node_softnet_processed_total{cpu="1"} 916354 | ||
2649 | node_softnet_processed_total{cpu="2"} 5.577791e+06 | ||
2650 | node_softnet_processed_total{cpu="3"} 3.113785e+06 | ||
2651 | # HELP node_softnet_times_squeezed_total Number of times processing packets ran out of quota | ||
2652 | # TYPE node_softnet_times_squeezed_total counter | ||
2653 | node_softnet_times_squeezed_total{cpu="0"} 1 | ||
2654 | node_softnet_times_squeezed_total{cpu="1"} 10 | ||
2655 | node_softnet_times_squeezed_total{cpu="2"} 85 | ||
2656 | node_softnet_times_squeezed_total{cpu="3"} 50 | ||
2638 | # HELP node_textfile_mtime_seconds Unixtime mtime of textfiles successfully read. | 2657 | # HELP node_textfile_mtime_seconds Unixtime mtime of textfiles successfully read. |
2639 | # TYPE node_textfile_mtime_seconds gauge | 2658 | # TYPE node_textfile_mtime_seconds gauge |
2640 | # HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise | 2659 | # HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise |
diff --git a/collector/fixtures/proc/net/softnet_stat b/collector/fixtures/proc/net/softnet_stat new file mode 100644 index 0000000..d5a5a20 --- /dev/null +++ b/collector/fixtures/proc/net/softnet_stat | |||
@@ -0,0 +1,4 @@ | |||
1 | 00049279 00000000 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 | ||
2 | 000dfb82 00000029 0000000a 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 | ||
3 | 00551c3f 00000000 00000055 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 | ||
4 | 002f8339 00000000 00000032 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 \ No newline at end of file | ||
diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go new file mode 100644 index 0000000..3e767ca --- /dev/null +++ b/collector/softnet_linux.go | |||
@@ -0,0 +1,99 @@ | |||
1 | // Copyright 2019 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | // +build !nosoftnet | ||
15 | |||
16 | package collector | ||
17 | |||
18 | import ( | ||
19 | "fmt" | ||
20 | "strconv" | ||
21 | |||
22 | "github.com/prometheus/client_golang/prometheus" | ||
23 | "github.com/prometheus/procfs" | ||
24 | ) | ||
25 | |||
26 | type softnetCollector struct { | ||
27 | fs procfs.FS | ||
28 | processed *prometheus.Desc | ||
29 | dropped *prometheus.Desc | ||
30 | timeSqueezed *prometheus.Desc | ||
31 | } | ||
32 | |||
33 | const ( | ||
34 | softnetSubsystem = "softnet" | ||
35 | ) | ||
36 | |||
37 | func init() { | ||
38 | registerCollector("softnet", defaultEnabled, NewSoftnetCollector) | ||
39 | } | ||
40 | |||
41 | // NewSoftnetCollector returns a new Collector exposing softnet metrics. | ||
42 | func NewSoftnetCollector() (Collector, error) { | ||
43 | fs, err := procfs.NewFS(*procPath) | ||
44 | if err != nil { | ||
45 | return nil, fmt.Errorf("failed to open procfs: %w", err) | ||
46 | } | ||
47 | |||
48 | return &softnetCollector{ | ||
49 | fs: fs, | ||
50 | processed: prometheus.NewDesc( | ||
51 | prometheus.BuildFQName(namespace, softnetSubsystem, "processed_total"), | ||
52 | "Number of processed packets", | ||
53 | []string{"cpu"}, nil, | ||
54 | ), | ||
55 | dropped: prometheus.NewDesc( | ||
56 | prometheus.BuildFQName(namespace, softnetSubsystem, "dropped_total"), | ||
57 | "Number of dropped packets", | ||
58 | []string{"cpu"}, nil, | ||
59 | ), | ||
60 | timeSqueezed: prometheus.NewDesc( | ||
61 | prometheus.BuildFQName(namespace, softnetSubsystem, "times_squeezed_total"), | ||
62 | "Number of times processing packets ran out of quota", | ||
63 | []string{"cpu"}, nil, | ||
64 | ), | ||
65 | }, nil | ||
66 | } | ||
67 | |||
68 | // Update gets parsed softnet statistics using procfs. | ||
69 | func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error { | ||
70 | stats, err := c.fs.GatherSoftnetStats() | ||
71 | if err != nil { | ||
72 | return fmt.Errorf("could not get softnet statistics: %s", err) | ||
73 | } | ||
74 | |||
75 | for cpuNumber, cpuStats := range stats { | ||
76 | cpu := strconv.Itoa(cpuNumber) | ||
77 | |||
78 | ch <- prometheus.MustNewConstMetric( | ||
79 | c.processed, | ||
80 | prometheus.CounterValue, | ||
81 | float64(cpuStats.Processed), | ||
82 | cpu, | ||
83 | ) | ||
84 | ch <- prometheus.MustNewConstMetric( | ||
85 | c.dropped, | ||
86 | prometheus.CounterValue, | ||
87 | float64(cpuStats.Dropped), | ||
88 | cpu, | ||
89 | ) | ||
90 | ch <- prometheus.MustNewConstMetric( | ||
91 | c.timeSqueezed, | ||
92 | prometheus.CounterValue, | ||
93 | float64(cpuStats.TimeSqueezed), | ||
94 | cpu, | ||
95 | ) | ||
96 | } | ||
97 | |||
98 | return nil | ||
99 | } | ||