blob: 4f2aea3fdee78971299c7821edc1cdf69e32bb9a [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13
14import asyncio
15from typing import Any
16
17from common.job import Job
18from common.log_count_handler import MsgCounterHandler
19from common.metrics import SERVICE_ERRORS
20
21# How frequently to poll systemd for error logs, in seconds
22POLL_INTERVAL = 10
23
24
25class ServiceLogErrorReporter(Job):
26 """ Reports the number of logged errors for the service """
27
28 def __init__(
29 self,
30 loop: asyncio.BaseEventLoop,
31 service_config: Any,
32 handler: MsgCounterHandler,
33 ) -> None:
34 super().__init__(interval=POLL_INTERVAL, loop=loop)
35 self._service_config = service_config
36 self._handler = handler
37
38 async def _run(self):
39 error_count = self._handler.pop_error_count()
40 SERVICE_ERRORS.inc(error_count)