Loading src/kpi_value_writer/service/MetricWriterToPrometheus.py +2 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ import ast import time import threading import logging from prometheus_client import start_http_server, Gauge, CollectorRegistry from prometheus_client import Gauge, CollectorRegistry from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.proto.kpi_value_api_pb2 import KpiValue Loading @@ -26,7 +26,6 @@ from common.proto.kpi_manager_pb2 import KpiDescriptor LOGGER = logging.getLogger(__name__) PROM_METRICS = {} PROM_REGISTERY = CollectorRegistry() class MetricWriterToPrometheus: ''' Loading @@ -34,14 +33,8 @@ class MetricWriterToPrometheus: cooked KPI value = KpiDescriptor (gRPC message) + KpiValue (gRPC message) ''' def __init__(self): # prometheus server address and configs self.start_prometheus_client() pass def start_prometheus_client(self): start_http_server(10808, registry=PROM_REGISTERY) LOGGER.debug("Prometheus client is started on port 10808") def merge_kpi_descriptor_and_kpi_value(self, kpi_descriptor, kpi_value): # Creating a dictionary from the kpi_descriptor's attributes cooked_kpi = { Loading Loading @@ -71,8 +64,7 @@ class MetricWriterToPrometheus: PROM_METRICS[metric_name] = Gauge ( metric_name, cooked_kpi['kpi_description'], metric_tags, registry=PROM_REGISTERY metric_tags ) LOGGER.debug("Metric is created with labels: {:}".format(metric_tags)) PROM_METRICS[metric_name].labels( Loading src/kpi_value_writer/service/__main__.py +3 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import logging, signal, sys, threading from prometheus_client import start_http_server from kpi_value_writer.service.KpiValueWriter import KpiValueWriter from common.Settings import get_log_level Loading @@ -38,6 +39,8 @@ def main(): grpc_service = KpiValueWriter() grpc_service.start() start_http_server(10808) LOGGER.debug("Prometheus client is started on port 10808") # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=1.0): pass Loading Loading
src/kpi_value_writer/service/MetricWriterToPrometheus.py +2 −10 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ import ast import time import threading import logging from prometheus_client import start_http_server, Gauge, CollectorRegistry from prometheus_client import Gauge, CollectorRegistry from common.proto.kpi_sample_types_pb2 import KpiSampleType from common.proto.kpi_value_api_pb2 import KpiValue Loading @@ -26,7 +26,6 @@ from common.proto.kpi_manager_pb2 import KpiDescriptor LOGGER = logging.getLogger(__name__) PROM_METRICS = {} PROM_REGISTERY = CollectorRegistry() class MetricWriterToPrometheus: ''' Loading @@ -34,14 +33,8 @@ class MetricWriterToPrometheus: cooked KPI value = KpiDescriptor (gRPC message) + KpiValue (gRPC message) ''' def __init__(self): # prometheus server address and configs self.start_prometheus_client() pass def start_prometheus_client(self): start_http_server(10808, registry=PROM_REGISTERY) LOGGER.debug("Prometheus client is started on port 10808") def merge_kpi_descriptor_and_kpi_value(self, kpi_descriptor, kpi_value): # Creating a dictionary from the kpi_descriptor's attributes cooked_kpi = { Loading Loading @@ -71,8 +64,7 @@ class MetricWriterToPrometheus: PROM_METRICS[metric_name] = Gauge ( metric_name, cooked_kpi['kpi_description'], metric_tags, registry=PROM_REGISTERY metric_tags ) LOGGER.debug("Metric is created with labels: {:}".format(metric_tags)) PROM_METRICS[metric_name].labels( Loading
src/kpi_value_writer/service/__main__.py +3 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,7 @@ # limitations under the License. import logging, signal, sys, threading from prometheus_client import start_http_server from kpi_value_writer.service.KpiValueWriter import KpiValueWriter from common.Settings import get_log_level Loading @@ -38,6 +39,8 @@ def main(): grpc_service = KpiValueWriter() grpc_service.start() start_http_server(10808) LOGGER.debug("Prometheus client is started on port 10808") # Wait for Ctrl+C or termination signal while not terminate.wait(timeout=1.0): pass Loading