|
|
|
|
@ -200,8 +200,8 @@ This optional step uses a python script to generate the sample logs used in this |
|
|
|
|
1. Copy the python script below and paste it into a new file on your local machine. |
|
|
|
|
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
#!/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,16 +350,18 @@ 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: |
|
|
|
|
@ -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. |
|
|
|
|
``` |
|
|
|
|
|