aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Nicholson <petergoods@hotmail.com>2019-12-30 01:36:10 +0100
committerBen Kochie <superq@gmail.com>2019-12-30 01:36:10 +0100
commita80b7d0bc5ee93e704bab22e7592ed8b7d65899e (patch)
treee535e50150d90de1bcc372e6d88bec7adada67a7
parentcafb12dc59f5b853bdd1167547056428eaddd353 (diff)
downloadprometheus_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.md1
-rw-r--r--README.md1
-rw-r--r--collector/fixtures/e2e-64k-page-output.txt19
-rw-r--r--collector/fixtures/e2e-output.txt19
-rw-r--r--collector/fixtures/proc/net/softnet_stat4
-rw-r--r--collector/softnet_linux.go99
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
diff --git a/README.md b/README.md
index 7a4b9f4..b8bb283 100644
--- a/README.md
+++ b/README.md
@@ -53,6 +53,7 @@ nfsd | Exposes NFS kernel server statistics from `/proc/net/rpc/nfsd`. This is t
53pressure | 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)) 53pressure | 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))
54schedstat | Exposes task scheduler statistics from `/proc/schedstat`. | Linux 54schedstat | Exposes task scheduler statistics from `/proc/schedstat`. | Linux
55sockstat | Exposes various statistics from `/proc/net/sockstat`. | Linux 55sockstat | Exposes various statistics from `/proc/net/sockstat`. | Linux
56softnet | Exposes statistics from `/proc/net/softnet_stat`. | Linux
56stat | Exposes various statistics from `/proc/stat`. This includes boot time, forks and interrupts. | Linux 57stat | Exposes various statistics from `/proc/stat`. This includes boot time, forks and interrupts. | Linux
57textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_ 58textfile | Exposes statistics read from local disk. The `--collector.textfile.directory` flag must be set. | _any_
58thermal\_zone | Exposes thermal zone & cooling device statistics from `/sys/class/thermal`. | Linux 59thermal\_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
2547node_scrape_collector_success{collector="qdisc"} 1 2547node_scrape_collector_success{collector="qdisc"} 1
2548node_scrape_collector_success{collector="schedstat"} 1 2548node_scrape_collector_success{collector="schedstat"} 1
2549node_scrape_collector_success{collector="sockstat"} 1 2549node_scrape_collector_success{collector="sockstat"} 1
2550node_scrape_collector_success{collector="softnet"} 1
2550node_scrape_collector_success{collector="stat"} 1 2551node_scrape_collector_success{collector="stat"} 1
2551node_scrape_collector_success{collector="textfile"} 1 2552node_scrape_collector_success{collector="textfile"} 1
2552node_scrape_collector_success{collector="thermal_zone"} 1 2553node_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
2598node_sockstat_sockets_used 229 2599node_sockstat_sockets_used 229
2600# HELP node_softnet_dropped_total Number of dropped packets
2601# TYPE node_softnet_dropped_total counter
2602node_softnet_dropped_total{cpu="0"} 0
2603node_softnet_dropped_total{cpu="1"} 41
2604node_softnet_dropped_total{cpu="2"} 0
2605node_softnet_dropped_total{cpu="3"} 0
2606# HELP node_softnet_processed_total Number of processed packets
2607# TYPE node_softnet_processed_total counter
2608node_softnet_processed_total{cpu="0"} 299641
2609node_softnet_processed_total{cpu="1"} 916354
2610node_softnet_processed_total{cpu="2"} 5.577791e+06
2611node_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
2614node_softnet_times_squeezed_total{cpu="0"} 1
2615node_softnet_times_squeezed_total{cpu="1"} 10
2616node_softnet_times_squeezed_total{cpu="2"} 85
2617node_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
2568node_scrape_collector_success{collector="qdisc"} 1 2568node_scrape_collector_success{collector="qdisc"} 1
2569node_scrape_collector_success{collector="schedstat"} 1 2569node_scrape_collector_success{collector="schedstat"} 1
2570node_scrape_collector_success{collector="sockstat"} 1 2570node_scrape_collector_success{collector="sockstat"} 1
2571node_scrape_collector_success{collector="softnet"} 1
2571node_scrape_collector_success{collector="stat"} 1 2572node_scrape_collector_success{collector="stat"} 1
2572node_scrape_collector_success{collector="textfile"} 1 2573node_scrape_collector_success{collector="textfile"} 1
2573node_scrape_collector_success{collector="thermal_zone"} 1 2574node_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
2637node_sockstat_sockets_used 229 2638node_sockstat_sockets_used 229
2639# HELP node_softnet_dropped_total Number of dropped packets
2640# TYPE node_softnet_dropped_total counter
2641node_softnet_dropped_total{cpu="0"} 0
2642node_softnet_dropped_total{cpu="1"} 41
2643node_softnet_dropped_total{cpu="2"} 0
2644node_softnet_dropped_total{cpu="3"} 0
2645# HELP node_softnet_processed_total Number of processed packets
2646# TYPE node_softnet_processed_total counter
2647node_softnet_processed_total{cpu="0"} 299641
2648node_softnet_processed_total{cpu="1"} 916354
2649node_softnet_processed_total{cpu="2"} 5.577791e+06
2650node_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
2653node_softnet_times_squeezed_total{cpu="0"} 1
2654node_softnet_times_squeezed_total{cpu="1"} 10
2655node_softnet_times_squeezed_total{cpu="2"} 85
2656node_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 @@
100049279 00000000 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
2000dfb82 00000029 0000000a 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
300551c3f 00000000 00000055 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
4002f8339 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
16package collector
17
18import (
19 "fmt"
20 "strconv"
21
22 "github.com/prometheus/client_golang/prometheus"
23 "github.com/prometheus/procfs"
24)
25
26type softnetCollector struct {
27 fs procfs.FS
28 processed *prometheus.Desc
29 dropped *prometheus.Desc
30 timeSqueezed *prometheus.Desc
31}
32
33const (
34 softnetSubsystem = "softnet"
35)
36
37func init() {
38 registerCollector("softnet", defaultEnabled, NewSoftnetCollector)
39}
40
41// NewSoftnetCollector returns a new Collector exposing softnet metrics.
42func 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.
69func (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}