Skip to content


The Gauge is a metric whose value can go up and down. It's useful to measure things like memory usage or temperatures for example.


from pytheus.metrics import Gauge

gauge = Gauge('room_temperature', 'temperature in the living room')


It is possible to increment by 1 by calling inc():

# increase by 1

it's also possible to specify the amount:

# increase by 7


As for incrementing we can call dec() to decrement the value by 1:

# decrease by 1

or we can specify the amount we want to decrement:

# decrease by 7

Set a value

A Gauge value can be set directly with the set() method:


and as an utility you can also set it to the current time (unix timestamp):


Track progress

You can use the track_inprogress context manager to track progress of things, each time the context manager is entered it will increase the gauge value by 1 and each time it exits it will decrease that value:

with gauge.track_inprogress():

Track time

A Gauge can time a piece of code, it will set the value to the duration in seconds if you call the time() context manager:

with gauge.time():

As a Decorator

When used as a decorator the Gauge will time the piece of code, syntactic sugar to the time() context manager:

def do_something():

It is also possible to pass the track_inprogress flag to make the decorator work as syntactic sugar for the track_inprogress context manager:

def do_something():