Repository navigation
Missing EnumMetricFamily for custom collector #1130
Replies: 1 comment
|
@andreynovikov this is a year old now, so for whoever lands here next: from prometheus_client import CollectorRegistry, Enum, generate_latest
from prometheus_client.core import StateSetMetricFamily
states = ["starting", "running", "stopped"]
class TaskCollector:
def collect(self):
m = StateSetMetricFamily("task_state", "Task state", labels=["task"])
m.add_metric(["t1"], {s: s == "running" for s in states})
yield m
custom = CollectorRegistry()
custom.register(TaskCollector())
print(generate_latest(custom).decode())
direct = CollectorRegistry()
Enum("task_state", "Task state", ["task"], states=states, registry=direct).labels("t1").state("running")
lines = lambda r: sorted(generate_latest(r).splitlines())
print("same lines as Enum:", lines(custom) == lines(direct))The lines only match after sorting: The name is easy to miss because @csmarchbanks would a docs pull request adding sections for those three to |
Uh oh!
There was an error while loading. Please reload this page.
I want to expose
Enumin my custom collector, but there is no implementation forEnumMetricFamily. Is it on purpose? How can I substitute it?All reactions