psmqtt
psmqtt copied to clipboard
Unable to set-up with raid devices
Hi, it seems that my raid 0 devices are not liked by the python program. Here's my psmqtt.conf:
import socket
mqtt_broker = '192.168.1.65' # default: 'localhost'
mqtt_port = 1883 # default: 1883
mqtt_clientid = 'GC01SRVR'
mqtt_username = 'mqtt'
mqtt_password = 'mqtt_password'
mqtt_clean_session = False
mqtt_qos = 0
mqtt_retain = False
#mqtt_topic_prefix = 'psmqtt/'
mqtt_topic_prefix = 'psmqtt/' + socket.gethostname() + '/'
mqtt_request_topic = 'request'
schedule = {
"every 1 minute" : [
"cpu_percent",
"virtual_memory/percent",
],
"every 60 minutes" : "disk_usage/percent/|", # slash replaced with vertical slash
"every 1 second" : [
"disk_usage/percent/|dev|mapper|backup",
"disk_usage/percent/|dev|mappervm",
"disk_usage/percent/|dev|mapper3tb",
"disk_usage/percent/|dev|mapper|4tb",
"disk_usage/percent/|",
]
}
Forgot to add the error I get:
root@GC01SRVR:psmqtt$ python3 psmqtt.py
[2021-11-19 18:34:56,902] DEBUG Connected to MQTT broker, subscribing to topic psmqtt/GC01SRVR/request/#
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python3.9/threading.py", line 954, in _bootstrap_inner
self.run()
File "/home/programmi/psmqtt/psmqtt.py", line 212, in run
self.s.run()
File "/usr/lib/python3.9/sched.py", line 151, in run
action(*argument, **kwargs)
File "/home/programmi/psmqtt/psmqtt.py", line 178, in on_timer
run_task(tasks, tasks)
File "/home/programmi/psmqtt/psmqtt.py", line 63, in run_task
if task.startswith(topic_prefix):
AttributeError: 'set' object has no attribute 'startswith'
Could you help me out a bit please? :)
I figured out with a bash script if anybody is interested:
Prerequisites:
apt-get install mosquitto-clients
For the disks:
#!/bin/sh
df -hl | grep '/dev/md127' | awk '{;percent+=$5;} END{print percent}' | column -t > /home/programmi/mqtt/root.txt
df -hl | grep '/dev/mapper/4tb' | awk '{;percent+=$5;} END{print percent}' | column -t > /home/programmi/mqtt/4tb.txt
df -hl | grep '/dev/mapper/3tb' | awk '{;percent+=$5;} END{print percent}' | column -t > /home/programmi/mqtt/3tb.txt
df -hl | grep '/dev/mapper/backup' | awk '{;percent+=$5;} END{print percent}' | column -t > /home/programmi/mqtt/backup.txt
df -hl | grep '/dev/mapper/vm' | awk '{;percent+=$5;} END{print percent}' | column -t > /home/programmi/mqtt/vm.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P mqtt_password -t GC01SRVR/disk_usage/root -f /home/programmi/mqtt/root.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P mqtt_password -t GC01SRVR/disk_usage/4tb -f /home/programmi/mqtt/4tb.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/disk_usage/3tb -f /home/programmi/mqtt/3tb.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/disk_usage/backup -f /home/programmi/mqtt/backup.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/disk_usage/vm -f /home/programmi/mqtt/vm.txt
For the CPU:
#!/bin/bash
awk '{u=$2+$4; t=$2+$4+$5; if (NR==1){u1=u; t1=t;} else print ($2+$4-u1) * 100 / (t-t1) ; }' <(grep 'cpu ' /proc/stat) <(sleep 1;grep 'cpu ' /proc/stat) > /home/prog>
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/cpu_usage -f /home/programmi/mqtt/cpu.txt
For the memory available:
#!/bin/bash
AVAILABLEMEM=$(grep MemAvailable /proc/meminfo | grep -o -E '[0-9]+')
echo "scale=2;$AVAILABLEMEM/1000000" | bc > /home/programmi/mqtt/memoryavailable.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/memory_available -f /home/programmi/mqtt/memoryavailable.txt
For the uptime
#!/bin/bash
UPTIME=$(cat /proc/uptime | head -n1 | awk '{print $1;}')
echo "scale=2;$UPTIME/60/60/24" | bc > /home/programmi/mqtt/uptime.txt
mosquitto_pub -h 192.168.1.65 -p 1883 -u user -P password -t GC01SRVR/uptime -f /home/programmi/mqtt/uptime.txt