Created
October 5, 2017 11:09
-
-
Save flaminscotsman/8b6ab867462b830a344b99f782330bef to your computer and use it in GitHub Desktop.
ConstLabels example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import types | |
from functools import partial | |
from prometheus_client import * | |
# Dummy objects to get this to work | |
def resolve_current_machine_name(): | |
import socket | |
return socket.getaddrinfo(socket.gethostname(), 0, 0, 0, 0, socket.AI_CANONNAME)[0][3] | |
config = {'generic':{'production': True}} | |
QUEUE_TIME = Histogram( | |
'queue_time_seconds', | |
'Time taken between an entities being pushed into the queue and being dispatched for processing', | |
['environment', 'server'] | |
) | |
QUEUE_TIME = QUEUE_TIME.labels( | |
environment='production' if config['generic']['production'] else 'development', | |
server=resolve_current_machine_name() | |
) | |
FRONTEND_REQUESTS = Counter( | |
'broker_frontend_requests', | |
'Incoming requests to frontend endpoints on broker', | |
['environment', 'server', 'endpoint', 'status'] | |
) | |
FRONTEND_REQUESTS.labels = partial( | |
FRONTEND_REQUESTS.labels, | |
environment='production' if config['generic']['production'] else 'development', | |
server=resolve_current_machine_name() | |
) | |
QUEUE_TIME = QUEUE_TIME.observe(0.8) | |
FRONTEND_REQUESTS.labels(endpoint="/widget", status="ok").inc() | |
from prometheus_client import start_http_server | |
import time | |
start_http_server(8000) | |
while True: | |
time.sleep(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment