Skip to content
Snippets Groups Projects
Commit 22282375 authored by Carlos Natalino Da Silva's avatar Carlos Natalino Da Silva
Browse files

Improving Prometheus metrics declaration.

parent 598ccfa6
No related branches found
No related tags found
2 merge requests!142Release TeraFlowSDN 2.1,!97Optical cybersecurity scenario
...@@ -19,6 +19,8 @@ import random ...@@ -19,6 +19,8 @@ import random
import grpc import grpc
import numpy as np import numpy as np
import redis import redis
from prometheus_client import Histogram
from common.Constants import ServiceNameEnum from common.Constants import ServiceNameEnum
from common.method_wrappers.Decorator import (MetricsPool, MetricTypeEnum, from common.method_wrappers.Decorator import (MetricsPool, MetricTypeEnum,
safe_and_metered_rpc_method) safe_and_metered_rpc_method)
...@@ -36,7 +38,6 @@ from dbscanserving.client.DbscanServingClient import DbscanServingClient ...@@ -36,7 +38,6 @@ from dbscanserving.client.DbscanServingClient import DbscanServingClient
from monitoring.client.MonitoringClient import MonitoringClient from monitoring.client.MonitoringClient import MonitoringClient
from opticalattackmitigator.client.OpticalAttackMitigatorClient import \ from opticalattackmitigator.client.OpticalAttackMitigatorClient import \
OpticalAttackMitigatorClient OpticalAttackMitigatorClient
from prometheus_client import Histogram
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
...@@ -51,29 +52,11 @@ METRICS_POOL_DETAILS = MetricsPool( ...@@ -51,29 +52,11 @@ METRICS_POOL_DETAILS = MetricsPool(
}, },
) )
METRIC_LABELS = dict(operation="detect")
metric_labels = dict(operation="detect") HISTOGRAM_DURATION: Histogram = METRICS_POOL_DETAILS.get_or_create(
histogram_duration: Histogram = METRICS_POOL_DETAILS.get_or_create(
"details", MetricTypeEnum.HISTOGRAM_DURATION "details", MetricTypeEnum.HISTOGRAM_DURATION
) )
DETECTION_RESPONSE_TIME = Histogram(
"tfs_opticalattackdetector_inference_response_time",
"Time taken by the inference component to reply",
)
MONITORING_RESPONSE_TIME = Histogram(
"tfs_opticalattackdetector_monitoring_response_time",
"Time taken by the monitoring component to reply",
)
MITIGATION_RESPONSE_TIME = Histogram(
"tfs_opticalattackdetector_mitigation_response_time",
"Time taken by the attack mitigator to reply",
)
CACHE_RESPONSE_TIME = Histogram(
"tfs_opticalattackdetector_cache_response_time", "Time taken by the cache to reply"
)
monitoring_client: MonitoringClient = MonitoringClient() monitoring_client: MonitoringClient = MonitoringClient()
dbscanserving_client: DbscanServingClient = DbscanServingClient() dbscanserving_client: DbscanServingClient = DbscanServingClient()
attack_mitigator_client: OpticalAttackMitigatorClient = OpticalAttackMitigatorClient() attack_mitigator_client: OpticalAttackMitigatorClient = OpticalAttackMitigatorClient()
...@@ -197,8 +180,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi ...@@ -197,8 +180,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
detection_sample.append(random.uniform(5000.0, 6000.0)) detection_sample.append(random.uniform(5000.0, 6000.0))
# adding the sample to the cache and recovering the cache # adding the sample to the cache and recovering the cache
with histogram_duration.labels(step="cachefetch", **metric_labels).time(): with HISTOGRAM_DURATION.labels(step="cachefetch", **METRIC_LABELS).time():
# with CACHE_RESPONSE_TIME.time():
r.rpush( r.rpush(
"opm_{}".format(s_uuid.replace("-", "_")), "opm_{}".format(s_uuid.replace("-", "_")),
pickle.dumps(tuple(detection_sample)), pickle.dumps(tuple(detection_sample)),
...@@ -215,8 +197,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi ...@@ -215,8 +197,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
detection_sample.features.append(feature) detection_sample.features.append(feature)
detection_request.samples.append(detection_sample) detection_request.samples.append(detection_sample)
with histogram_duration.labels(step="uldetection", **metric_labels).time(): with HISTOGRAM_DURATION.labels(step="uldetection", **METRIC_LABELS).time():
# with DETECTION_RESPONSE_TIME.time():
response: dbscan.DetectionResponse = dbscanserving_client.Detect( response: dbscan.DetectionResponse = dbscanserving_client.Detect(
detection_request detection_request
) )
...@@ -236,15 +217,14 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi ...@@ -236,15 +217,14 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
else: else:
kpi.kpi_value.int32Val = 0 kpi.kpi_value.int32Val = 0
with histogram_duration.labels(step="includekpi", **metric_labels).time(): with HISTOGRAM_DURATION.labels(step="includekpi", **METRIC_LABELS).time():
# with MONITORING_RESPONSE_TIME.time():
monitoring_client.IncludeKpi(kpi) monitoring_client.IncludeKpi(kpi)
# if -1 in response.cluster_indices: # attack detected # if -1 in response.cluster_indices: # attack detected
if kpi.kpi_value.int32Val == -1: if kpi.kpi_value.int32Val == -1:
attack = AttackDescription() attack = AttackDescription()
attack.cs_id.uuid = request.service_id.service_uuid.uuid attack.cs_id.uuid = request.service_id.service_uuid.uuid
with histogram_duration.labels(step="mitigation", **metric_labels).time(): with HISTOGRAM_DURATION.labels(step="mitigation", **METRIC_LABELS).time():
# with MITIGATION_RESPONSE_TIME.time(): # with MITIGATION_RESPONSE_TIME.time():
response: AttackResponse = attack_mitigator_client.NotifyAttack(attack) response: AttackResponse = attack_mitigator_client.NotifyAttack(attack)
......
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