Browse Source

fluxplug: make initial commit

Signed-off-by: Nagy Károly Gábriel <k@jpi.io>
master
Nagy Károly Gábriel 6 years ago
commit
ea14803794
Signed by: karasz
GPG Key ID: C6BA1070A8CBDA0C
  1. 13
      README.md
  2. 10
      chrony.sh
  3. 0
      data/.keep
  4. 11
      disks.sh
  5. 11
      loadavg.sh
  6. 35
      master
  7. 11
      meminfo.sh
  8. 13
      packs.sh
  9. 0
      tmp/.keep

13
README.md

@ -0,0 +1,13 @@
# FluXPlug
`fluxplug` is group of shell utilities that makes feeding data to InfluxDB via HTTP easier.
`fluxplug` aspires to be a replacement for telegraf from InfluxData writen in shell and making output only to InfluxDB's HTTP API.
For now FluXPlug has the following plugins (measurements):
* Chrony - it will feed data from a `chrony` client.
* Disks - it will parse `df` data and feed it to InfluxDB
* LoadAVG - parse `/proc/loadavg` and feed InfluxDB with it
* MemInfo - parse `/proc/meminfo` and feeds the result to InfluxDB
* Packs - will execute APT and feed InfluxDB with the number of upgradable packages (no modifications to the system will be made)

10
chrony.sh

@ -0,0 +1,10 @@
#!/bin/sh
set -o noclobber
HOME=$(dirname $0)
. "$HOME"/master
LINE=$($CHRONY | "$AWK" -F"," -v myhost="$myhost" -v time=`date -u +%s%N` '{printf "chrony,host=%s,reference_id=%s,stratum=%si,leap_status=%s system_time=%s,last_offset=%s,rms_offset=%s,frequency=%s,residual_frequency=%s,skew=%s,root_delay=%s,root_dispersion=%s,update_interval=%s %s\n",myhost,$2,$3,$13,$4,$5,$6,$7,$8,$9,$10,$11,$12,time}')
writeline "$LINE" "$MAXLINES"

0
data/.keep

11
disks.sh

@ -0,0 +1,11 @@
#!/bin/sh
set -o noclobber
HOME=$(dirname $0)
. "$HOME"/master
LINE=$($DF | $SED | "$AWK" -v myhost="$myhost" -v time=`date -u +%s%N` '{sub(/\%$/,"",$5);printf "disks,host=%s,disk=%s total=%s,available=%s,used=%s,percent=%s %s\n",myhost,$1,$2,$4,$3,$5,time}')
writeline "$LINE" $((2*$MAXLINES))

11
loadavg.sh

@ -0,0 +1,11 @@
#!/bin/sh
set -o noclobber
HOME=$(dirname $0)
. "$HOME"/master
LINE=$("$AWK" -v myhost="$myhost" -v time=`date -u +%s%N` '{load1=$1; load5=$2; load15=$3 } END {printf "loadavg,host=%s load_1=%s,load_5=%s,load_15=%s %s\n",myhost,load1,load5,load15,time}' /proc/loadavg )
writeline "$LINE" "$MAXLINES"

35
master

@ -0,0 +1,35 @@
#!/bin/sh
myhost=$(/bin/hostname -f)
CURL="/usr/bin/curl -is -u user:password -XPOST 'http://influxdb.url/write?db=jpi' --data-binary "
AWK="/usr/bin/awk"
WC="/usr/bin/wc"
DF="/bin/df -t ext4 "
SED="/bin/sed -e 1d"
CHRONY="/usr/bin/chronyc -nc tracking"
z=$(basename $0)
IAM="${z%.*}"
tmpfile="$HOME"/tmp/"$IAM"
datafile="$HOME"/data/"$IAM"
MAXLINES=10
sendfile() {
datfile="$1"
echo $CURL" @$datfile"
}
writeline() {
line="$1"
length="$2"
echo "$line" >> "$tmpfile"
lines=$("$WC" -l < "$tmpfile")
if [ "$lines" -ge $length ]; then
mv "$tmpfile" "$datafile"
sendfile "$datafile"
fi
}

11
meminfo.sh

@ -0,0 +1,11 @@
#!/bin/sh
set -o noclobber
HOME=$(dirname $0)
. "$HOME"/master
LINE=$("$AWK" -v myhost="$myhost" -v time=`date -u +%s%N` '{if ($1 ~/MemTotal:/) memtotal=$2; if ($1 ~/MemFree:/) memfree=$2; if ($1 ~/MemAvailable:/) memavailable=$2} END {if ( memtotal && memfree && memavailable ) printf "meminfo,host=%s mem_total=%si,mem_free=%si,mem_available=%si %s\n",myhost,memtotal,memfree,memavailable,time}' /proc/meminfo)
writeline "$LINE" "$MAXLINES"

13
packs.sh

@ -0,0 +1,13 @@
#!/bin/sh
set -o noclobber
HOME=$(dirname $0)
. "$HOME"/master
LINE=$("$APT" | "$AWK" -v myhost="$myhost" -v time=`date -u +%s%N` '{if ($1~/^Inst/) counter=counter+1} END {if (counter) printf "packages,host=%s packs=%si %s\n",myhost,counter,time}')
if [ -n "${LINE##+([[:space:]])}" ]; then # <= FIXME! find a better way.
writeline "$LINE" "$MAXLINES"
fi
Loading…
Cancel
Save