Last active
August 28, 2019 20:59
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
#_______________________________________________________________________________ | |
#__ | |
#__ collect.sh | |
#__ | |
#__ Faz a coleta de network provindo do sar | |
#__ | |
#__ autor : Afonso Rodrigues | |
#__ data : 27/08/2019 | |
#__ | |
#__ historico de manutencao | |
#__ | |
#__ 00/00/0000 - Autor - Descrição | |
#__ | |
#_______________________________________________________________________________ | |
set -e | |
AWK=/usr/bin/awk | |
CAT=/bin/cat | |
DATE=/bin/date | |
SAR=/usr/bin/sar | |
SED=/bin/sed | |
SEQ=/usr/bin/seq | |
ECHO="/bin/echo -e" | |
export LC_TIME="POSIX" | |
export LC_NUMERIC=en_US.UTF-8 | |
COLUMN_METRIC=2 | |
COLUMN_START_DATA=3 | |
HOSTNAME=`hostname` | |
`$CAT /dev/null > metric` | |
COUNT_INTERFACES=`ls -A /sys/class/net | wc -l` | |
TIMESTAMP=`$DATE +%s` | |
COLLECT_DATA=`$SAR -n DEV 1 1` | |
HEADER=`$ECHO "$COLLECT_DATA" | $SED -n 3p | $SED 's1/1_1g; s1%1p_1g'` | |
N_COLUMNS=`$ECHO "$HEADER" | head -1| tr '|' ' ' | wc -w ` | |
let "N_END_DATA=$COUNT_INTERFACES+3" | |
DATA=`$ECHO "$COLLECT_DATA" | $AWK -v end="$N_END_DATA" 'NR >= 4 && NR <= end'` | |
for i in `$SEQ 1 $COUNT_INTERFACES`; | |
do | |
LINE=`$ECHO "$DATA" | $AWK -v line="$i" 'NR == line'` | |
for j in `$SEQ $COLUMN_START_DATA $N_COLUMNS`; | |
do | |
METRIC_NAME=`$ECHO "$HEADER" | $AWK -F ' ' '{print $fld}' fld=$j ` | |
METRIC=`$ECHO "$LINE" | $AWK -F ' ' '{print ",tag=reverse-proxy-edge,interface="$2" value="$fld}' fld=$j ` | |
$ECHO "sar_network_$METRIC_NAME,host=$HOSTNAME$METRIC" >> metric | |
done | |
done | |
$CAT metric | |
curl -i -XPOST 'http://localhost:8086/write?db=sar' --data-binary @metric |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://docs.influxdata.com/platform/install-and-deploy/deploying/sandbox-install/ | |
git clone https://github.com/influxdata/sandbox.git |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment