@@ -34,11 +34,6 @@ typedef struct {
34
34
uint64_t bytes;
35
35
uint64_t transfers;
36
36
uint64_t blocks;
37
- double kb_per_transfer;
38
- double transfers_per_second;
39
- double mb_per_second;
40
- double blocks_per_second;
41
- double ms_per_transaction;
42
37
} Stats;
43
38
44
39
int _get_ndevs() {
@@ -87,11 +82,6 @@ Stats _get_stats(int i) {
87
82
stats.bytes = total_bytes;
88
83
stats.transfers = total_transfers;
89
84
stats.blocks = total_blocks;
90
- stats.kb_per_transfer = kb_per_transfer;
91
- stats.transfers_per_second = transfers_per_second;
92
- stats.mb_per_second = mb_per_second;
93
- stats.blocks_per_second = blocks_per_second;
94
- stats.ms_per_transaction = ms_per_transaction;
95
85
96
86
return stats;
97
87
}
@@ -103,14 +93,9 @@ const (
103
93
)
104
94
105
95
type devstatCollector struct {
106
- bytes_total * prometheus.CounterVec
107
- transfers_total * prometheus.CounterVec
108
- blocks_total * prometheus.CounterVec
109
- bytes_per_transfer * prometheus.GaugeVec
110
- transfers_per_second * prometheus.GaugeVec
111
- bytes_per_second * prometheus.GaugeVec
112
- blocks_per_second * prometheus.GaugeVec
113
- seconds_per_transaction * prometheus.GaugeVec
96
+ bytesDesc * prometheus.Desc
97
+ transfersDesc * prometheus.Desc
98
+ blocksDesc * prometheus.Desc
114
99
}
115
100
116
101
func init () {
@@ -121,77 +106,20 @@ func init() {
121
106
// Device stats.
122
107
func NewDevstatCollector () (Collector , error ) {
123
108
return & devstatCollector {
124
- bytes_total : prometheus .NewCounterVec (
125
- prometheus.CounterOpts {
126
- Namespace : Namespace ,
127
- Subsystem : devstatSubsystem ,
128
- Name : "bytes_total" ,
129
- Help : "The total number of bytes transferred for reads and writes on the device." ,
130
- },
131
- []string {"device" },
109
+ bytesDesc : prometheus .NewDesc (
110
+ prometheus .BuildFQName (Namespace , devstatSubsystem , "bytes_total" ),
111
+ "The total number of bytes transferred for reads and writes on the device." ,
112
+ []string {"device" }, nil ,
132
113
),
133
- transfers_total : prometheus .NewCounterVec (
134
- prometheus.CounterOpts {
135
- Namespace : Namespace ,
136
- Subsystem : devstatSubsystem ,
137
- Name : "transfers_total" ,
138
- Help : "The total number of transactions completed." ,
139
- },
140
- []string {"device" },
114
+ transfersDesc : prometheus .NewDesc (
115
+ prometheus .BuildFQName (Namespace , devstatSubsystem , "transfers_total" ),
116
+ "The total number of transactions completed." ,
117
+ []string {"device" }, nil ,
141
118
),
142
- blocks_total : prometheus .NewCounterVec (
143
- prometheus.CounterOpts {
144
- Namespace : Namespace ,
145
- Subsystem : devstatSubsystem ,
146
- Name : "blocks_total" ,
147
- Help : "The total number of bytes given in terms of the devices blocksize." ,
148
- },
149
- []string {"device" },
150
- ),
151
- bytes_per_transfer : prometheus .NewGaugeVec (
152
- prometheus.GaugeOpts {
153
- Namespace : Namespace ,
154
- Subsystem : devstatSubsystem ,
155
- Name : "bytes_per_transfer" ,
156
- Help : "The average number of bytes per transfer." ,
157
- },
158
- []string {"device" },
159
- ),
160
- transfers_per_second : prometheus .NewGaugeVec (
161
- prometheus.GaugeOpts {
162
- Namespace : Namespace ,
163
- Subsystem : devstatSubsystem ,
164
- Name : "transfers_per_second" ,
165
- Help : "The average number of transfers per second." ,
166
- },
167
- []string {"device" },
168
- ),
169
- bytes_per_second : prometheus .NewGaugeVec (
170
- prometheus.GaugeOpts {
171
- Namespace : Namespace ,
172
- Subsystem : devstatSubsystem ,
173
- Name : "bytes_per_second" ,
174
- Help : "The average bytes per second." ,
175
- },
176
- []string {"device" },
177
- ),
178
- blocks_per_second : prometheus .NewGaugeVec (
179
- prometheus.GaugeOpts {
180
- Namespace : Namespace ,
181
- Subsystem : devstatSubsystem ,
182
- Name : "blocks_per_second" ,
183
- Help : "The average blocks per second." ,
184
- },
185
- []string {"device" },
186
- ),
187
- seconds_per_transaction : prometheus .NewGaugeVec (
188
- prometheus.GaugeOpts {
189
- Namespace : Namespace ,
190
- Subsystem : devstatSubsystem ,
191
- Name : "seconds_per_transaction" ,
192
- Help : "The average number of seconds per transaction." ,
193
- },
194
- []string {"device" },
119
+ blocksDesc : prometheus .NewDesc (
120
+ prometheus .BuildFQName (Namespace , devstatSubsystem , "blocks_total" ),
121
+ "The total number of bytes given in terms of the devices blocksize." ,
122
+ []string {"device" }, nil ,
195
123
),
196
124
}, nil
197
125
}
@@ -209,24 +137,10 @@ func (c *devstatCollector) Update(ch chan<- prometheus.Metric) (err error) {
209
137
stats := C ._get_stats (i )
210
138
device := fmt .Sprintf ("%s%d" , C .GoString (& stats .device [0 ]), stats .unit )
211
139
212
- c .bytes_total .With (prometheus.Labels {"device" : device }).Set (float64 (stats .bytes ))
213
- c .transfers_total .With (prometheus.Labels {"device" : device }).Set (float64 (stats .transfers ))
214
- c .blocks_total .With (prometheus.Labels {"device" : device }).Set (float64 (stats .blocks ))
215
- c .bytes_per_transfer .With (prometheus.Labels {"device" : device }).Set (float64 (stats .kb_per_transfer ) * 1000 )
216
- c .bytes_per_second .With (prometheus.Labels {"device" : device }).Set (float64 (stats .mb_per_second ) * 1000000 )
217
- c .transfers_per_second .With (prometheus.Labels {"device" : device }).Set (float64 (stats .transfers_per_second ))
218
- c .blocks_per_second .With (prometheus.Labels {"device" : device }).Set (float64 (stats .blocks_per_second ))
219
- c .seconds_per_transaction .With (prometheus.Labels {"device" : device }).Set (float64 (stats .ms_per_transaction ) / 1000 )
140
+ ch <- prometheus .MustNewConstMetric (c .bytesDesc , prometheus .CounterValue , float64 (stats .bytes ), device )
141
+ ch <- prometheus .MustNewConstMetric (c .transfersDesc , prometheus .CounterValue , float64 (stats .transfers ), device )
142
+ ch <- prometheus .MustNewConstMetric (c .blocksDesc , prometheus .CounterValue , float64 (stats .blocks ), device )
220
143
}
221
144
222
- c .bytes_total .Collect (ch )
223
- c .transfers_total .Collect (ch )
224
- c .blocks_total .Collect (ch )
225
- c .bytes_per_transfer .Collect (ch )
226
- c .bytes_per_second .Collect (ch )
227
- c .transfers_per_second .Collect (ch )
228
- c .blocks_per_second .Collect (ch )
229
- c .seconds_per_transaction .Collect (ch )
230
-
231
145
return err
232
146
}
0 commit comments