Skip to content
Snippets Groups Projects
Commit 89e7755e authored by Waleed Akbar's avatar Waleed Akbar
Browse files

changes in Metric Writer to Prometheus.

- start_http_server() call is move to main
- CollectorRegistory variable is removed
parent 14cc7a76
No related branches found
No related tags found
2 merge requests!294Release TeraFlowSDN 4.0,!261(CTTC) New Analytics Component
...@@ -18,7 +18,7 @@ import ast ...@@ -18,7 +18,7 @@ import ast
import time import time
import threading import threading
import logging 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_sample_types_pb2 import KpiSampleType
from common.proto.kpi_value_api_pb2 import KpiValue from common.proto.kpi_value_api_pb2 import KpiValue
...@@ -26,7 +26,6 @@ from common.proto.kpi_manager_pb2 import KpiDescriptor ...@@ -26,7 +26,6 @@ from common.proto.kpi_manager_pb2 import KpiDescriptor
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
PROM_METRICS = {} PROM_METRICS = {}
PROM_REGISTERY = CollectorRegistry()
class MetricWriterToPrometheus: class MetricWriterToPrometheus:
''' '''
...@@ -34,13 +33,7 @@ class MetricWriterToPrometheus: ...@@ -34,13 +33,7 @@ class MetricWriterToPrometheus:
cooked KPI value = KpiDescriptor (gRPC message) + KpiValue (gRPC message) cooked KPI value = KpiDescriptor (gRPC message) + KpiValue (gRPC message)
''' '''
def __init__(self): def __init__(self):
# prometheus server address and configs
self.start_prometheus_client()
pass 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): def merge_kpi_descriptor_and_kpi_value(self, kpi_descriptor, kpi_value):
# Creating a dictionary from the kpi_descriptor's attributes # Creating a dictionary from the kpi_descriptor's attributes
...@@ -71,8 +64,7 @@ class MetricWriterToPrometheus: ...@@ -71,8 +64,7 @@ class MetricWriterToPrometheus:
PROM_METRICS[metric_name] = Gauge ( PROM_METRICS[metric_name] = Gauge (
metric_name, metric_name,
cooked_kpi['kpi_description'], cooked_kpi['kpi_description'],
metric_tags, metric_tags
registry=PROM_REGISTERY
) )
LOGGER.debug("Metric is created with labels: {:}".format(metric_tags)) LOGGER.debug("Metric is created with labels: {:}".format(metric_tags))
PROM_METRICS[metric_name].labels( PROM_METRICS[metric_name].labels(
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# limitations under the License. # limitations under the License.
import logging, signal, sys, threading import logging, signal, sys, threading
from prometheus_client import start_http_server
from kpi_value_writer.service.KpiValueWriter import KpiValueWriter from kpi_value_writer.service.KpiValueWriter import KpiValueWriter
from common.Settings import get_log_level from common.Settings import get_log_level
...@@ -38,6 +39,8 @@ def main(): ...@@ -38,6 +39,8 @@ def main():
grpc_service = KpiValueWriter() grpc_service = KpiValueWriter()
grpc_service.start() grpc_service.start()
start_http_server(10808)
LOGGER.debug("Prometheus client is started on port 10808")
# Wait for Ctrl+C or termination signal # Wait for Ctrl+C or termination signal
while not terminate.wait(timeout=1.0): pass while not terminate.wait(timeout=1.0): pass
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment