Skip to content

Commit 6036f7f

Browse files
Merge pull request #4 from pluralsh/setup-prometheus
Setup Prometheus
2 parents b6b7c85 + 4873b90 commit 6036f7f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/main.py

+13
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
from fastapi import FastAPI
2+
from prometheus_fastapi_instrumentator import Instrumentator
3+
import prometheus_client as prom
4+
import time
25

36
import os
47

58
app = FastAPI()
9+
Instrumentator().instrument(app)
10+
11+
prom.start_http_server(9090)
12+
13+
@app.get("/ping")
14+
def test():
15+
if int(time.time()) % 3 == 0:
16+
raise Exception("unknown internal error")
17+
18+
return {"pong": True}
619

720
@app.get("/")
821
def read_root():

requirements.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fastapi~=0.103
22
uvicorn~=0.23
3-
httpx
3+
httpx
4+
prometheus-fastapi-instrumentator

0 commit comments

Comments
 (0)