Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken example for a custom Counter metrics #2978

Closed
feeeper opened this issue Feb 28, 2024 · 3 comments
Closed

Broken example for a custom Counter metrics #2978

feeeper opened this issue Feb 28, 2024 · 3 comments
Assignees
Labels
triaged Issue has been reviewed and triaged

Comments

@feeeper
Copy link

feeeper commented Feb 28, 2024

馃摎 The doc issue

The example in the section Add Counter based metrics shows how to add custom Counter metric:

# Create a counter with name 'LoopCount' and dimensions, initial value
metrics.add_counter('LoopCount', 1, None, dimensions)

# Increment counter by 2 
metrics.add_counter('LoopCount', 2 , None, dimensions)

# Decrement counter by 1
metrics.add_counter('LoopCount', -1, None, dimensions)

I tried to copy this example to my custom handler:

dims = [Dimension('ModelName', 'doc_model')]
self.metrics.add_counter('LoopCount', 1, None, dimensions=dims)
# Increment counter by 2 
self.metrics.add_counter('LoopCount', 2 , None, dimensions=dims)
# Decrement counter by 1
self.metrics.add_counter('LoopCount', -1, None, dimensions=dims)

When I call API for inference I got an error in the terminal:

2024-02-28T15:23:57,011 [ERROR] W-9000-doc_model_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Failed to parse metrics line: "[METRICS]Failed to update metric with name:LoopCount and dimensions: ModelName:doc_model,Level:Model with value: -1: Counter metric update value cannot be negative".

Suggest a potential alternative/fix

No response

@agunapal agunapal added the triaged Issue has been reviewed and triaged label Feb 29, 2024
@namannandan
Copy link
Collaborator

@feeeper This error is expected since counter metrics cannot have negative values. You will need to use a gauge metric for this use case by setting metric_type = MetricTypes.GAUGE: https://github.com/pytorch/serve/blob/v0.9.0/docs/metrics.md#function-api-to-add-generic-metrics-with-default-dimensions.

Torchserve metrics are modeled based on prometheus metrics semantics: https://prometheus.io/docs/concepts/metric_types/

A more detailed examples to emit various types of custom metrics: https://github.com/pytorch/serve/tree/master/examples/custom_metrics

@feeeper
Copy link
Author

feeeper commented Mar 1, 2024

@namannandan yeah, I got it. But what I want to say that I got this exact code snippet from your documentation. And this snippet doesn't work.

@namannandan
Copy link
Collaborator

Metrics documentation will be fixed as a part of this tracking issue: #3001

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been reviewed and triaged
Projects
None yet
Development

No branches or pull requests

3 participants