mirror of
https://github.com/tcivie/meshtastic-metrics-exporter.git
synced 2024-12-27 14:39:57 -08:00
Merge branch 'main' into add-support-for-neighbour-info
This commit is contained in:
commit
555885baf9
|
@ -461,9 +461,9 @@ class TraceRouteAppProcessor(Processor):
|
|||
traceroute.ParseFromString(payload)
|
||||
if traceroute.route:
|
||||
route = traceroute.route
|
||||
self.metrics.route_discovery_counter.labels(
|
||||
self.metrics.route_discovery_gauge.labels(
|
||||
**client_details.to_dict()
|
||||
).inc(len(route))
|
||||
).set(len(route))
|
||||
|
||||
|
||||
@ProcessorRegistry.register_processor(PortNum.NEIGHBORINFO_APP)
|
||||
|
|
|
@ -324,7 +324,7 @@ class _Metrics:
|
|||
)
|
||||
|
||||
def _init_route_discovery_metrics(self):
|
||||
self.route_discovery_counter = Counter(
|
||||
self.route_discovery_gauge = Gauge(
|
||||
'route_length',
|
||||
'Number of nodes in the route',
|
||||
self._get_common_labels(),
|
||||
|
|
14
main.py
14
main.py
|
@ -35,11 +35,23 @@ def handle_connect(client, userdata, flags, reason_code, properties):
|
|||
client.subscribe(os.getenv('MQTT_TOPIC', 'msh/israel/#'))
|
||||
|
||||
|
||||
def update_node_status(node_number, status):
|
||||
with connection_pool.connection() as conn:
|
||||
with conn.cursor() as cur:
|
||||
cur.execute("INSERT INTO client_details (node_id, mqtt_status) VALUES (%s, %s)"
|
||||
"ON CONFLICT(node_id)"
|
||||
"DO UPDATE SET mqtt_status = %s", (node_number, status, status))
|
||||
conn.commit()
|
||||
|
||||
|
||||
def handle_message(client, userdata, message):
|
||||
current_timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
print(f"Received message on topic '{message.topic}' at {current_timestamp}")
|
||||
if '/stat/' in message.topic:
|
||||
print(f"Filtered out message from topic containing '/stat/': {message.topic}")
|
||||
user_id = message.topic.split('/')[-1] # Hexadecimal user ID
|
||||
if user_id[0] == '!':
|
||||
node_number = str(int(user_id[1:], 16))
|
||||
update_node_status(node_number, message.payload.decode('utf-8'))
|
||||
return
|
||||
|
||||
envelope = ServiceEnvelope()
|
||||
|
|
|
@ -5,4 +5,5 @@ unishox2-py3~=1.0.0
|
|||
cryptography~=42.0.8
|
||||
psycopg~=3.1.19
|
||||
psycopg_pool~=3.2.2
|
||||
meshtastic~=2.3.13
|
||||
meshtastic~=2.3.13
|
||||
psycopg-binary~=3.1.20
|
Loading…
Reference in a new issue