Created
November 5, 2023 17:28
-
-
Save tuck1s/6a17e6a5c86a2c58d518ee450a277878 to your computer and use it in GitHub Desktop.
example of grafana/loki api when you need push any log/message from your python script
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
#!/usr/bin/env python3 | |
# example of grafana/loki api when you need push any log/message from your python script | |
import requests, time | |
import names # get some random data | |
nano_ts = int(time.time()*1e9) | |
name = names.get_full_name() | |
# push msg log into grafana-loki | |
url="http://localhost:3100/loki/api/v1/push" | |
payload = { | |
"streams": [ | |
{ | |
"stream": { | |
"foo": "bar2" | |
}, | |
"values": [ | |
[ | |
str(nano_ts), | |
name, | |
] | |
] | |
} | |
] | |
} | |
answer = requests.post(url, json=payload) # automatically sets Content-Type | |
print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment