Python 如何更新计数器:在avery请求后设置新值,而不是将新值增加到以前的值?
想用python创建Prometheus客户端吗 拿了这个密码Python 如何更新计数器:在avery请求后设置新值,而不是将新值增加到以前的值?,python,python-3.x,prometheus,Python,Python 3.x,Prometheus,想用python创建Prometheus客户端吗 拿了这个密码 from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) c.labels(method='get', endpoint='/').inc() c.labels(method='post', endpoint='/submit').inc() 一切正常,但我想在av
from prometheus_client import Counter
c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint'])
c.labels(method='get', endpoint='/').inc()
c.labels(method='post', endpoint='/submit').inc()
一切正常,但我想在avery请求后设置新值,而不是将新值增加到以前的值
怎样才能做到呢?你必须使用仪表,而不是计数器 自述文件中的示例:
from prometheus_client import Gauge
g = Gauge('my_inprogress_requests', 'Description of gauge')
g.inc() # Increment by 1
g.dec(10) # Decrement by given value
g.set(4.2) # Set to a given value
另见普罗米修斯公制类型:
计数器
计数器是一种累积度量,它表示一个只向上移动的数值。计数器通常用于计算已服务的请求、已完成的任务、发生的错误等。计数器不应用于显示项目的当前计数,这些项目的数量也会下降,例如,当前正在运行的goroutine的数量。在这个用例中使用量规
仪表
仪表是一种表示单个数值的度量,该数值可以任意上下移动
仪表通常用于测量温度或当前内存使用量等测量值,但也可用于上下波动的“计数”,如正在运行的goroutine数