本文整理汇总了Python中prometheus_client.Gauge.set_function方法的典型用法代码示例。如果您正苦于以下问题:Python Gauge.set_function方法的具体用法?Python Gauge.set_function怎么用?Python Gauge.set_function使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类prometheus_client.Gauge
的用法示例。
在下文中一共展示了Gauge.set_function方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestGauge
# 需要导入模块: from prometheus_client import Gauge [as 别名]
# 或者: from prometheus_client.Gauge import set_function [as 别名]
class TestGauge(unittest.TestCase):
def setUp(self):
self.registry = CollectorRegistry()
self.gauge = Gauge('g', 'help', registry=self.registry)
def test_gauge(self):
self.assertEqual(0, self.registry.get_sample_value('g'))
self.gauge.inc()
self.assertEqual(1, self.registry.get_sample_value('g'))
self.gauge.dec(3)
self.assertEqual(-2, self.registry.get_sample_value('g'))
self.gauge.set(9)
self.assertEqual(9, self.registry.get_sample_value('g'))
def test_function_decorator(self):
self.assertEqual(0, self.registry.get_sample_value('g'))
@self.gauge.track_inprogress()
def f():
self.assertEqual(1, self.registry.get_sample_value('g'))
f()
self.assertEqual(0, self.registry.get_sample_value('g'))
def test_block_decorator(self):
self.assertEqual(0, self.registry.get_sample_value('g'))
with self.gauge.track_inprogress():
self.assertEqual(1, self.registry.get_sample_value('g'))
self.assertEqual(0, self.registry.get_sample_value('g'))
def test_gauge_function(self):
x = {}
self.gauge.set_function(lambda: len(x))
self.assertEqual(0, self.registry.get_sample_value('g'))
self.gauge.inc()
self.assertEqual(0, self.registry.get_sample_value('g'))
x['a'] = None
self.assertEqual(1, self.registry.get_sample_value('g'))
def test_function_decorator(self):
self.assertEqual(0, self.registry.get_sample_value('g'))
@self.gauge.time()
def f():
time.sleep(.001)
f()
self.assertNotEqual(0, self.registry.get_sample_value('g'))
def test_block_decorator(self):
self.assertEqual(0, self.registry.get_sample_value('g'))
with self.gauge.time():
time.sleep(.001)
self.assertNotEqual(0, self.registry.get_sample_value('g'))
示例2: register_prometheus_gauges
# 需要导入模块: from prometheus_client import Gauge [as 别名]
# 或者: from prometheus_client.Gauge import set_function [as 别名]
def register_prometheus_gauges(export_internal_raspberry=False):
g = Gauge("sensor_temperature_in_celsius", "Local room temperature around the raspberry pi", ["sensor"])
error_g = Gauge("faulty_sensor_read", "Is 1 if the sensor could not be read.", ["sensor"])
sensors = find_sensors()
print "Found sensors:", ", ".join(map(lambda x: str(x), sensors))
for sensor in sensors:
g.labels(str(sensor)).set_function(sensor)
sensor.set_error_gauge(error_g.labels(str(sensor)))
if export_internal_raspberry:
g = Gauge("cpu_temperature_in_celsius", "CPU Temperature of the Raspberry Pi")
g.set_function(read_raspberry_pi_temperature)
return sensors
示例3: Gauge
# 需要导入模块: from prometheus_client import Gauge [as 别名]
# 或者: from prometheus_client.Gauge import set_function [as 别名]
import time
from prometheus_client import start_http_server
from prometheus_client import Gauge
TIME = Gauge('time_seconds',
'The current time.')
TIME.set_function(lambda: time.time())
if __name__ == "__main__":
start_http_server(8000)
while True:
time.sleep(1)