1- // +build !nodiskstats
1+ // +build !nodevstat
22
33package collector
44
@@ -124,85 +124,71 @@ const (
124124)
125125
126126type devstatCollector struct {
127- bytes * prometheus.GaugeVec
128- transfers * prometheus.GaugeVec
129- duration * prometheus.GaugeVec
130- busyTime * prometheus.GaugeVec
131- blocks * prometheus.GaugeVec
127+ bytes * prometheus.CounterVec
128+ bytes_total * prometheus.CounterVec
129+ transfers * prometheus.CounterVec
130+ duration * prometheus.CounterVec
131+ busyTime * prometheus.CounterVec
132+ blocks * prometheus.CounterVec
132133}
133134
134135func init () {
135136 Factories ["devstat" ] = NewDevstatCollector
136137}
137138
138- // device stats.
139+ // Takes a prometheus registry and returns a new Collector exposing
140+ // Device stats.
139141func NewDevstatCollector () (Collector , error ) {
140- //var diskLabelNames = []string{"device"}
141- //var ioType = []string{"type"}
142-
143142 return & devstatCollector {
144- // Docs from https://www.kernel.org/doc/Documentation/iostats.txt
145- bytes : prometheus .NewGaugeVec (
146- prometheus.GaugeOpts {
143+ bytes : prometheus .NewCounterVec (
144+ prometheus.CounterOpts {
147145 Namespace : Namespace ,
148146 Subsystem : devstatSubsystem ,
149- Name : "bytes " ,
150- Help : "The total number of bytes transferred " ,
147+ Name : "bytes_total " ,
148+ Help : "The total number of bytes in transactions. " ,
151149 },
152150 []string {"device" , "type" },
153151 ),
154- transfers : prometheus .NewGaugeVec (
155- prometheus.GaugeOpts {
152+ transfers : prometheus .NewCounterVec (
153+ prometheus.CounterOpts {
156154 Namespace : Namespace ,
157155 Subsystem : devstatSubsystem ,
158- Name : "transfers " ,
159- Help : "The total number of transactions" ,
156+ Name : "transfers_total " ,
157+ Help : "The total number of transactions. " ,
160158 },
161159 []string {"device" , "type" },
162160 ),
163- duration : prometheus .NewGaugeVec (
164- prometheus.GaugeOpts {
161+ duration : prometheus .NewCounterVec (
162+ prometheus.CounterOpts {
165163 Namespace : Namespace ,
166164 Subsystem : devstatSubsystem ,
167- Name : "duration " ,
168- Help : "The total duration of transactions" ,
165+ Name : "duration_seconds_total " ,
166+ Help : "The total duration of transactions in seconds. " ,
169167 },
170168 []string {"device" , "type" },
171169 ),
172- busyTime : prometheus .NewGaugeVec (
173- prometheus.GaugeOpts {
170+ busyTime : prometheus .NewCounterVec (
171+ prometheus.CounterOpts {
174172 Namespace : Namespace ,
175173 Subsystem : devstatSubsystem ,
176- Name : "busy_time " ,
177- Help : "Total time the device had one or more transactions outstanding" ,
174+ Name : "busy_time_seconds_total " ,
175+ Help : "Total time the device had one or more transactions outstanding in seconds. " ,
178176 },
179177 []string {"device" },
180178 ),
181- blocks : prometheus .NewGaugeVec (
182- prometheus.GaugeOpts {
179+ blocks : prometheus .NewCounterVec (
180+ prometheus.CounterOpts {
183181 Namespace : Namespace ,
184182 Subsystem : devstatSubsystem ,
185- Name : "blocks " ,
186- Help : "The total number of blocks transferred" ,
183+ Name : "blocks_transferred_total " ,
184+ Help : "The total number of blocks transferred. " ,
187185 },
188186 []string {"device" },
189187 ),
190188 }, nil
191189}
192190
193191func (c * devstatCollector ) Update (ch chan <- prometheus.Metric ) (err error ) {
194- /*
195- var busyTime [3]C.longlong
196- var blocks [3]C.uint64_t
197- var kbPerTransfer [3]C.longlong
198- var transfersPerSecond [3]C.longlong
199- var mbPerSecond [3]C.longlong
200- var blocksPerSecond [3]C.longlong
201- var msPerTransaction [3]C.longlong
202- var busyPCT C.longlong
203- var queueLength C.uint64_t
204-
205- */
206192 count := C ._get_ndevs ()
207193 if count == - 1 {
208194 return errors .New ("devstat_getdevs() failed!" )
@@ -214,17 +200,18 @@ func (c *devstatCollector) Update(ch chan<- prometheus.Metric) (err error) {
214200 for i := C .int (0 ); i < count ; i ++ {
215201 stats := C ._get_stats (i )
216202 device := fmt .Sprintf ("%s%d" , C .GoString (& stats .device [0 ]), stats .unit )
203+ // Free metrics are disabled for now, please see PR #88 for more details.
217204 c .bytes .With (prometheus.Labels {"device" : device , "type" : "read" }).Set (float64 (stats .bytes .read ))
218205 c .bytes .With (prometheus.Labels {"device" : device , "type" : "write" }).Set (float64 (stats .bytes .write ))
219- c .bytes .With (prometheus.Labels {"device" : device , "type" : "free" }).Set (float64 (stats .bytes .free ))
206+ // c.bytes.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.bytes.free))
220207 c .transfers .With (prometheus.Labels {"device" : device , "type" : "other" }).Set (float64 (stats .transfers .other ))
221208 c .transfers .With (prometheus.Labels {"device" : device , "type" : "read" }).Set (float64 (stats .transfers .read ))
222209 c .transfers .With (prometheus.Labels {"device" : device , "type" : "write" }).Set (float64 (stats .transfers .write ))
223- c .transfers .With (prometheus.Labels {"device" : device , "type" : "free" }).Set (float64 (stats .transfers .free ))
210+ // c.transfers.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.transfers.free))
224211 c .duration .With (prometheus.Labels {"device" : device , "type" : "other" }).Set (float64 (stats .duration .other ))
225212 c .duration .With (prometheus.Labels {"device" : device , "type" : "read" }).Set (float64 (stats .duration .read ))
226213 c .duration .With (prometheus.Labels {"device" : device , "type" : "write" }).Set (float64 (stats .duration .write ))
227- c .duration .With (prometheus.Labels {"device" : device , "type" : "free" }).Set (float64 (stats .duration .free ))
214+ // c.duration.With(prometheus.Labels{"device": device, "type": "free"}).Set(float64(stats.duration.free))
228215 c .busyTime .With (prometheus.Labels {"device" : device }).Set (float64 (stats .busyTime ))
229216 c .blocks .With (prometheus.Labels {"device" : device }).Set (float64 (stats .blocks ))
230217 }
0 commit comments