Comments (2)
I've been using Prometheus for a while and I only needed to add a service like this:
import re
import sys
import traceback
import aiohttp.web
import asab
import prometheus_client
class Metrics(asab.Service):
def __init__(self, app: asab.Application, service_name=__name__):
super().__init__(app, service_name)
self._charset_regex = re.compile(r'(^|;)(\s*charset\s*=\s*([^;\s]+)\s*;*)', flags=re.IGNORECASE)
async def initialize(self, app: asab.Application):
await super().initialize(app)
web_service = app.get_service('asab.WebService')
web_service.WebApp.router.add_get('/metrics', self._metrics)
async def finalize(self, app: asab.Application):
await super().finalize(app)
def _metrics(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
try:
accept_header = request.headers.get('Accept')
encoder, content_type = prometheus_client.exposition.choose_encoder(accept_header)
# separate the charset from the content-type
matches = self._charset_regex.findall(content_type)
if matches:
charset = matches[-1][2]
else:
charset = None
content_type = self._charset_regex.sub(r'\1', content_type)
return aiohttp.web.Response(
body=encoder(prometheus_client.REGISTRY), content_type=content_type, charset=charset)
except Exception:
exc_type, exc_value, exc_traceback = sys.exc_info()
error = ''.join(traceback.format_exception_only(exc_type, exc_value)).strip()
raise aiohttp.web.HTTPInternalServerError(reason=error.replace('\n', ' # '))
from asab.
Yes - in order to explore this a bit more, we need to integrate prometheus_client
with asab.metrics
from asab.
Related Issues (20)
- Fails to detect Docker container runtime HOT 1
- We seek a maintainer of ASAB to join our team 👋🏻
- Missing try/catch in the periodic pull of the asab/library/providers/git HOT 4
- Add configurable global security to REST API docs
- Possible unnecessary Docker checking HOT 2
- Developer mode for authz
- Openapi docs: Read query params from docstrings
- Add event types into `upsertor.execute()` method
- Add documentation for asab.storage
- Generating ID automatically in `asab.storage` HOT 1
- Set AES Key to None if not specified in configuration
- OAuth setup for Swagger
- Granular access control HOT 1
- OpenAPI: Custom parameters in docstring overwrite path parameters
- Missing error handing in `inotify_init()`
- asab.library in python 3.11 HOT 2
- Support for sentry.io
- Housekeeping: Not 10 minutes
- InfluxDB errors when recording metrics should not bring down the application HOT 4
- More generic exception handling for a feed to InfluxDB
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 asab.