yr.DoubleCounter.add_labels#
- DoubleCounter.add_labels(labels: dict) None[source]#
add lable for metrics data.
- Parameters:
labels (dict) – The dictionary of labels to add.
- Raises:
ValueError – If the labels are empty.
Example
>>> import yr >>> >>> config = yr.Config(enable_metrics=True) >>> yr.init(config) >>> >>> @yr.instance >>> class Actor: >>> def __init__(self): >>> self.data = yr.DoubleCounter( >>> "userFuncTime", >>> "user function cost time", >>> "ms", >>> {"runtime": "runtime1"} >>> ) >>> self.data.add_labels({"stage": "init"}) >>> print("Actor init:", self.data._DoubleCounter__double_counter_labels) >>> >>> def run(self): >>> self.data.set(5) >>> self.data.add_labels({"phase": "run"}) >>> msg = ( ... f"Actor run: {self.data._UInt64Counter__uint_counter_labels}, " ... f"value: {self.data.get_value()}" ... ) >>> print(msg) >>> return msg >>> actor1 = Actor.options(name="actor").invoke() >>> result = actor1.run.invoke() >>> print("run result:", yr.get(result))