@@ -61,7 +61,7 @@ def format_response(self, data) -> [str]:
61
61
resp .extend (header )
62
62
for sts in metric .timeseries :
63
63
for _key , _value in sts .dps .items ():
64
- sts_resp = SingleTimeSeriesResponse (name , _key , _value , sts .tags )
64
+ sts_resp = SingleTimeSeriesResponse (name , _key , _value , sts .tags , metric . mtype )
65
65
self .logger .trace (f'sts_resp.str_expfmt output: { sts_resp .str_expfmt ()} ' )
66
66
resp .extend (sts_resp .str_expfmt ())
67
67
return resp
@@ -201,6 +201,13 @@ def GET(self, **params):
201
201
resString = '\n ' .join (resp ) + '\n '
202
202
return resString
203
203
204
+ # /metrics_gpfs_waiters
205
+ elif 'metrics_gpfs_waiters' in cherrypy .request .script_name :
206
+ resp = self .metrics (['GPFSWaiters' ])
207
+ cherrypy .response .headers ['Content-Type' ] = 'text/plain'
208
+ resString = '\n ' .join (resp ) + '\n '
209
+ return resString
210
+
204
211
# /metrics
205
212
elif 'metrics' in cherrypy .request .script_name :
206
213
resp = self .metrics ()
@@ -238,14 +245,26 @@ def OPTIONS(self):
238
245
239
246
class SingleTimeSeriesResponse ():
240
247
241
- def __init__ (self , metricname , timestamp , value , tags ):
248
+ def __init__ (self , metricname , timestamp , value , tags , type ):
242
249
self .metric = metricname
243
250
self .timestamp = timestamp * 1000
244
251
self .value = value if value is not None else 0 # TODO check if we should return None or null
245
252
self .tags = tags
253
+ self .type = type
246
254
247
- def str_expfmt (self ) -> str :
255
+ def str_expfmt (self ) -> [ str ] :
248
256
myset = []
257
+ mstring = ''
258
+
259
+ if self .type == 'histogram' :
260
+ mstring = self ._str_expfmt_histogram ()
261
+ else :
262
+ mstring = self ._str_expfmt_gauge ()
263
+
264
+ myset .append (mstring )
265
+ return myset
266
+
267
+ def _str_expfmt_gauge (self ) -> str :
249
268
250
269
if self .tags :
251
270
labels = ',' .join ('%s="%s"' % (k , v ) for k , v in self .tags .items ())
@@ -261,5 +280,30 @@ def str_expfmt(self) -> str:
261
280
value = repr (float (self .value )),
262
281
timestamp = int (self .timestamp )
263
282
)
264
- myset .append (mstring )
265
- return myset
283
+ return mstring
284
+
285
+ def _str_expfmt_histogram (self ) -> str :
286
+
287
+ labels = ''
288
+
289
+ if self .tags :
290
+ for k , v in self .tags .items ():
291
+ if k == 'waiters_time_threshold' :
292
+ k = 'le'
293
+ elif v == 'all' :
294
+ v = '+Inf'
295
+ if labels == '' :
296
+ labels = labels + '%s="%s"' % (k , v )
297
+ else :
298
+ labels = labels + ',%s="%s"' % (k , v )
299
+
300
+ if labels :
301
+ fmtstr = '{name}{{{labels}}} {value} {timestamp}'
302
+ else :
303
+ fmtstr = '{name} {value} {timestamp}'
304
+ mstring = fmtstr .format (name = self .metric + '_bucket' ,
305
+ labels = labels ,
306
+ value = repr (float (self .value )),
307
+ timestamp = int (self .timestamp )
308
+ )
309
+ return mstring
0 commit comments