-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brett Beutell
committed
May 9, 2023
1 parent
a29a178
commit d6abce3
Showing
5 changed files
with
33 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,42 @@ | ||
from fastapi import FastAPI | ||
from fastapi import FastAPI, Response | ||
import uvicorn | ||
from autometrics import autometrics | ||
from prometheus_client import generate_latest | ||
|
||
app = FastAPI() | ||
|
||
|
||
# Set up a metrics endpoint for Prometheus to scrape | ||
# `generate_lates` returns the latest metrics data in the Prometheus text format | ||
@app.get("/metrics") | ||
def metrics(): | ||
return Response(generate_latest()) | ||
|
||
|
||
@app.get("/") | ||
@autometrics | ||
def read_root(): | ||
do_something() | ||
return {"Hello": "World"} | ||
|
||
|
||
@app.get("/async-test") | ||
@autometrics | ||
async def async_test_route(): | ||
message = await my_async_function() | ||
return {"Hello": message} | ||
|
||
|
||
@autometrics | ||
def do_something(): | ||
print("I did something") | ||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="localhost", port=8080) | ||
|
||
@autometrics | ||
async def my_async_function(): | ||
print("I did something async") | ||
return "Hello, async world!" | ||
|
||
|
||
if __name__ == "__main__": | ||
uvicorn.run(app, host="localhost", port=8080) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
anyio==3.6.2 | ||
# autometrics==0.4 | ||
shame-deps/autometrics-0.5-py3-none-any.whl | ||
# shame-deps/autometrics-0.5-py3-none-any.whl | ||
# -e git+ssh://[email protected]/autometrics-dev/autometrics-py.git@0a11a33315bba5ba843b6b543e464b2871dd5206#egg=autometrics | ||
# -e ../autometrics-py | ||
-e ../autometrics-py | ||
click==8.1.3 | ||
fastapi==0.95.0 | ||
h11==0.14.0 | ||
|