Help Needed for metric type summary
See original GitHub issueI have two questions
-
Is there a way to store average latency time based on the histogram
flask_http_request_duration_seconds_sum
andflask_http_request_duration_seconds_count
as another metric? -
What is the best way to pass r.status_code if you do not use
@app.route
to instantiate? I am using BluePrint and Flask_restful to register and instantiate separately as in
Following your example on creating a summary
@app.route('/status/<int:status>')
@metrics.summary('requests_by_status', 'Request latencies by status', labels={'status': lambda r: r.status_code})
def echo_status(status):
return 'Status: %s' % status, status
from flask import Blueprint
from flask_restful import Resource
api_v1 = Blueprint('api_v1', __name__, url_prefix='/api/v1')
rest_api_v1 = Api(api_v1, errors=errors)
def add_resource(resource, route, endpoint=None, defaults=None):
"""Add a resource for both trailing slash and no trailing slash to prevent redirects."""
slashless = route.rstrip('/')
endpoint = endpoint or resource.__name__.lower()
defaults = defaults or {}
# resources without slashes
rest_api_v1.add_resource(resource,
slashless,
endpoint=endpoint + '__slashless',
defaults=defaults)
class Test(Resource):
status = 200
@staticmethod
@metrics.summary('dummy_test', 'Test Request latencies by status',
labels={'dummy_test': lambda r: ???})
def get():
try:
time.sleep(random.randint(0, 5))
if random.choice([True, False]):
return 'OK', 200
else:
return 'Not OK', 400
except Exception as e:
logger.error('%r' % e)
add_resource(Test, '/test', endpoint='test')
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Metric types - Prometheus.io
Metric types. Counter; Gauge; Histogram; Summary. The Prometheus client libraries offer four core metric types. These are currently only differentiated in ...
Read more >The 4 Types Of Prometheus Metrics - Tom Gregory
Metric types · 1. Counters · 2. Gauges · 3. Histograms · 4. Summaries.
Read more >A Deep Dive Into the Four Types of Prometheus Metrics
Summaries · A counter with the total number of measurements. The metric name uses the _count suffix. · A counter with the sum...
Read more >Metrics Summary - Datadog Docs
Overview. The Metrics Summary page displays a list of your metrics reported to Datadog under a specified time frame: the past hour, day,...
Read more >Metric Types in Prometheus and PromQL - PromLabs
Summary : A summary is used to track the distribution of a set of observed values (like request latencies) as a set of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you. I will give it a try on
0.8.2
I think I managed to get it working for your use case. It’s running through Travis now, and should be available in
0.8.2
very soon. Thanks again for the report!