Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Paste
P1260
(An Untitled Masterwork)
Active
Public
Actions
Authored by
douardda
on Jan 20 2022, 1:46 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
None
class
Statsd
:
# ...
@contextmanager
def
status_gauge
(
self
,
metric_name
:
str
,
statuses
:
Collection
[
str
],
common_tags
:
Optional
[
Dict
[
str
,
str
]]
=
None
):
current_status
=
Optional
[
str
]
=
None
for
status
in
statuses
:
self
.
gauge
(
metric_name
,
0
,
{
**
common_tags
,
"status"
:
status
})
def
set
(
new_status
:
str
):
if
new_status
not
in
statuses
:
raise
ValueError
(
f
'{new_status} not in {statuses}'
)
if
current_status
:
self
.
gauge
(
metric_name
,
0
,
{
**
common_tags
,
"status"
:
current_status
})
current_status
=
new_status
self
.
gauge
(
metric_name
,
1
,
{
**
common_tags
,
"status"
:
current_status
})
yield
set
for
status
in
statuses
:
self
.
gauge
(
metric_name
,
0
,
{
**
common_tags
,
"status"
:
status
})
Event Timeline
douardda
created this paste.
Jan 20 2022, 1:46 PM
2022-01-20 13:46:42 (UTC+1)
Log In to Comment