Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2020 The Magma Authors. |
| 2 | # SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
| 6 | import asyncio |
| 7 | from typing import Any |
| 8 | |
| 9 | from common.job import Job |
| 10 | from common.log_count_handler import MsgCounterHandler |
| 11 | from common.metrics import SERVICE_ERRORS |
| 12 | |
| 13 | # How frequently to poll systemd for error logs, in seconds |
| 14 | POLL_INTERVAL = 10 |
| 15 | |
| 16 | |
| 17 | class ServiceLogErrorReporter(Job): |
| 18 | """ Reports the number of logged errors for the service """ |
| 19 | |
| 20 | def __init__( |
| 21 | self, |
| 22 | loop: asyncio.BaseEventLoop, |
| 23 | service_config: Any, |
| 24 | handler: MsgCounterHandler, |
| 25 | ) -> None: |
| 26 | super().__init__(interval=POLL_INTERVAL, loop=loop) |
| 27 | self._service_config = service_config |
| 28 | self._handler = handler |
| 29 | |
| 30 | async def _run(self): |
| 31 | error_count = self._handler.pop_error_count() |
| 32 | SERVICE_ERRORS.inc(error_count) |