Skip to content

Commit

Permalink
Log modem log items to console
Browse files Browse the repository at this point in the history
Log the modem log items to console. This prevents log lines from
being lost when the modem resets.
  • Loading branch information
ties committed Dec 11, 2023
1 parent 24479b9 commit df2d881
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@
index page.
* Build with Python 3.12
* Update pre-commit settings
* Log new modem log items with `f3896.eventlog` tag:
```
INFO:f3896.eventlog:2023-12-09T19:46:45+00:00 [notice]: US profile assignment change. US Chan ID: 27; Previous Profile: 10 13; New Profile: 11 13.;CM-MAC=44:05:de:ad:be:ef;CMTS-MAC=00:01:de:ad:be:ef;CM-QOS=1.1;CM-VER=3.1;
INFO:f3896.eventlog:2023-12-09T18:36:26+00:00 [notice]: US profile assignment change. US Chan ID: 27; Previous Profile: 9 13; New Profile: 10 13.;CM-MAC=44:05:de:ad:be:ef;CMTS-MAC=00:01:de:ad:be:ef;CM-QOS=1.1;CM-VER=3.1;
```
15 changes: 14 additions & 1 deletion sagemcom_f3896_client/exporter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import logging
import os
from typing import List
from typing import List, Set

import aiohttp
import click
Expand All @@ -18,12 +18,14 @@
UpstreamProfileMessage,
)
from sagemcom_f3896_client.models import (
EventLogItem,
ModemDownstreamChannelResult,
ModemUpstreamChannelResult,
)
from sagemcom_f3896_client.profile_messages import ProfileMessageStore

LOG = logging.getLogger(__name__)
MODEM_LOG = logging.getLogger("modem.eventlog")

MODEM_METRICS_DURATION = Summary(
"modem_metrics_processing_seconds", "Time spent processing modem metrics"
Expand All @@ -44,6 +46,7 @@ class Exporter:
modem_upstreams: List[ModemUpstreamChannelResult] = []

profile_messages: ProfileMessageStore
previous_logs: Set[EventLogItem] = set()

def __init__(self, client: SagemcomModemSessionClient, port: int):
self.client = client
Expand Down Expand Up @@ -373,6 +376,16 @@ async def __log_based_metrics(self, registry: CollectorRegistry) -> None:
log_lines = await self.client.modem_event_log()
for line in log_lines:
metric_log_by_priority.labels(priority=line.priority).inc()

# print the new log message
current_messages = set(log_lines)
new_messages = current_messages - self.previous_logs
for msg in sorted(new_messages, reverse=True):
MODEM_LOG.info(
"%s [%s]: %s", msg.time.isoformat(), msg.priority, msg.message
)
self.previous_logs = current_messages

# parse the log lines
log_messages = [line.parse() for line in reversed(log_lines)]

Expand Down

0 comments on commit df2d881

Please sign in to comment.