aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Layher <mdlayher@gmail.com>2017-04-21 18:19:35 -0400
committerMatt Layher <mdlayher@gmail.com>2017-04-22 11:53:07 -0400
commit1feb091b367bd3a70bad818a0c26088ede857471 (patch)
treeb6cf56188209d5bd203eec7aa622b19e663cf5ca
parente7ea5c1867e0c5ffe2c9c964a941139ff66cbbf9 (diff)
downloadprometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.tar.bz2
prometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.tar.xz
prometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.zip
Initial XFS collector
-rw-r--r--README.md1
-rw-r--r--collector/fixtures/e2e-output.txt25
-rw-r--r--collector/fixtures/sys/fs/xfs/sda1/stats/stats24
-rw-r--r--collector/xfs_linux.go140
-rwxr-xr-xend-to-end-test.sh1
-rw-r--r--node_exporter.go2
-rw-r--r--vendor/github.com/prometheus/procfs/sysfs/doc.go16
-rw-r--r--vendor/github.com/prometheus/procfs/sysfs/fs.go82
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/parse.go2
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/xfs.go5
-rw-r--r--vendor/vendor.json16
11 files changed, 306 insertions, 8 deletions
diff --git a/README.md b/README.md
index 94a1a65..918a8cc 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,7 @@ time | Exposes the current system time. | _any_
44uname | Exposes system information as provided by the uname system call. | Linux 44uname | Exposes system information as provided by the uname system call. | Linux
45vmstat | Exposes statistics from `/proc/vmstat`. | Linux 45vmstat | Exposes statistics from `/proc/vmstat`. | Linux
46wifi | Exposes WiFi device and station statistics. | Linux 46wifi | Exposes WiFi device and station statistics. | Linux
47xfs | Exposes XFS runtime statistics. | Linux (kernel 4.4+)
47zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/) 48zfs | Exposes [ZFS](http://open-zfs.org/) performance statistics. | [Linux](http://zfsonlinux.org/)
48 49
49### Disabled by default 50### Disabled by default
diff --git a/collector/fixtures/e2e-output.txt b/collector/fixtures/e2e-output.txt
index 68ef54b..3e48a1c 100644
--- a/collector/fixtures/e2e-output.txt
+++ b/collector/fixtures/e2e-output.txt
@@ -2143,6 +2143,7 @@ node_scrape_collector_success{collector="sockstat"} 1
2143node_scrape_collector_success{collector="stat"} 1 2143node_scrape_collector_success{collector="stat"} 1
2144node_scrape_collector_success{collector="textfile"} 1 2144node_scrape_collector_success{collector="textfile"} 1
2145node_scrape_collector_success{collector="wifi"} 1 2145node_scrape_collector_success{collector="wifi"} 1
2146node_scrape_collector_success{collector="xfs"} 1
2146node_scrape_collector_success{collector="zfs"} 1 2147node_scrape_collector_success{collector="zfs"} 1
2147# HELP node_sockstat_FRAG_inuse Number of FRAG sockets in state inuse. 2148# HELP node_sockstat_FRAG_inuse Number of FRAG sockets in state inuse.
2148# TYPE node_sockstat_FRAG_inuse gauge 2149# TYPE node_sockstat_FRAG_inuse gauge
@@ -2222,6 +2223,30 @@ node_wifi_station_transmit_failed_total{device="wlan0"} 2
2222# HELP node_wifi_station_transmit_retries_total The total number of times a station has had to retry while sending a packet. 2223# HELP node_wifi_station_transmit_retries_total The total number of times a station has had to retry while sending a packet.
2223# TYPE node_wifi_station_transmit_retries_total counter 2224# TYPE node_wifi_station_transmit_retries_total counter
2224node_wifi_station_transmit_retries_total{device="wlan0"} 10 2225node_wifi_station_transmit_retries_total{device="wlan0"} 10
2226# HELP node_xfs_allocation_btree_compares_total Number of allocation B-tree compares for a filesystem.
2227# TYPE node_xfs_allocation_btree_compares_total counter
2228node_xfs_allocation_btree_compares_total{device="sda1"} 0
2229# HELP node_xfs_allocation_btree_lookups_total Number of allocation B-tree lookups for a filesystem.
2230# TYPE node_xfs_allocation_btree_lookups_total counter
2231node_xfs_allocation_btree_lookups_total{device="sda1"} 0
2232# HELP node_xfs_allocation_btree_records_deleted_total Number of allocation B-tree records deleted for a filesystem.
2233# TYPE node_xfs_allocation_btree_records_deleted_total counter
2234node_xfs_allocation_btree_records_deleted_total{device="sda1"} 0
2235# HELP node_xfs_allocation_btree_records_inserted_total Number of allocation B-tree records inserted for a filesystem.
2236# TYPE node_xfs_allocation_btree_records_inserted_total counter
2237node_xfs_allocation_btree_records_inserted_total{device="sda1"} 0
2238# HELP node_xfs_extent_allocation_blocks_allocated_total Number of blocks allocated for a filesystem.
2239# TYPE node_xfs_extent_allocation_blocks_allocated_total counter
2240node_xfs_extent_allocation_blocks_allocated_total{device="sda1"} 872
2241# HELP node_xfs_extent_allocation_blocks_freed_total Number of blocks freed for a filesystem.
2242# TYPE node_xfs_extent_allocation_blocks_freed_total counter
2243node_xfs_extent_allocation_blocks_freed_total{device="sda1"} 0
2244# HELP node_xfs_extent_allocation_extents_allocated_total Number of extents allocated for a filesystem.
2245# TYPE node_xfs_extent_allocation_extents_allocated_total counter
2246node_xfs_extent_allocation_extents_allocated_total{device="sda1"} 1
2247# HELP node_xfs_extent_allocation_extents_freed_total Number of extents freed for a filesystem.
2248# TYPE node_xfs_extent_allocation_extents_freed_total counter
2249node_xfs_extent_allocation_extents_freed_total{device="sda1"} 0
2225# HELP node_zfs_arc_anon_evictable_data kstat.zfs.misc.arcstats.anon_evictable_data 2250# HELP node_zfs_arc_anon_evictable_data kstat.zfs.misc.arcstats.anon_evictable_data
2226# TYPE node_zfs_arc_anon_evictable_data untyped 2251# TYPE node_zfs_arc_anon_evictable_data untyped
2227node_zfs_arc_anon_evictable_data 0 2252node_zfs_arc_anon_evictable_data 0
diff --git a/collector/fixtures/sys/fs/xfs/sda1/stats/stats b/collector/fixtures/sys/fs/xfs/sda1/stats/stats
new file mode 100644
index 0000000..d5c04d9
--- /dev/null
+++ b/collector/fixtures/sys/fs/xfs/sda1/stats/stats
@@ -0,0 +1,24 @@
1extent_alloc 1 872 0 0
2abt 0 0 0 0
3blk_map 61 29 1 1 1 91 0
4bmbt 0 0 0 0
5dir 3 2 1 52
6trans 4 40 0
7ig 5 1 0 4 0 0 1
8log 8 21 0 5821 4
9push_ail 44 0 1102 15 0 2 0 2 0 2
10xstrat 1 0
11rw 28 0
12attr 0 0 0 0
13icluster 2 2 2
14vnodes 4 0 0 0 1 1 1 0
15buf 22 25 14 0 0 8 0 8 8
16abtb2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0
17abtc2 2 1 1 1 0 0 0 0 0 0 0 0 0 0 0
18bmbt2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
19ibt2 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0
20fibt2 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0
21rmapbt 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
22qm 0 0 0 0 0 0 0 0
23xpc 3571712 3568056 0
24debug 0
diff --git a/collector/xfs_linux.go b/collector/xfs_linux.go
new file mode 100644
index 0000000..849cbff
--- /dev/null
+++ b/collector/xfs_linux.go
@@ -0,0 +1,140 @@
1// Copyright 2017 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
14package collector
15
16import (
17 "fmt"
18
19 "github.com/prometheus/client_golang/prometheus"
20 "github.com/prometheus/procfs/sysfs"
21 "github.com/prometheus/procfs/xfs"
22)
23
24// An xfsCollector is a Collector which gathers metrics from XFS filesystems.
25type xfsCollector struct {
26 fs sysfs.FS
27}
28
29func init() {
30 Factories["xfs"] = NewXFSCollector
31}
32
33// NewXFSCollector returns a new Collector exposing XFS statistics.
34func NewXFSCollector() (Collector, error) {
35 fs, err := sysfs.NewFS(*sysPath)
36 if err != nil {
37 return nil, fmt.Errorf("failed to open sysfs: %v", err)
38 }
39
40 return &xfsCollector{
41 fs: fs,
42 }, nil
43}
44
45// Update implements Collector.
46func (c *xfsCollector) Update(ch chan<- prometheus.Metric) error {
47 stats, err := c.fs.XFSStats()
48 if err != nil {
49 return fmt.Errorf("failed to retrieve XFS stats: %v", err)
50 }
51
52 for _, s := range stats {
53 c.updateXFSStats(ch, s)
54 }
55
56 return nil
57}
58
59// updateXFSStats collects statistics for a single XFS filesystem.
60func (c *xfsCollector) updateXFSStats(ch chan<- prometheus.Metric, s *xfs.Stats) {
61 const (
62 subsystem = "xfs"
63 )
64
65 var (
66 labels = []string{"device"}
67 )
68
69 // Metric names and descriptions are sourced from:
70 // http://xfs.org/index.php/Runtime_Stats.
71 //
72 // Each metric has a name that roughly follows the pattern of
73 // "node_xfs_category_value_total", using the categories and value names
74 // found on the XFS wiki.
75 //
76 // Note that statistics for more than one internal B-tree are measured,
77 // and as such, each one must be differentiated by name.
78 metrics := []struct {
79 name string
80 desc string
81 value float64
82 }{
83 {
84 name: "extent_allocation_extents_allocated_total",
85 desc: "Number of extents allocated for a filesystem.",
86 value: float64(s.ExtentAllocation.ExtentsAllocated),
87 },
88 {
89 name: "extent_allocation_blocks_allocated_total",
90 desc: "Number of blocks allocated for a filesystem.",
91 value: float64(s.ExtentAllocation.BlocksAllocated),
92 },
93 {
94 name: "extent_allocation_extents_freed_total",
95 desc: "Number of extents freed for a filesystem.",
96 value: float64(s.ExtentAllocation.ExtentsFreed),
97 },
98 {
99 name: "extent_allocation_blocks_freed_total",
100 desc: "Number of blocks freed for a filesystem.",
101 value: float64(s.ExtentAllocation.BlocksFreed),
102 },
103 {
104 name: "allocation_btree_lookups_total",
105 desc: "Number of allocation B-tree lookups for a filesystem.",
106 value: float64(s.AllocationBTree.Lookups),
107 },
108 {
109 name: "allocation_btree_compares_total",
110 desc: "Number of allocation B-tree compares for a filesystem.",
111 value: float64(s.AllocationBTree.Compares),
112 },
113 {
114 name: "allocation_btree_records_inserted_total",
115 desc: "Number of allocation B-tree records inserted for a filesystem.",
116 value: float64(s.AllocationBTree.RecordsInserted),
117 },
118 {
119 name: "allocation_btree_records_deleted_total",
120 desc: "Number of allocation B-tree records deleted for a filesystem.",
121 value: float64(s.AllocationBTree.RecordsDeleted),
122 },
123 }
124
125 for _, m := range metrics {
126 desc := prometheus.NewDesc(
127 prometheus.BuildFQName(Namespace, subsystem, m.name),
128 m.desc,
129 labels,
130 nil,
131 )
132
133 ch <- prometheus.MustNewConstMetric(
134 desc,
135 prometheus.CounterValue,
136 m.value,
137 s.Name,
138 )
139 }
140}
diff --git a/end-to-end-test.sh b/end-to-end-test.sh
index f47fbb5..c68d89c 100755
--- a/end-to-end-test.sh
+++ b/end-to-end-test.sh
@@ -28,6 +28,7 @@ collectors=$(cat << COLLECTORS
28 bonding 28 bonding
29 megacli 29 megacli
30 wifi 30 wifi
31 xfs
31 zfs 32 zfs
32COLLECTORS 33COLLECTORS
33) 34)
diff --git a/node_exporter.go b/node_exporter.go
index f6daa2d..f5ef01e 100644
--- a/node_exporter.go
+++ b/node_exporter.go
@@ -32,7 +32,7 @@ import (
32) 32)
33 33
34const ( 34const (
35 defaultCollectors = "arp,conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,zfs" 35 defaultCollectors = "arp,conntrack,cpu,diskstats,entropy,edac,exec,filefd,filesystem,hwmon,infiniband,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,time,uname,vmstat,wifi,xfs,zfs"
36) 36)
37 37
38var ( 38var (
diff --git a/vendor/github.com/prometheus/procfs/sysfs/doc.go b/vendor/github.com/prometheus/procfs/sysfs/doc.go
new file mode 100644
index 0000000..9a6c244
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/sysfs/doc.go
@@ -0,0 +1,16 @@
1// Copyright 2017 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// Package sysfs provides functions to retrieve system and kernel metrics
15// from the pseudo-filesystem sys.
16package sysfs
diff --git a/vendor/github.com/prometheus/procfs/sysfs/fs.go b/vendor/github.com/prometheus/procfs/sysfs/fs.go
new file mode 100644
index 0000000..8e83800
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/sysfs/fs.go
@@ -0,0 +1,82 @@
1// Copyright 2017 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
14package sysfs
15
16import (
17 "fmt"
18 "os"
19 "path/filepath"
20
21 "github.com/prometheus/procfs/xfs"
22)
23
24// FS represents the pseudo-filesystem sys, which provides an interface to
25// kernel data structures.
26type FS string
27
28// DefaultMountPoint is the common mount point of the sys filesystem.
29const DefaultMountPoint = "/sys"
30
31// NewFS returns a new FS mounted under the given mountPoint. It will error
32// if the mount point can't be read.
33func NewFS(mountPoint string) (FS, error) {
34 info, err := os.Stat(mountPoint)
35 if err != nil {
36 return "", fmt.Errorf("could not read %s: %s", mountPoint, err)
37 }
38 if !info.IsDir() {
39 return "", fmt.Errorf("mount point %s is not a directory", mountPoint)
40 }
41
42 return FS(mountPoint), nil
43}
44
45// Path returns the path of the given subsystem relative to the sys root.
46func (fs FS) Path(p ...string) string {
47 return filepath.Join(append([]string{string(fs)}, p...)...)
48}
49
50// XFSStats retrieves XFS filesystem runtime statistics for each mounted XFS
51// filesystem. Only available on kernel 4.4+. On older kernels, an empty
52// slice of *xfs.Stats will be returned.
53func (fs FS) XFSStats() ([]*xfs.Stats, error) {
54 matches, err := filepath.Glob(fs.Path("fs/xfs/*/stats/stats"))
55 if err != nil {
56 return nil, err
57 }
58
59 stats := make([]*xfs.Stats, 0, len(matches))
60 for _, m := range matches {
61 f, err := os.Open(m)
62 if err != nil {
63 return nil, err
64 }
65
66 // "*" used in glob above indicates the name of the filesystem.
67 name := filepath.Base(filepath.Dir(filepath.Dir(m)))
68
69 // File must be closed after parsing, regardless of success or
70 // failure. Defer is not used because of the loop.
71 s, err := xfs.ParseStats(f)
72 _ = f.Close()
73 if err != nil {
74 return nil, err
75 }
76
77 s.Name = name
78 stats = append(stats, s)
79 }
80
81 return stats, nil
82}
diff --git a/vendor/github.com/prometheus/procfs/xfs/parse.go b/vendor/github.com/prometheus/procfs/xfs/parse.go
index d1285fa..c8f6279 100644
--- a/vendor/github.com/prometheus/procfs/xfs/parse.go
+++ b/vendor/github.com/prometheus/procfs/xfs/parse.go
@@ -17,7 +17,6 @@ import (
17 "bufio" 17 "bufio"
18 "fmt" 18 "fmt"
19 "io" 19 "io"
20 "log"
21 "strconv" 20 "strconv"
22 "strings" 21 "strings"
23) 22)
@@ -273,7 +272,6 @@ func vnodeStats(us []uint32) (VnodeStats, error) {
273 // stats versions. Therefore, 7 or 8 elements may appear in 272 // stats versions. Therefore, 7 or 8 elements may appear in
274 // this slice. 273 // this slice.
275 l := len(us) 274 l := len(us)
276 log.Println(l)
277 if l != 7 && l != 8 { 275 if l != 7 && l != 8 {
278 return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l) 276 return VnodeStats{}, fmt.Errorf("incorrect number of values for XFS vnode stats: %d", l)
279 } 277 }
diff --git a/vendor/github.com/prometheus/procfs/xfs/xfs.go b/vendor/github.com/prometheus/procfs/xfs/xfs.go
index ed77d90..d86794b 100644
--- a/vendor/github.com/prometheus/procfs/xfs/xfs.go
+++ b/vendor/github.com/prometheus/procfs/xfs/xfs.go
@@ -22,6 +22,11 @@ package xfs
22// kernel source. Most counters are uint32s (same data types used in 22// kernel source. Most counters are uint32s (same data types used in
23// xfs_stats.h), but some of the "extended precision stats" are uint64s. 23// xfs_stats.h), but some of the "extended precision stats" are uint64s.
24type Stats struct { 24type Stats struct {
25 // The name of the filesystem used to source these statistics.
26 // If empty, this indicates aggregated statistics for all XFS
27 // filesystems on the host.
28 Name string
29
25 ExtentAllocation ExtentAllocationStats 30 ExtentAllocation ExtentAllocationStats
26 AllocationBTree BTreeStats 31 AllocationBTree BTreeStats
27 BlockMapping BlockMappingStats 32 BlockMapping BlockMappingStats
diff --git a/vendor/vendor.json b/vendor/vendor.json
index cce2597..1928d02 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -131,14 +131,20 @@
131 { 131 {
132 "checksumSHA1": "cD4xn1qxbkiuXqUExpdnDroCTrY=", 132 "checksumSHA1": "cD4xn1qxbkiuXqUExpdnDroCTrY=",
133 "path": "github.com/prometheus/procfs", 133 "path": "github.com/prometheus/procfs",
134 "revision": "a1dba9ce8baed984a2495b658c82687f8157b98f", 134 "revision": "332f6238064950a97bc3ed3f5421f6418537e707",
135 "revisionTime": "2017-02-16T22:32:56Z" 135 "revisionTime": "2017-04-21T21:58:51Z"
136 }, 136 },
137 { 137 {
138 "checksumSHA1": "kOWRcAHWFkId0aCIOSOyjzC0Zfc=", 138 "checksumSHA1": "eiBAd4edewJTOtTwxh/ubJdjd+I=",
139 "path": "github.com/prometheus/procfs/sysfs",
140 "revision": "332f6238064950a97bc3ed3f5421f6418537e707",
141 "revisionTime": "2017-04-21T21:58:51Z"
142 },
143 {
144 "checksumSHA1": "xCiFAAwVTrjsfZT1BIJQ3DgeNCY=",
139 "path": "github.com/prometheus/procfs/xfs", 145 "path": "github.com/prometheus/procfs/xfs",
140 "revision": "a1dba9ce8baed984a2495b658c82687f8157b98f", 146 "revision": "332f6238064950a97bc3ed3f5421f6418537e707",
141 "revisionTime": "2017-02-16T22:32:56Z" 147 "revisionTime": "2017-04-21T21:58:51Z"
142 }, 148 },
143 { 149 {
144 "checksumSHA1": "uozMgPjB4AggpuuJkGq3FgAs4CA=", 150 "checksumSHA1": "uozMgPjB4AggpuuJkGq3FgAs4CA=",