Created
January 10, 2017 10:55
-
-
Save koma5/2def07299c5e364300b54cf6a869ea30 to your computer and use it in GitHub Desktop.
publish statistics about a mongodb which is recording every mqtt message in my network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, pymongo, mosquitto, json | |
from pymongo import MongoClient | |
client = MongoClient('mongo') | |
records = client.mqttRecord | |
mqttC = mosquitto.Mosquitto("publishMongoStats-"+str(os.getpid())) | |
mqttC.connect("mqtt", 1883, 60) | |
dbStats = records.command('dbstats') | |
mqttC.publish("byteli/mongo/mqttRecord", json.dumps(dbStats), 1, retain=True) | |
collStatsAvg = records.command('collstats', 'averages') | |
collStatsMsg = records.command('collstats', 'messages') | |
mqttC.publish("byteli/mongo/mqttRecord/messages", json.dumps(collStatsMsg), 1, retain=True) | |
mqttC.publish("byteli/mongo/mqttRecord/averages", json.dumps(collStatsAvg), 1, retain=True) | |
mqttC.disconnect() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment