-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinflux-writer.sh
executable file
·46 lines (38 loc) · 1.1 KB
/
influx-writer.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/bash
set -o pipefail
prepare() {
csv-to-json \
| jq '.url.query.stem=(if .url.query.q then .url.query.q|split(" where")[0]|split(" WHERE")[0] else "" end)' \
| jq '.timeScale=(if .duration < 1000 then "ms" else ( if .duration < 60000 then "s" else "m" end ) end)' \
| json-to-csv --columns=duration,requestId,startedAt,status,url.query.q,url.path,url.query.stem,timeScale \
| surrogate-keys --natural-key=url.query.stem --surrogate-key=url.query.stem.hash
}
convert() {
influx-line-format \
--measurement httpd \
--tags=status,url.path,url.query.stem.hash,timeScale \
--timestamp startedAt \
--format="2006-01-02 15:04:05.999" \
--values=requestId,duration,url.query.q,url.query.stem
}
write() {
local url=$1
(
while true; do
count=0
while test $count -lt 1000; do
read -r line
if test -z "$line"; then
exit 1
fi
let count=count+1
echo "$line"
done | curl --data-binary @- -XPOST "$url" || exit 0
done
) || exit $?
}
prepare-convert-and-write() {
url="${1:-http://localhost:8086/write?db=httpdlogs&precision=ns}"
prepare | convert | write "$url"
}
"$@"