diff --git a/sensors/Makefile b/sensors/Makefile new file mode 100644 index 0000000..39e88bc --- /dev/null +++ b/sensors/Makefile @@ -0,0 +1,5 @@ +systemd: + sudo cp ./sensors.service /etc/systemd/system + sudo cp ./sensors.timer /etc/systemd/system + sudo systemctl enable sensors.timer + sudo systemctl start sensors.timer diff --git a/scripts/conf.d/1wire b/sensors/conf.d/1wire similarity index 100% rename from scripts/conf.d/1wire rename to sensors/conf.d/1wire diff --git a/scripts/conf.d/433mhz b/sensors/conf.d/433mhz similarity index 100% rename from scripts/conf.d/433mhz rename to sensors/conf.d/433mhz diff --git a/scripts/monitor.sh b/sensors/monitor.sh similarity index 100% rename from scripts/monitor.sh rename to sensors/monitor.sh diff --git a/scripts/plugins/1wire b/sensors/plugins/1wire similarity index 97% rename from scripts/plugins/1wire rename to sensors/plugins/1wire index cd652d1..24a073b 100755 --- a/scripts/plugins/1wire +++ b/sensors/plugins/1wire @@ -24,7 +24,7 @@ GPLv2 =cut -. $MUNIN_LIBDIR/plugins/plugin.sh +source $MUNIN_LIBDIR/plugins/plugin.sh if [ "$1" = "autoconf" ]; then echo yes diff --git a/scripts/plugins/433mhz b/sensors/plugins/433mhz similarity index 98% rename from scripts/plugins/433mhz rename to sensors/plugins/433mhz index 8ad59d9..d241150 100755 --- a/scripts/plugins/433mhz +++ b/sensors/plugins/433mhz @@ -24,7 +24,7 @@ GPLv2 =cut -. $MUNIN_LIBDIR/plugins/plugin.sh +source $MUNIN_LIBDIR/plugins/plugin.sh if [ "$1" = "autoconf" ]; then echo yes diff --git a/scripts/plugins/ina219 b/sensors/plugins/ina219 similarity index 97% rename from scripts/plugins/ina219 rename to sensors/plugins/ina219 index 60ac957..29075aa 100755 --- a/scripts/plugins/ina219 +++ b/sensors/plugins/ina219 @@ -24,7 +24,7 @@ GPLv2 =cut -. $MUNIN_LIBDIR/plugins/plugin.sh +source $MUNIN_LIBDIR/plugins/plugin.sh if [ "$1" = "autoconf" ]; then echo yes diff --git a/scripts/plugins/plugin.sh b/sensors/plugins/plugin.sh similarity index 100% rename from scripts/plugins/plugin.sh rename to sensors/plugins/plugin.sh diff --git a/scripts/run.sh b/sensors/run.sh similarity index 81% rename from scripts/run.sh rename to sensors/run.sh index 080eec3..c1a55c0 100755 --- a/scripts/run.sh +++ b/sensors/run.sh @@ -2,8 +2,8 @@ source ~/.mysql-grafana.conf -PLUGINS="1wire 433mhz ina219" -#PLUGINS="433mhz" +#PLUGINS="1wire ina219 433mhz" +PLUGINS="1wire ina219 433mhz" # https://stackoverflow.com/a/1482133 SCRIPT_PATH=$(dirname -- "$( readlink -f -- "$0"; )";) @@ -13,7 +13,7 @@ SOURCE=$(hostname -s) for PLUGIN in ${PLUGINS}; do echo "Processing ${PLUGIN}..." - PLUGIN_ENV="MUNIN_LIBDIR="${SCRIPT_PATH}"" + PLUGIN_ENV=MUNIN_LIBDIR=${SCRIPT_PATH} PLUGIN_CONF="${SCRIPT_PATH}/conf.d/${PLUGIN}" if [ -f ${PLUGIN_CONF} ]; then while IFS="" read -r p || [ -n "$p" ] @@ -26,14 +26,15 @@ for PLUGIN in ${PLUGINS}; do PLUGIN_ENV+=" ${PARAM}=${VALUE}" fi done < ${PLUGIN_CONF} - echo "${PLUGIN_ENV}" fi - DATA=$(env -i ${PLUGIN_ENV} plugins/${PLUGIN}) + CMD="${PLUGIN_ENV} ${SCRIPT_PATH}/plugins/${PLUGIN}" + #echo "${CMD}" + DATA=$(eval $CMD) - echo "-----------------" - echo "$DATA" - echo "-----------------" + #echo "-----------------" + #echo "$DATA" + #echo "-----------------" TABLE_NAME="home_${PLUGIN}" # default @@ -44,7 +45,7 @@ for PLUGIN in ${PLUGINS}; do #echo $LINE SQL=$(echo $LINE | sed -E "s/(.*)\.(.*) (.*)/INSERT INTO ${TABLE_NAME} (source, metric, value) VALUES (\"${SOURCE}\",\"\1\", \"\3\");/") - #echo $SQL + echo $SQL echo $SQL | mysql --host="192.168.0.12" --database="${DATABASE}" --user="${USER}" --password="${PASSWORD}" done # LINE diff --git a/sensors/sensors.service b/sensors/sensors.service new file mode 100644 index 0000000..2435f2b --- /dev/null +++ b/sensors/sensors.service @@ -0,0 +1,8 @@ +[Unit] +Description=Read sensor values + +[Service] +Type=oneshot +User=pi +Group=pi +ExecStart=/home/pi/git/monitoring/sensors/run.sh diff --git a/sensors/sensors.timer b/sensors/sensors.timer new file mode 100644 index 0000000..919d876 --- /dev/null +++ b/sensors/sensors.timer @@ -0,0 +1,10 @@ +[Unit] +Description=Periodically update sensor readings + +[Timer] +#OnCalendar=*-*-* 10:45:00 +#OnBootSec=30sec +OnUnitActiveSec=300sec + +[Install] +WantedBy=timers.target