Skip to content

Instantly share code, notes, and snippets.

@afonsoaugusto
Last active August 28, 2019 20:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save afonsoaugusto/d03309fb0f434d7d3809661d630ca21d to your computer and use it in GitHub Desktop.
#!/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
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