Comments (3)
@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.
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.
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)
- Cannot See Multiprocess metric under /metric page while suing multiple workers HOT 1
- Multi process mode does not work as expected
- _created metrics are not created in multi-process mode HOT 2
- Large content in info response impacts performance a lot HOT 1
- Response body `info.response.body` is still empty
- Multiple metrics endpoints when using `expose` + multliple workers HOT 5
- Adding metrics from routers HOT 2
- Running custom metrics in background HOT 4
- Inprogress requests causes duplicated prometheus timeseries error
- labels on highr bucket default metrics
- Having metrics values even with no endpoints activity HOT 1
- Not full metrics list HOT 1
- FastAPI app with many routers HOT 3
- Instrumentator middleware includes BackgroundTask duration in http request latency metrics
- How to properly initialize modified_status when throwing exception
- Default metrics are gone when adding a custom instrumentation HOT 3
- Allow for custom dynamic labels on default metrics HOT 1
- Remove FastAPI in favor of Starlette HOT 3
- Upgrade fastapi version to support >100.0 HOT 5
- Metrics disappear when setting PROMETHEUS_MULTIPROC_DIR HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prometheus-fastapi-instrumentator.