diff options
author | kadota kyohei <lufia@users.noreply.github.com> | 2017-07-06 20:51:24 +0900 |
---|---|---|
committer | Johannes 'fish' Ziemke <github@freigeist.org> | 2017-07-06 13:51:24 +0200 |
commit | a077024f51594ff531f04fefe588c39ddf04d5f7 (patch) | |
tree | e2d7df3a3deb49e2857ae5229c1d49359dd09bd8 /collector/diskstats_darwin.go | |
parent | ab3414e6fd08f45c5609ef1422338c240ec5a943 (diff) | |
download | prometheus_node_collector-a077024f51594ff531f04fefe588c39ddf04d5f7.tar.bz2 prometheus_node_collector-a077024f51594ff531f04fefe588c39ddf04d5f7.tar.xz prometheus_node_collector-a077024f51594ff531f04fefe588c39ddf04d5f7.zip |
add diskstats on Darwin (#593)
* Add diskstats collector for Darwin
* Update year in the header
* Update README.md
* Add github.com/lufia/iostat to vendored packages
* Change stats to follow naming guidelines
* Add a entry of github.com/lufia/iostat into vendor.json
* Remove /proc/diskstats from description
Diffstat (limited to 'collector/diskstats_darwin.go')
-rw-r--r-- | collector/diskstats_darwin.go | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go new file mode 100644 index 0000000..753bfc6 --- /dev/null +++ b/collector/diskstats_darwin.go | |||
@@ -0,0 +1,177 @@ | |||
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 | // +build !nodiskstats | ||
15 | |||
16 | package collector | ||
17 | |||
18 | import ( | ||
19 | "fmt" | ||
20 | |||
21 | "github.com/lufia/iostat" | ||
22 | "github.com/prometheus/client_golang/prometheus" | ||
23 | ) | ||
24 | |||
25 | const ( | ||
26 | diskSubsystem = "disk" | ||
27 | ) | ||
28 | |||
29 | type typedDescFunc struct { | ||
30 | typedDesc | ||
31 | value func(stat *iostat.DriveStats) float64 | ||
32 | } | ||
33 | |||
34 | type diskstatsCollector struct { | ||
35 | descs []typedDescFunc | ||
36 | } | ||
37 | |||
38 | func init() { | ||
39 | Factories["diskstats"] = NewDiskstatsCollector | ||
40 | } | ||
41 | |||
42 | // NewDiskstatsCollector returns a new Collector exposing disk device stats. | ||
43 | func NewDiskstatsCollector() (Collector, error) { | ||
44 | var diskLabelNames = []string{"device"} | ||
45 | |||
46 | return &diskstatsCollector{ | ||
47 | descs: []typedDescFunc{ | ||
48 | { | ||
49 | typedDesc: typedDesc{ | ||
50 | desc: prometheus.NewDesc( | ||
51 | prometheus.BuildFQName(Namespace, diskSubsystem, "reads_completed_total"), | ||
52 | "The total number of reads completed successfully.", | ||
53 | diskLabelNames, | ||
54 | nil, | ||
55 | ), | ||
56 | valueType: prometheus.CounterValue, | ||
57 | }, | ||
58 | value: func(stat *iostat.DriveStats) float64 { | ||
59 | return float64(stat.NumRead) | ||
60 | }, | ||
61 | }, | ||
62 | { | ||
63 | typedDesc: typedDesc{ | ||
64 | desc: prometheus.NewDesc( | ||
65 | prometheus.BuildFQName(Namespace, diskSubsystem, "read_sectors_total"), | ||
66 | "The total number of sectors read successfully.", | ||
67 | diskLabelNames, | ||
68 | nil, | ||
69 | ), | ||
70 | valueType: prometheus.CounterValue, | ||
71 | }, | ||
72 | value: func(stat *iostat.DriveStats) float64 { | ||
73 | return float64(stat.NumRead) / float64(stat.BlockSize) | ||
74 | }, | ||
75 | }, | ||
76 | { | ||
77 | typedDesc: typedDesc{ | ||
78 | desc: prometheus.NewDesc( | ||
79 | prometheus.BuildFQName(Namespace, diskSubsystem, "read_seconds_total"), | ||
80 | "The total number of seconds spent by all reads.", | ||
81 | diskLabelNames, | ||
82 | nil, | ||
83 | ), | ||
84 | valueType: prometheus.CounterValue, | ||
85 | }, | ||
86 | value: func(stat *iostat.DriveStats) float64 { | ||
87 | return stat.TotalReadTime.Seconds() | ||
88 | }, | ||
89 | }, | ||
90 | { | ||
91 | typedDesc: typedDesc{ | ||
92 | desc: prometheus.NewDesc( | ||
93 | prometheus.BuildFQName(Namespace, diskSubsystem, "writes_completed_total"), | ||
94 | "The total number of writes completed successfully.", | ||
95 | diskLabelNames, | ||
96 | nil, | ||
97 | ), | ||
98 | valueType: prometheus.CounterValue, | ||
99 | }, | ||
100 | value: func(stat *iostat.DriveStats) float64 { | ||
101 | return float64(stat.NumWrite) | ||
102 | }, | ||
103 | }, | ||
104 | { | ||
105 | typedDesc: typedDesc{ | ||
106 | desc: prometheus.NewDesc( | ||
107 | prometheus.BuildFQName(Namespace, diskSubsystem, "written_sectors_total"), | ||
108 | "The total number of sectors written successfully.", | ||
109 | diskLabelNames, | ||
110 | nil, | ||
111 | ), | ||
112 | valueType: prometheus.CounterValue, | ||
113 | }, | ||
114 | value: func(stat *iostat.DriveStats) float64 { | ||
115 | return float64(stat.NumWrite) / float64(stat.BlockSize) | ||
116 | }, | ||
117 | }, | ||
118 | { | ||
119 | typedDesc: typedDesc{ | ||
120 | desc: prometheus.NewDesc( | ||
121 | prometheus.BuildFQName(Namespace, diskSubsystem, "write_seconds_total"), | ||
122 | "This is the total number of seconds spent by all writes.", | ||
123 | diskLabelNames, | ||
124 | nil, | ||
125 | ), | ||
126 | valueType: prometheus.CounterValue, | ||
127 | }, | ||
128 | value: func(stat *iostat.DriveStats) float64 { | ||
129 | return stat.TotalWriteTime.Seconds() | ||
130 | }, | ||
131 | }, | ||
132 | { | ||
133 | typedDesc: typedDesc{ | ||
134 | desc: prometheus.NewDesc( | ||
135 | prometheus.BuildFQName(Namespace, diskSubsystem, "read_bytes_total"), | ||
136 | "The total number of bytes read successfully.", | ||
137 | diskLabelNames, | ||
138 | nil, | ||
139 | ), | ||
140 | valueType: prometheus.CounterValue, | ||
141 | }, | ||
142 | value: func(stat *iostat.DriveStats) float64 { | ||
143 | return float64(stat.BytesRead) | ||
144 | }, | ||
145 | }, | ||
146 | { | ||
147 | typedDesc: typedDesc{ | ||
148 | desc: prometheus.NewDesc( | ||
149 | prometheus.BuildFQName(Namespace, diskSubsystem, "written_bytes_total"), | ||
150 | "The total number of bytes written successfully.", | ||
151 | diskLabelNames, | ||
152 | nil, | ||
153 | ), | ||
154 | valueType: prometheus.CounterValue, | ||
155 | }, | ||
156 | value: func(stat *iostat.DriveStats) float64 { | ||
157 | return float64(stat.BytesWritten) | ||
158 | }, | ||
159 | }, | ||
160 | }, | ||
161 | }, nil | ||
162 | } | ||
163 | |||
164 | func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { | ||
165 | diskStats, err := iostat.ReadDriveStats() | ||
166 | if err != nil { | ||
167 | return fmt.Errorf("couldn't get diskstats: %s", err) | ||
168 | } | ||
169 | |||
170 | for _, stats := range diskStats { | ||
171 | for _, desc := range c.descs { | ||
172 | v := desc.value(stats) | ||
173 | ch <- desc.mustNewConstMetric(v, stats.Name) | ||
174 | } | ||
175 | } | ||
176 | return nil | ||
177 | } | ||