blob: c79947f196a553f230aa6f1463214bed2a6e0301 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# 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 Chen49950b92021-11-08 19:19:18 +08005
6import asyncio
7from typing import Any
8
9from common.job import Job
10from common.log_count_handler import MsgCounterHandler
11from common.metrics import SERVICE_ERRORS
12
13# How frequently to poll systemd for error logs, in seconds
14POLL_INTERVAL = 10
15
16
17class 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)