mirror of
https://github.com/grafana/grafana.git
synced 2024-12-01 21:19:28 -06:00
fixed py code indentation pt.2 (#80975)
* fixed py code indentation * pretty * 2nd code snippet update * pretty * pretty
This commit is contained in:
parent
ef50fe9ebb
commit
3a7b745278
@ -199,9 +199,9 @@ This optional step uses a python script to generate the sample logs used in this
|
||||
1. Install Python3 on your local machine if needed.
|
||||
1. Copy the python script below and paste it into a new file on your local machine.
|
||||
|
||||
```
|
||||
#!/bin/env python3
|
||||
```
|
||||
```
|
||||
|
||||
#!/bin/env python3
|
||||
|
||||
import datetime
|
||||
import math
|
||||
@ -209,12 +209,14 @@ import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
requests_per_second = 2
|
||||
failure_rate = 0.05
|
||||
get_post_ratio = 0.9
|
||||
get_average_duration_ms = 500
|
||||
post_average_duration_ms = 2000
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
# Exponential distribution random value of average 1/lines_per_second.
|
||||
@ -244,7 +246,8 @@ In a terminal window on linux-based systems run the command:
|
||||
|
||||
chmod 755 ./web-server-logs-simulator.py
|
||||
|
||||
````
|
||||
|
||||
```
|
||||
|
||||
1. Run the script.
|
||||
|
||||
@ -292,7 +295,7 @@ that generates the sample logs used in this tutorial to create alerts.
|
||||
|
||||
**Bash**
|
||||
|
||||
````
|
||||
```
|
||||
|
||||
wget https://raw.githubusercontent.com/grafana/loki/v2.8.0/production/docker-compose.yaml -O docker-compose.yaml
|
||||
|
||||
@ -347,31 +350,33 @@ import random
|
||||
import sys
|
||||
import time
|
||||
|
||||
|
||||
|
||||
requests_per_second = 2
|
||||
failure_rate = 0.05
|
||||
get_post_ratio = 0.9
|
||||
get_average_duration_ms = 500
|
||||
post_average_duration_ms = 2000
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
# Exponential distribution random value of average 1/lines_per_second.
|
||||
|
||||
d = random.expovariate(requests_per_second)
|
||||
time.sleep(d)
|
||||
if random.random() < failure_rate:
|
||||
status = "500"
|
||||
else:
|
||||
status = "200"
|
||||
if random.random() < get_post_ratio:
|
||||
method = "GET"
|
||||
duration_ms = math.floor(random.expovariate(1/get_average_duration_ms))
|
||||
else:
|
||||
method = "POST"
|
||||
duration_ms = math.floor(random.expovariate(1/post_average_duration_ms))
|
||||
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
|
||||
print(f"{timestamp} level=info method={method} url=/ status={status} duration={duration_ms}ms")
|
||||
sys.stdout.flush()
|
||||
# Exponential distribution random value of average 1/lines_per_second.
|
||||
d = random.expovariate(requests_per_second)
|
||||
time.sleep(d)
|
||||
if random.random() < failure_rate:
|
||||
status = "500"
|
||||
else:
|
||||
status = "200"
|
||||
if random.random() < get_post_ratio:
|
||||
method = "GET"
|
||||
duration_ms = math.floor(random.expovariate(1/get_average_duration_ms))
|
||||
else:
|
||||
method = "POST"
|
||||
duration_ms = math.floor(random.expovariate(1/post_average_duration_ms))
|
||||
timestamp = datetime.datetime.now(tz=datetime.timezone.utc).isoformat()
|
||||
print(f"{timestamp} level=info method={method} url=/ status={status} duration={duration_ms}ms")
|
||||
sys.stdout.flush()
|
||||
|
||||
```
|
||||
|
||||
@ -396,6 +401,7 @@ sudo touch /var/log/web_requests.log
|
||||
chmod 755 /var/log/web_requests.log
|
||||
python3 ./web-server-logs-simulator.py | tee -a /var/log/web_requests.log
|
||||
|
||||
|
||||
```
|
||||
|
||||
**Running on Windows**
|
||||
@ -425,4 +431,3 @@ If you don't see the logs in Explore, check these things:
|
||||
- If the file is empty, check that you followed the steps above to create the file and change the permissions.
|
||||
- If the file exists, verify that promtail is running and check that it is configured correctly.
|
||||
- In Grafana Explore, check that the time range is only for the last 5 minutes.
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user