Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P8458
latest
Active
Public
Actions
Authored by
jbond
on Apr 30 2019, 10:57 AM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Referenced Files
F28866515: raw.txt
Apr 30 2019, 10:57 AM
2019-04-30 10:57:51 (UTC+0)
Subscribers
None
def
latest
(
self
,
metric
:
str
,
host
:
str
,
timeperiod
:
Optional
[
str
]
=
'2m'
)
->
float
:
"""Get the latest prometheous metric
Arguments:
metric (str): name of the prometheous metric
host (str): hostname of the node to search for
Returns:
float: The current value of the metric or -1 if no values returned
Raises:
PrometheusError: on faliure
"""
query
=
'sum(irate({metric}{{instance=~"{host}(:[0-9]{{1,5}})?"}}[{timeperiod}]))'
.
format
(
metric
=
metric
,
host
=
host
,
timeperiod
=
timeperiod
)
result
=
self
.
query
(
query
)
if
not
result
:
logger
.
warning
(
'no metrics returned for time period'
)
return
-
1
return
float
(
result
[
0
][
'value'
][
1
])
latest
(
'apache_accesses_total'
,
'mw1222'
)
Event Timeline
jbond
created this paste.
Apr 30 2019, 10:57 AM
2019-04-30 10:57:51 (UTC+0)
Log In to Comment