-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This will allow monitoring the execution of the code.
- Loading branch information
Showing
6 changed files
with
120 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ __pycache__/ | |
/index.html | ||
/details.html | ||
/ipv6-in-real-life.json | ||
/metrics.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# SPDX-FileCopyrightText: 2023 Diego Elio Pettenò | ||
# | ||
# SPDX-License-Identifier: 0BSD | ||
|
||
import enum | ||
import pathlib | ||
import time | ||
from typing import Optional | ||
|
||
import prometheus_client | ||
|
||
|
||
class LoadStatus(enum.Enum): | ||
NOT_STARTED = "not_started" | ||
COMPLETED = "completed" | ||
FAILED = "failed" | ||
|
||
|
||
class Metrics: | ||
_SINGLETON: Optional["Metrics"] = None | ||
|
||
@classmethod | ||
def get(cls) -> "Metrics": | ||
if cls._SINGLETON is None: | ||
cls._SINGLETON = Metrics() | ||
|
||
return cls._SINGLETON | ||
|
||
def __init__(self): | ||
self._registry = prometheus_client.CollectorRegistry() | ||
|
||
self._run_timestamp = prometheus_client.Gauge( | ||
"last_run_timestamp", | ||
"Unix Timestamp of the last generation.", | ||
unit="seconds", | ||
registry=self._registry, | ||
) | ||
self._run_timestamp.set(time.time()) | ||
|
||
self._source_loaded = prometheus_client.Enum( | ||
"source_load_status", | ||
"Status of the loading of data source.", | ||
registry=self._registry, | ||
states=[e.value for e in LoadStatus], | ||
) | ||
self.set_source_loaded(LoadStatus.NOT_STARTED) | ||
|
||
self._ipv4_resolution_successes = prometheus_client.Counter( | ||
"ipv4_resolution_successes", | ||
"Number of resolution successes when resolving A records", | ||
registry=self._registry, | ||
) | ||
|
||
self._ipv4_resolution_failures = prometheus_client.Counter( | ||
"ipv4_resolution_failures", | ||
"Number of resolution failures when resolving A records", | ||
registry=self._registry, | ||
) | ||
|
||
self._ipv6_resolution_successes = prometheus_client.Counter( | ||
"ipv6_resolution_successes", | ||
"Number of resolution successes when resolving AAAA records", | ||
registry=self._registry, | ||
) | ||
|
||
self._ipv6_resolution_failures = prometheus_client.Counter( | ||
"ipv6_resolution_failures", | ||
"Number of resolution failures when resolving AAAA records", | ||
registry=self._registry, | ||
) | ||
|
||
def set_source_loaded(self, state: LoadStatus) -> None: | ||
self._source_loaded.state(state.value) | ||
|
||
def count_ipv4_resolution_success(self) -> None: | ||
self._ipv4_resolution_successes.inc() | ||
|
||
def count_ipv4_resolution_failure(self) -> None: | ||
self._ipv4_resolution_failures.inc() | ||
|
||
def count_ipv6_resolution_success(self) -> None: | ||
self._ipv6_resolution_successes.inc() | ||
|
||
def count_ipv6_resolution_failure(self) -> None: | ||
self._ipv6_resolution_failures.inc() | ||
|
||
def write_out(self, output: pathlib.Path) -> None: | ||
prometheus_client.write_to_textfile(str(output), self._registry) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ click_log | |
cmarkgfm | ||
jinja2 | ||
pycountry | ||
prometheus-client |