aboutsummaryrefslogtreecommitdiff
path: root/collector/xfs_linux.go
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 /collector/xfs_linux.go
parente7ea5c1867e0c5ffe2c9c964a941139ff66cbbf9 (diff)
downloadprometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.tar.bz2
prometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.tar.xz
prometheus_node_collector-1feb091b367bd3a70bad818a0c26088ede857471.zip
Initial XFS collector
Diffstat (limited to 'collector/xfs_linux.go')
-rw-r--r--collector/xfs_linux.go140
1 files changed, 140 insertions, 0 deletions
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}