Server Monitoring with Qubitro

How To Do?

“pip install psutil”
import psutil
import paho.mqtt.client as mqtt
import time
import json
broker_host = ""
broker_port = 8883
def on_connect(client, userdata, flags, rc):
if rc == 0:
print("Connected to Qubitro!")
client.on_publish = on_publish
print("Failed to connect, visit:\n return code:", rc)
def on_publish(client, obj, publish):
print("Published: " + str(payload))
client = mqtt.Client(client_id=device_id)
client.username_pw_set(username=device_id, password=device_token)
client.connect(broker_host, broker_port, 60)
client.on_connect = on_connect

while True:
payload = {'CPU usage': psutil.cpu_percent(interval=0.5) , 'CPU frequency': int(psutil.cpu_freq().current),
'RAM Percentage': psutil.virtual_memory().percent,'Swap Percentage': psutil.swap_memory().percent,
'Memory Percentage':psutil.disk_usage('/').percent}
client.publish(device_id, payload=json.dumps(payload))

Qubitro Cloud Setup:

Device ID & Token

Let’s Start the Monitoring:

Terminal OP
Portal Output Readings



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store