diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba5c5db --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.fluxrc +data/ +tmp/ +plugind-enabled/ diff --git a/fluxplug b/fluxplug new file mode 100755 index 0000000..3741a50 --- /dev/null +++ b/fluxplug @@ -0,0 +1,52 @@ +#!/bin/sh +#General variables +FLUXPLUGHOME="/opt/fluxplug" +myhost=$(/bin/hostname -f) +MAXLINES=10 + +# Utilities +CURL="/usr/bin/curl" +AWK="/usr/bin/awk" +WC="/usr/bin/wc" +DF="/bin/df" +SED="/bin/sed" +CHRONY="/usr/bin/chronyc" + +#Utilities with opts +CURLWOPTS="$CURL -is -o /dev/null -w \"%{http_code}\\\n\" --netrc-file $FLUXPLUGHOME/.fluxrc -XPOST 'http://influxdb.url/write?db=mydb' --data-binary" +CHRONYWOPTS="$CHRONY -nc tracking" +DFWOPTS="$DF -t ext4" +SEDWOPTS="$SED -e 1d" + +#Directories +tmpdir="$FLUXPLUGHOME"/tmp +datadir="$FLUXPLUGHOME"/data + +send_file() { + datfile="$1" + echo $CURLWOPTS" @$datfile" +} + +write_line() { + line="$1" + length="$2" + file="$3" + tmpfile="$tmpdir"/"$file" + datafile="$datadir"/"$file" + + echo "$line" >> "$tmpfile" + lines=$("$WC" -l < "$tmpfile") + if [ "$lines" -ge $length ]; then + mv "$tmpfile" "$datafile" + send_file "$datafile" + fi +} + +execute_every_minute() { + for i in $(ls -1 $FLUXPLUGHOME/plugins-enabled/01m*); do + . $i + done + +} + +execute_every_minute diff --git a/master b/master deleted file mode 100644 index 627db1a..0000000 --- a/master +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/sh -myhost=$(/bin/hostname -f) -CURL="/usr/bin/curl -is -o /dev/null -w \"%{http_code}\\\n\" -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="$FLUXPLUGHOME"/tmp/"$IAM" -datafile="$FLUXPLUGHOME"/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/plugins-available/chrony b/plugins-available/chrony new file mode 100644 index 0000000..a64d4a1 --- /dev/null +++ b/plugins-available/chrony @@ -0,0 +1,9 @@ +#!/bin/sh + +set -o noclobber + +me="chrony" + +LINE=$($CHRONYWOPTS | "$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}') + +write_line "$LINE" "$MAXLINES" "$me" diff --git a/plugins-available/chrony.sh b/plugins-available/chrony.sh deleted file mode 100755 index aecd3f6..0000000 --- a/plugins-available/chrony.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -set -o noclobber -old=$PWD -cd $(dirname $(readlink -f "$0")) -cd ../ -FLUXPLUGHOME=$PWD -. "$FLUXPLUGHOME"/master -cd $old - -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/plugins-available/disks.sh b/plugins-available/disks old mode 100755 new mode 100644 similarity index 62% rename from plugins-available/disks.sh rename to plugins-available/disks index 8b75f87..1f7d4e8 --- a/plugins-available/disks.sh +++ b/plugins-available/disks @@ -1,14 +1,10 @@ #!/bin/sh set -o noclobber -old=$PWD -cd $(dirname $(readlink -f "$0") -cd ../ -FLUXPLUGHOME=$PWD -. "$FLUXPLUGHOME"/master -cd $old + +me="disks" 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)) +writeline "$LINE" $((2*$MAXLINES)) "$me" diff --git a/plugins-available/loadavg.sh b/plugins-available/loadavg old mode 100755 new mode 100644 similarity index 64% rename from plugins-available/loadavg.sh rename to plugins-available/loadavg index c7b470f..c3cef47 --- a/plugins-available/loadavg.sh +++ b/plugins-available/loadavg @@ -1,14 +1,10 @@ #!/bin/sh set -o noclobber -old=$PWD -cd $(dirname $(readlink -f "$0")) -cd ../ -FLUXPLUGHOME=$PWD -. "$FLUXPLUGHOME"/master -cd $old + +me="loadavg" 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" +writeline "$LINE" "$MAXLINES" "$me" diff --git a/plugins-available/meminfo.sh b/plugins-available/meminfo old mode 100755 new mode 100644 similarity index 74% rename from plugins-available/meminfo.sh rename to plugins-available/meminfo index bd931eb..32711ec --- a/plugins-available/meminfo.sh +++ b/plugins-available/meminfo @@ -1,14 +1,10 @@ #!/bin/sh set -o noclobber -old=$PWD -cd $(dirname $(readlink -f "$0")) -cd ../ -FLUXPLUGHOME=$PWD -. "$FLUXPLUGHOME"/master -cd $old + +me="meinfo" 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" +writeline "$LINE" "$MAXLINES" "$me" diff --git a/plugins-available/packs.sh b/plugins-available/packs old mode 100755 new mode 100644 similarity index 69% rename from plugins-available/packs.sh rename to plugins-available/packs index 02ffccd..2fb7025 --- a/plugins-available/packs.sh +++ b/plugins-available/packs @@ -1,16 +1,12 @@ #!/bin/sh set -o noclobber -old=$PWD -cd $(dirname $(readlink -f "$0")) -cd ../ -FLUXPLUGHOME=$PWD -. "$FLUXPLUGHOME"/master -cd $old + +me="packs" 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" + writeline "$LINE" "$MAXLINES" "$me" fi