question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help Needed for metric type summary

See original GitHub issue

I have two questions

  1. Is there a way to store average latency time based on the histogram flask_http_request_duration_seconds_sum and flask_http_request_duration_seconds_count as another metric?

  2. 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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
miteshvpcommented, Jun 25, 2019

Thank you. I will give it a try on 0.8.2

0reactions
rycus86commented, Jun 24, 2019

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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found