Systemd > MQTT Bridge
MQay is a Python script that monitors the memory usage and uptime of one or more systemd services, and publishes this information to an MQTT broker. The script can be used to keep track of important system processes and receive notifications when they go down.
MQay requires the following Python packages to be installed:
psutilpaho-mqtt
To install the dependencies, you can run the following command:
pip install -r requirements.txt
Before running MQay, you need to set the following variables in the script:
service_names: A list of the systemd services you want to monitor.broker_address: The hostname or IP address of the MQTT broker.broker_port: The port number of the MQTT broker (usually 1883).broker_username: The username to use for authenticating with the MQTT broker.broker_password: The password to use for authenticating with the MQTT broker.
You can also adjust the time interval between checks by changing the value of the time.sleep function.
To run MQay, simply execute the script using Python:
python mqay.py service1 service2 service3
To build the Docker image for MQay, run the following command in the project directory:
docker build -t mqay .
This will build a Docker image with the name mqay.
To run the MQay script in a Docker container, you can use the following command:
docker run --rm -e service_names="service1,service2,service3" mqay service1 service2 service3
Make sure to replace the values of the environment variables with your own values. The --rm flag ensures that the container is removed after it stops running.
The script will start monitoring the specified systemd services and publishing their memory usage and uptime information to the MQTT broker. When a service goes down, the script will publish the following information:
memory: 0cpu_time: "Off"
MQay is released under the MIT License.