GithubHelp home page GithubHelp logo

Comments (3)

trallnag avatar trallnag commented on May 26, 2024 7

@pawamoy you can now select from a few already existing instrumentations or add your own. Check the updated README.md for more info.

Recording size of requests / responses:

instrumentator.add(
    metrics.request_size(
        should_include_handler=False,
        should_include_method=False,
        should_include_status=False,
    )
).add(
    metrics.response_size(
        should_include_handler=False,
        should_include_method=False,
        should_include_status=False,
    )
)

Or creating your own:

def http_requested_languages_total() -> Callable[[Info], None]:
    METRIC = Counter(
        "http_requested_languages_total", 
        "Number of times a certain language has been requested.", 
        labelnames=("langs",)
    )

    def instrumentation(info: Info) -> None:
        langs = set()
        lang_str = info.request.headers["Accept-Language"]
        for element in lang_str.split(",")
            element = element.split(";")[0].strip().lower()
            langs.add(element)
        for language in langs:
            METRIC.labels(language).inc()

    return instrumentation

instrumentator.add(http_requested_languages_total())

from prometheus-fastapi-instrumentator.

trallnag avatar trallnag commented on May 26, 2024 1

Do you want the transfered data metric just for a few specific endpoints or all endpoints transparently?

Option 1: Instrument the specific endpoints manually by directly using the Prometheus library.

Option 2: Not supported. I could put it on my bucket list. Though I'm not sure if I would hardcode the new metrics or do something like @rycus86 has done in his package for instrumenting Flask apps https://github.com/rycus86/prometheus_flask_exporter.

And thanks

from prometheus-fastapi-instrumentator.

pawamoy avatar pawamoy commented on May 26, 2024

Thanks for the quick answer!

Do you want the transfered data metric just for a few specific endpoints or all endpoints transparently?

Depends! It was just an example 🙂 Could be both.

Oh yes, it seems prometheus_flask_exporter allows to do what I'm looking for.

So I would say: don't hardcode it! Instead, provide a way for users to add their own custom, exported metrics.

from prometheus-fastapi-instrumentator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.