-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_metrics.sh
More file actions
executable file
·34 lines (23 loc) · 968 Bytes
/
send_metrics.sh
File metadata and controls
executable file
·34 lines (23 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
COLLECTOR_API_PORT=3035
# Array of possible states
states=("cpu" "ram" "disk" "network")
while true; do
# Generate a random index to select a state from the array
index=$(( RANDOM % ${#states[@]} ))
# Select a random state
state=${states[$index]}
# Generate a random value between 0 and 2500
value=$(( RANDOM % 2501 ))
# Generate the current timestamp in the specified format
timestamp=$(date -u +"%Y-%m-%dT%H:%M:%S%z")
# Generate a random correlation_id between 0 and 10000
corelation_id=$(( RANDOM % 10001 ))
# Print the variables
echo "Send a metric with Corelation_id: $corelation_id, Timestamp: $timestamp, State: $state and Value: $value"
# Send the metric to the
curl -X POST "localhost:3035/metrics" -H "Content-Type: application/json" \
--data-raw "{\"corelation_id\": \"$corelation_id\",\"name\":\"$state\",\"timestamp\": \"$timestamp\", \"value\":$value}"
# Delay for 100 milliseconds
sleep .1
done