Skip to main content

Gauge

Gauge represents a gauge labeled with values from the context. See labeled.SetMetricsKeys for more information

Methods


Inc()

@classmethod
def Inc(
ctx: context.Context
)

Increments the gauge by 1. Call this method to increase the gauge's current value by a fixed amount.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.

Add()

@classmethod
def Add(
ctx: context.Context,
v: float64
)

Adds a specified float64 value to the gauge. Use this method to increase the gauge's value by a variable amount.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.
vfloat64The value to add to the gauge. This can be any positive or negative float64 number.

Set()

@classmethod
def Set(
ctx: context.Context,
v: float64
)

Sets the gauge to a specific float64 value. This method is used to explicitly define the gauge's current reading.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.
vfloat64The new float64 value to set the gauge to. This will overwrite the current gauge value.

Dec()

@classmethod
def Dec(
ctx: context.Context
)

Decrements the gauge by 1. Call this method to decrease the gauge's current value by a fixed amount.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.

Sub()

@classmethod
def Sub(
ctx: context.Context,
v: float64
)

Subtracts a specified float64 value from the gauge. Use this method to decrease the gauge's value by a variable amount.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.
vfloat64The value to subtract from the gauge. This can be any positive or negative float64 number.

SetToCurrentTime()

@classmethod
def SetToCurrentTime(
ctx: context.Context
)

Sets the gauge to the current Unix timestamp in seconds. This is useful for tracking the time of the last event or operation.

Parameters

NameTypeDescription
ctxcontext.ContextThe context for the operation, used to carry deadlines, cancellation signals, and other request-scoped values.