From ea148037947644958bcdef98eaf4d67ff4fa115a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nagy=20K=C3=A1roly=20G=C3=A1briel?= Date: Sat, 16 Mar 2019 23:20:03 +0200 Subject: [PATCH] fluxplug: make initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nagy Károly Gábriel --- README.md | 13 +++++++++++++ chrony.sh | 10 ++++++++++ data/.keep | 0 disks.sh | 11 +++++++++++ loadavg.sh | 11 +++++++++++ master | 35 +++++++++++++++++++++++++++++++++++ meminfo.sh | 11 +++++++++++ packs.sh | 13 +++++++++++++ tmp/.keep | 0 9 files changed, 104 insertions(+) create mode 100644 README.md create mode 100755 chrony.sh create mode 100644 data/.keep create mode 100755 disks.sh create mode 100755 loadavg.sh create mode 100644 master create mode 100755 meminfo.sh create mode 100755 packs.sh create mode 100644 tmp/.keep diff --git a/README.md b/README.md new file mode 100644 index 0000000..099d411 --- /dev/null +++ b/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) + diff --git a/chrony.sh b/chrony.sh new file mode 100755 index 0000000..19bdb26 --- /dev/null +++ b/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" diff --git a/data/.keep b/data/.keep new file mode 100644 index 0000000..e69de29 diff --git a/disks.sh b/disks.sh new file mode 100755 index 0000000..369041c --- /dev/null +++ b/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)) + diff --git a/loadavg.sh b/loadavg.sh new file mode 100755 index 0000000..388a281 --- /dev/null +++ b/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" + diff --git a/master b/master new file mode 100644 index 0000000..a7a50bf --- /dev/null +++ b/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 + + +} + diff --git a/meminfo.sh b/meminfo.sh new file mode 100755 index 0000000..92d7f51 --- /dev/null +++ b/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" + diff --git a/packs.sh b/packs.sh new file mode 100755 index 0000000..200bb69 --- /dev/null +++ b/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 + diff --git a/tmp/.keep b/tmp/.keep new file mode 100644 index 0000000..e69de29