-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path60_esxi_df.sh
executable file
·46 lines (39 loc) · 1.08 KB
/
60_esxi_df.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
#!/bin/bash
community=$1
host=$2
version="2c"
date=$(date +%s)
count=0
list=$(snmpdf -v $version -c $community $host)
echo "["
while read -r line; do
if (($count != 0)); then
if (($count > 1)); then
echo -n ","
fi
index=$(echo $line | awk '{print $1}')
index=$(echo $index | xargs) #trim the white space
size=$(echo $line | awk '{print $2}')
size=$(echo $size | xargs) #trim the white space
used=$(echo $line | awk '{print $5}')
used=$(echo $used | xargs -d% | xargs) #trim the white space
echo "{\
\"endpoint\" : \"$host\",\
\"tags\" : \"mount=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.df.size.kilobytes\",\
\"value\" : $size,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
echo ",{\
\"endpoint\" : \"$host\",\
\"tags\" : \"mount=$index\",\
\"timestamp\" : $date,\
\"metric\" : \"esxi.df.used.percentage\",\
\"value\" : $used,\
\"counterType\": \"GAUGE\",\
\"step\" : 60}"
fi
count=$((count+1))
done <<< "$list"
echo "]"