aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Brazil <brian.brazil@robustperception.io>2018-03-29 16:34:52 +0100
committerBrian Brazil <brian.brazil@robustperception.io>2018-03-29 22:00:02 +0100
commit499c342fed469de88a6c102d50bfc61853520d2d (patch)
treee9e4f53687c06604f9b5cfa74bfa0569772f5441
parentc8c144587e6afa4821a5f3a685f4a7953e91918c (diff)
downloadprometheus_node_collector-499c342fed469de88a6c102d50bfc61853520d2d.tar.bz2
prometheus_node_collector-499c342fed469de88a6c102d50bfc61853520d2d.tar.xz
prometheus_node_collector-499c342fed469de88a6c102d50bfc61853520d2d.zip
Greatly reduce the metrics vmstat returns by default.
Vmstat has over 100 fields, most of which are highly detailed debug information. Trim this down to only essential fields by default, configurable by flag. Signed-off-by: Brian Brazil <brian.brazil@robustperception.io>
-rw-r--r--collector/fixtures/e2e-output.txt19
-rw-r--r--collector/fixtures/proc/vmstat119
-rw-r--r--collector/vmstat_linux.go18
-rwxr-xr-xend-to-end-test.sh4
4 files changed, 156 insertions, 4 deletions
diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt
index 48e5fed..03db85a 100644
--- a/collector/fixtures/e2e-output.txt
+++ b/collector/fixtures/e2e-output.txt
@@ -2739,6 +2739,7 @@ node_scrape_collector_success{collector="qdisc"} 1
2739node_scrape_collector_success{collector="sockstat"} 1 2739node_scrape_collector_success{collector="sockstat"} 1
2740node_scrape_collector_success{collector="stat"} 1 2740node_scrape_collector_success{collector="stat"} 1
2741node_scrape_collector_success{collector="textfile"} 1 2741node_scrape_collector_success{collector="textfile"} 1
2742node_scrape_collector_success{collector="vmstat"} 1
2742node_scrape_collector_success{collector="wifi"} 1 2743node_scrape_collector_success{collector="wifi"} 1
2743node_scrape_collector_success{collector="xfs"} 1 2744node_scrape_collector_success{collector="xfs"} 1
2744node_scrape_collector_success{collector="zfs"} 1 2745node_scrape_collector_success{collector="zfs"} 1
@@ -2789,6 +2790,24 @@ node_sockstat_sockets_used 229
2789# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise 2790# HELP node_textfile_scrape_error 1 if there was an error opening or reading a file, 0 otherwise
2790# TYPE node_textfile_scrape_error gauge 2791# TYPE node_textfile_scrape_error gauge
2791node_textfile_scrape_error 0 2792node_textfile_scrape_error 0
2793# HELP node_vmstat_pgfault /proc/vmstat information field pgfault.
2794# TYPE node_vmstat_pgfault untyped
2795node_vmstat_pgfault 2.320168809e+09
2796# HELP node_vmstat_pgmajfault /proc/vmstat information field pgmajfault.
2797# TYPE node_vmstat_pgmajfault untyped
2798node_vmstat_pgmajfault 507162
2799# HELP node_vmstat_pgpgin /proc/vmstat information field pgpgin.
2800# TYPE node_vmstat_pgpgin untyped
2801node_vmstat_pgpgin 7.344136e+06
2802# HELP node_vmstat_pgpgout /proc/vmstat information field pgpgout.
2803# TYPE node_vmstat_pgpgout untyped
2804node_vmstat_pgpgout 1.541180581e+09
2805# HELP node_vmstat_pswpin /proc/vmstat information field pswpin.
2806# TYPE node_vmstat_pswpin untyped
2807node_vmstat_pswpin 1476
2808# HELP node_vmstat_pswpout /proc/vmstat information field pswpout.
2809# TYPE node_vmstat_pswpout untyped
2810node_vmstat_pswpout 35045
2792# HELP node_wifi_interface_frequency_hertz The current frequency a WiFi interface is operating at, in hertz. 2811# HELP node_wifi_interface_frequency_hertz The current frequency a WiFi interface is operating at, in hertz.
2793# TYPE node_wifi_interface_frequency_hertz gauge 2812# TYPE node_wifi_interface_frequency_hertz gauge
2794node_wifi_interface_frequency_hertz{device="wlan0"} 2.412e+09 2813node_wifi_interface_frequency_hertz{device="wlan0"} 2.412e+09
diff --git a/collector/fixtures/proc/vmstat b/collector/fixtures/proc/vmstat
new file mode 100644
index 0000000..29b3f58
--- /dev/null
+++ b/collector/fixtures/proc/vmstat
@@ -0,0 +1,119 @@
1nr_free_pages 977769
2nr_alloc_batch 4158
3nr_inactive_anon 125031
4nr_active_anon 622512
5nr_inactive_file 92317
6nr_active_file 324014
7nr_unevictable 12
8nr_mlock 12
9nr_anon_pages 713633
10nr_mapped 118021
11nr_file_pages 450840
12nr_dirty 21
13nr_writeback 0
14nr_slab_reclaimable 85763
15nr_slab_unreclaimable 431112
16nr_page_table_pages 12504
17nr_kernel_stack 1156
18nr_overhead 4956
19nr_unstable 0
20nr_bounce 0
21nr_vmscan_write 35050
22nr_vmscan_immediate_reclaim 27
23nr_writeback_temp 0
24nr_isolated_anon 0
25nr_isolated_file 0
26nr_shmem 20623
27nr_dirtied 11127183
28nr_written 11122061
29nr_pages_scanned 0
30numa_hit 2601972389
31numa_miss 0
32numa_foreign 0
33numa_interleave 32353
34numa_local 2601972389
35numa_other 0
36workingset_refault 157066
37workingset_activate 104270
38workingset_nodereclaim 0
39nr_anon_transparent_hugepages 556
40nr_free_cma 0
41nr_dirty_threshold 270390
42nr_dirty_background_threshold 135030
43pgpgin 7344136
44pgpgout 1541180581
45pswpin 1476
46pswpout 35045
47pgalloc_dma 12
48pgalloc_dma32 611781566
49pgalloc_normal 2287227526
50pgalloc_movable 0
51pgfree 2938719870
52pgactivate 152952989
53pgdeactivate 898450
54pgfault 2320168809
55pgmajfault 507162
56pgrefill_dma 0
57pgrefill_dma32 186367
58pgrefill_normal 603970
59pgrefill_movable 0
60pgsteal_kswapd_dma 0
61pgsteal_kswapd_dma32 78783
62pgsteal_kswapd_normal 254128
63pgsteal_kswapd_movable 0
64pgsteal_direct_dma 0
65pgsteal_direct_dma32 44
66pgsteal_direct_normal 6484
67pgsteal_direct_movable 0
68pgscan_kswapd_dma 0
69pgscan_kswapd_dma32 107656
70pgscan_kswapd_normal 358784
71pgscan_kswapd_movable 0
72pgscan_direct_dma 0
73pgscan_direct_dma32 67
74pgscan_direct_normal 6796
75pgscan_direct_movable 0
76pgscan_direct_throttle 0
77zone_reclaim_failed 0
78pginodesteal 412258
79slabs_scanned 14355346
80kswapd_inodesteal 288891
81kswapd_low_wmark_hit_quickly 109
82kswapd_high_wmark_hit_quickly 45
83pageoutrun 247
84allocstall 83165
85pgrotated 35014
86drop_pagecache 0
87drop_slab 0
88numa_pte_updates 0
89numa_huge_pte_updates 0
90numa_hint_faults 0
91numa_hint_faults_local 0
92numa_pages_migrated 0
93pgmigrate_success 37070309
94pgmigrate_fail 36815
95compact_migrate_scanned 830267783
96compact_free_scanned 12336622550
97compact_isolated 82707414
98compact_stall 210959
99compact_fail 164840
100compact_success 46119
101htlb_buddy_alloc_success 0
102htlb_buddy_alloc_fail 0
103unevictable_pgs_culled 2188
104unevictable_pgs_scanned 0
105unevictable_pgs_rescued 3962
106unevictable_pgs_mlocked 3994
107unevictable_pgs_munlocked 3968
108unevictable_pgs_cleared 14
109unevictable_pgs_stranded 14
110thp_fault_alloc 142261
111thp_fault_fallback 98119
112thp_collapse_alloc 88421
113thp_collapse_alloc_failed 20954
114thp_split 69984
115thp_zero_page_alloc 9
116thp_zero_page_alloc_failed 20
117balloon_inflate 0
118balloon_deflate 0
119balloon_migrate 0
diff --git a/collector/vmstat_linux.go b/collector/vmstat_linux.go
index 0b9b2b5..13dd192 100644
--- a/collector/vmstat_linux.go
+++ b/collector/vmstat_linux.go
@@ -19,17 +19,25 @@ import (
19 "bufio" 19 "bufio"
20 "fmt" 20 "fmt"
21 "os" 21 "os"
22 "regexp"
22 "strconv" 23 "strconv"
23 "strings" 24 "strings"
24 25
25 "github.com/prometheus/client_golang/prometheus" 26 "github.com/prometheus/client_golang/prometheus"
27 "gopkg.in/alecthomas/kingpin.v2"
26) 28)
27 29
28const ( 30const (
29 vmStatSubsystem = "vmstat" 31 vmStatSubsystem = "vmstat"
30) 32)
31 33
32type vmStatCollector struct{} 34var (
35 vmStatFields = kingpin.Flag("collector.vmstat.fields", "Regexp of fields to return for vmstat collector.").Default("^(pgpg|pswp|pg.*fault|oom_kill).*").String()
36)
37
38type vmStatCollector struct {
39 fieldPattern *regexp.Regexp
40}
33 41
34func init() { 42func init() {
35 registerCollector("vmstat", defaultEnabled, NewvmStatCollector) 43 registerCollector("vmstat", defaultEnabled, NewvmStatCollector)
@@ -37,7 +45,10 @@ func init() {
37 45
38// NewvmStatCollector returns a new Collector exposing vmstat stats. 46// NewvmStatCollector returns a new Collector exposing vmstat stats.
39func NewvmStatCollector() (Collector, error) { 47func NewvmStatCollector() (Collector, error) {
40 return &vmStatCollector{}, nil 48 pattern := regexp.MustCompile(*vmStatFields)
49 return &vmStatCollector{
50 fieldPattern: pattern,
51 }, nil
41} 52}
42 53
43func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error { 54func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
@@ -54,6 +65,9 @@ func (c *vmStatCollector) Update(ch chan<- prometheus.Metric) error {
54 if err != nil { 65 if err != nil {
55 return err 66 return err
56 } 67 }
68 if !c.fieldPattern.MatchString(parts[0]) {
69 continue
70 }
57 71
58 ch <- prometheus.MustNewConstMetric( 72 ch <- prometheus.MustNewConstMetric(
59 prometheus.NewDesc( 73 prometheus.NewDesc(
diff --git a/end-to-end-test.sh b/end-to-end-test.sh
index e47cdaa..152aa98 100755
--- a/end-to-end-test.sh
+++ b/end-to-end-test.sh
@@ -32,6 +32,7 @@ enabled_collectors=$(cat << COLLECTORS
32 stat 32 stat
33 textfile 33 textfile
34 bonding 34 bonding
35 vmstat
35 wifi 36 wifi
36 xfs 37 xfs
37 zfs 38 zfs
@@ -42,7 +43,6 @@ disabled_collectors=$(cat << COLLECTORS
42 time 43 time
43 timex 44 timex
44 uname 45 uname
45 vmstat
46COLLECTORS 46COLLECTORS
47) 47)
48cd "$(dirname $0)" 48cd "$(dirname $0)"
@@ -148,4 +148,4 @@ get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-outpu
148 148
149diff -u \ 149diff -u \
150 "${fixture}" \ 150 "${fixture}" \
151 "${tmpdir}/e2e-output.txt" \ No newline at end of file 151 "${tmpdir}/e2e-output.txt"