forked from kuskoman/logstash-exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_metrics_to_readme.sh
executable file
·31 lines (26 loc) · 1.06 KB
/
add_metrics_to_readme.sh
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
#! /usr/bin/env bash
function getMetrics() {
curl -Ss http://localhost:9090/api/v1/targets/metadata | jq -c '.data[] | select(.metric | startswith("logstash"))' | while read -r line; do
metric=$(echo "$line" | jq -r '.metric')
type=$(echo "$line" | jq -r '.type')
help=$(echo "$line" | jq -r '.help')
echo "| $metric | $type | $help |"
done
}
FILE=README.md
while IFS= read -r line; do LINES+=("$line"); done < $FILE
startLine=$(grep -n "^<!-- METRICS_TABLE_START -->" $FILE | awk -F: '{print $1}')
endLine=$(grep -n "^<!-- METRICS_TABLE_END -->" $FILE | awk -F: '{print $1}')
metricsTable=$(echo "| Name | Type | Description |
| ----------- | ----------- | ----------- |
$(getMetrics | sort --version-sort)")
for ((i=0; i<${#LINES[@]}; i++)); do
if [ $i -eq $startLine ]; then
echo -e "${LINES[i]}"
echo "$metricsTable"
elif [ $i -gt $startLine ] && [ $i -lt $((endLine-2)) ]; then # -2 because of the empty line before the end marker
continue
else
echo -e "${LINES[i]}"
fi
done > $FILE