-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathipfs-collect
executable file
·47 lines (38 loc) · 1.33 KB
/
ipfs-collect
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
47
#!/bin/sh
set -eu
rrd_file=ipfs.rrd
data_file=data
if ! [ -e "$rrd_file" ]; then
rrdtool create "$rrd_file" -s 10 --no-overwrite \
DS:data_in:DERIVE:10:0:U \
DS:bw_total_in:DERIVE:10:0:U \
DS:bw_total_out:DERIVE:10:0:U \
DS:blocks_in:DERIVE:10:0:U \
DS:blocks_dup_in:DERIVE:10:0:U \
DS:wantlist_length:GAUGE:10:0:U \
RRA:AVERAGE:0.5:1:8640 \
RRA:MIN:0.5:1:8640 \
RRA:MAX:0.5:1:8640 \
RRA:LAST:0.5:1:8640
fi
while printf '\n'; sleep 5; do :; done | while read l; do
data_in=U
bw_total_in=U
bw_total_out=U
blocks_in=U
blocks_dup_in=U
wantlist_length=U
eval "$(
set +e
stat -c 'data_in=%s;' "$data_file"
curl -s 'http://127.0.0.1:5001/api/v0/stats/bw?encoding=json&stream-channels=true' | \
jq -r '@sh "bw_total_in=\(.TotalIn | tonumber); bw_total_out=\(.TotalOut | tonumber);"'
curl -s 'http://127.0.0.1:5001/api/v0/bitswap/stat?encoding=json&stream-channels=true' | \
jq -r '@sh "blocks_in=\(.BlocksReceived | tonumber); blocks_dup_in=\(.DupBlksReceived | tonumber); wantlist_length=\(.Wantlist | length);"'
)"
update="N:$data_in:$bw_total_in:$bw_total_out:$blocks_in:$blocks_dup_in:$wantlist_length"
printf '%s\n' "$update"
rrdtool update "$rrd_file" \
-t data_in:bw_total_in:bw_total_out:blocks_in:blocks_dup_in:wantlist_length \
"$update"
done