70 |
72 |
71 self.__subscribedTopics = [] |
73 self.__subscribedTopics = [] |
72 self.__topicQueue = {} |
74 self.__topicQueue = {} |
73 self.__updateUnsubscribeTopicComboBox() |
75 self.__updateUnsubscribeTopicComboBox() |
74 |
76 |
|
77 prefix = MqttMonitorWidget.BrokerStatusTopicPrefix |
75 self.__statusLabelMapping = { |
78 self.__statusLabelMapping = { |
76 MqttMonitorWidget.BrokerStatusTopicPrefix + "version": |
79 # broker |
77 self.versionLabel, |
80 prefix + "version": self.versionLabel, |
78 MqttMonitorWidget.BrokerStatusTopicPrefix + "timestamp": |
81 prefix + "timestamp": self.timestampLabel, |
79 self.timestampLabel, |
82 prefix + "uptime": self.uptimeLabel, |
80 MqttMonitorWidget.BrokerStatusTopicPrefix + "uptime": |
83 prefix + "subscriptions/count": self.subscriptionsLabel, |
81 self.uptimeLabel, |
84 # clients |
82 MqttMonitorWidget.BrokerStatusTopicPrefix + "subscriptions/count": |
85 prefix + "clients/connected": self.clientsConnectedLabel, |
83 self.subscriptionsLabel, |
86 prefix + "clients/disconnected": self.clientsDisconnectedLabel, |
84 MqttMonitorWidget.BrokerStatusTopicPrefix + "clients/connected": |
87 prefix + "clients/expired": self.clientsExpiredLabel, |
85 self.clientsConnectedLabel, |
88 prefix + "clients/maximum": self.clientsMaximumLabel, |
86 MqttMonitorWidget.BrokerStatusTopicPrefix + "clients/disconnected": |
89 prefix + "clients/total": self.clientsTotalLabel, |
87 self.clientsDisconnectedLabel, |
90 # messages |
88 MqttMonitorWidget.BrokerStatusTopicPrefix + "clients/expired": |
91 prefix + "messages/sent": self.messagesSentLabel, |
89 self.clientsExpiredLabel, |
92 prefix + "messages/received": self.messagesReceivedLabel, |
90 MqttMonitorWidget.BrokerStatusTopicPrefix + "clients/maximum": |
93 prefix + "messages/stored": self.messagesStoredLabel, |
91 self.clientsMaximumLabel, |
94 prefix + "store/messages/count": self.messagesStoredLabel, |
92 MqttMonitorWidget.BrokerStatusTopicPrefix + "clients/total": |
95 prefix + "messages/inflight": self.messagesInflightLabel, |
93 self.clientsTotalLabel, |
96 prefix + "retained messages/count": self.messagesRetainedLabel, |
94 MqttMonitorWidget.BrokerStatusTopicPrefix + "messages/sent": |
97 # publish messages |
95 self.messagesSentLabel, |
98 prefix + "publish/messages/sent": self.publishMessagesSentLabel, |
96 MqttMonitorWidget.BrokerStatusTopicPrefix + "messages/received": |
99 prefix + "publish/messages/received": |
97 self.messagesReceivedLabel, |
|
98 MqttMonitorWidget.BrokerStatusTopicPrefix + "messages/stored": |
|
99 self.messagesStoredLabel, |
|
100 MqttMonitorWidget.BrokerStatusTopicPrefix + "store/messages/count": |
|
101 self.messagesStoredLabel, |
|
102 MqttMonitorWidget.BrokerStatusTopicPrefix + "messages/inflight": |
|
103 self.messagesInflightLabel, |
|
104 MqttMonitorWidget.BrokerStatusTopicPrefix + \ |
|
105 "retained messages/count": |
|
106 self.messagesRetainedLabel, |
|
107 MqttMonitorWidget.BrokerStatusTopicPrefix + \ |
|
108 "publish/messages/sent": |
|
109 self.publishMessagesSentLabel, |
|
110 MqttMonitorWidget.BrokerStatusTopicPrefix + \ |
|
111 "publish/messages/received": |
|
112 self.publishMessagesReceivedLabel, |
100 self.publishMessagesReceivedLabel, |
113 MqttMonitorWidget.BrokerStatusTopicPrefix + \ |
101 prefix + "publish/messages/dropped": |
114 "publish/messages/dropped": |
|
115 self.publishMessagesDroppedLabel, |
102 self.publishMessagesDroppedLabel, |
116 MqttMonitorWidget.BrokerStatusTopicPrefix + "bytes/sent": |
103 # traffic |
117 self.bytesSentLabel, |
104 prefix + "bytes/sent": self.bytesSentLabel, |
118 MqttMonitorWidget.BrokerStatusTopicPrefix + "bytes/received": |
105 prefix + "bytes/received": self.bytesReceivedLabel, |
119 self.bytesReceivedLabel, |
106 # load |
120 ## MqttMonitorWidget.BrokerStatusTopicPrefix + "": |
107 prefix + "load/bytes/sent": self.loadBytesSentLabel, |
121 ## self.versionLabel, |
108 prefix + "load/bytes/received": self.loadBytesReceivedLabel, |
|
109 prefix + "load/messages/sent": self.loadMessagesSentLabel, |
|
110 prefix + "load/messages/received": self.loadMessagesReceivedLabel, |
|
111 prefix + "load/publish/sent": self.loadPublishSentLabel, |
|
112 prefix + "load/publish/received": self.loadPublishReceivedLabel, |
|
113 prefix + "load/publish/dropped": self.loadPublishDroppedLabel, |
|
114 prefix + "load/connections": self.loadConnectionsLabel, |
|
115 prefix + "load/sockets": self.loadSocketsLabel, |
122 } |
116 } |
|
117 |
|
118 self.__statusLoadValues = collections.defaultdict( |
|
119 self.__loadDefaultDictFactory) |
123 |
120 |
124 self.__client = MqttClient() |
121 self.__client = MqttClient() |
125 |
122 |
126 # connect the MQTT client signals |
123 # connect the MQTT client signals |
127 self.__client.onConnect.connect(self.__brokerConnected) |
124 self.__client.onConnect.connect(self.__brokerConnected) |
425 @type str |
426 @type str |
426 @param payload payload of the received message |
427 @param payload payload of the received message |
427 @type bytes |
428 @type bytes |
428 """ |
429 """ |
429 payloadStr = str(payload, encoding="utf-8", errors="replace").strip() |
430 payloadStr = str(payload, encoding="utf-8", errors="replace").strip() |
|
431 topic = topic.strip() |
|
432 |
|
433 if topic.startswith(MqttMonitorWidget.BrokerStatusTopicLoadPrefix): |
|
434 self.__handleBrokerLoadStatusMessage(topic, payloadStr) |
|
435 else: |
|
436 try: |
|
437 label = self.__statusLabelMapping[topic] |
|
438 label.setText(payloadStr) |
|
439 except KeyError: |
|
440 # ignore topics not shown in display |
|
441 pass |
|
442 |
|
443 def __handleBrokerLoadStatusMessage(self, topic, payloadStr): |
|
444 """ |
|
445 Private method to append a received message to the output. |
|
446 |
|
447 @param topic topic of the received message |
|
448 @type str |
|
449 @param payloadStr string representation of the payload of the |
|
450 received message |
|
451 @type str |
|
452 """ |
|
453 subtopic, topicElement = topic.rsplit("/", 1) |
|
454 self.__statusLoadValues[subtopic][topicElement] = payloadStr |
430 |
455 |
431 try: |
456 try: |
432 label = self.__statusLabelMapping[topic.strip()] |
457 label = self.__statusLabelMapping[subtopic] |
433 label.setText(payloadStr) |
458 label.setText("{0} / {1} / {2}".format( |
|
459 self.__statusLoadValues[subtopic]["1min"], |
|
460 self.__statusLoadValues[subtopic]["5min"], |
|
461 self.__statusLoadValues[subtopic]["15min"], |
|
462 )) |
434 except KeyError: |
463 except KeyError: |
435 # ignore topics not shown in display |
464 # ignore topics not shown in display |
436 pass |
465 pass |
|
466 |
|
467 def __loadDefaultDictFactory(self): |
|
468 """ |
|
469 Private method to populate non-existing load items. |
|
470 |
|
471 @return default dictionary entry |
|
472 @rtype dict |
|
473 """ |
|
474 return { |
|
475 "1min": "-", |
|
476 "5min": "-", |
|
477 "15min": "-", |
|
478 } |