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

Improving code.

parent 68a67051
Branches
Tags
2 merge requests!142Release TeraFlowSDN 2.1,!97Optical cybersecurity scenario
...@@ -83,31 +83,12 @@ LOOP_TIME = Histogram( ...@@ -83,31 +83,12 @@ LOOP_TIME = Histogram(
"tfs_opticalattackmanager_loop_seconds", "tfs_opticalattackmanager_loop_seconds",
"Time taken by each security loop", "Time taken by each security loop",
buckets=( buckets=(
1.0, 1.0, 2.5, 5.0, 7.5, 10.0, 12.5,
2.5, 15.0, 17.5, 20.0, 22.5, 25.0, 27.5,
5.0, 30.0, 32.5, 35.0, 37.5, 40.0,
7.5, 42.5, 45.0, 47.5,
10.0, 50.0, 52.5, 55.0, 57.5,
12.5, 60.0, 70.0, 80.0, 90.0, 100.0,
15.0,
17.5,
20.0,
22.5,
25.0,
27.5,
30.0,
32.5,
35.0,
37.5,
40.0,
42.5,
45.0,
47.5,
50.0,
52.5,
55.0,
57.5,
60.0,
float("inf"), float("inf"),
), ),
) )
...@@ -127,6 +108,11 @@ DESIRED_MONITORING_INTERVAL = Gauge( ...@@ -127,6 +108,11 @@ DESIRED_MONITORING_INTERVAL = Gauge(
"Desired loop monitoring interval", "Desired loop monitoring interval",
) )
DROP_COUNTER = Counter(
"tfs_opticalattackmanager_dropped_assessments",
"Dropped assessments due to detector timeout",
)
global service_list global service_list
global cache global cache
...@@ -390,6 +376,7 @@ async def monitor_services(terminate, service_list=None, cache=None): ...@@ -390,6 +376,7 @@ async def monitor_services(terminate, service_list=None, cache=None):
(i + 1) * k + min(i + 1, m), # last index (i + 1) * k + min(i + 1, m), # last index
host, host,
port, port,
DROP_COUNTER,
desired_monitoring_interval * 0.9, desired_monitoring_interval * 0.9,
) )
for i in range(cur_number_workers) for i in range(cur_number_workers)
......
...@@ -22,13 +22,7 @@ from prometheus_client import Counter ...@@ -22,13 +22,7 @@ from prometheus_client import Counter
from common.proto.asyncio.optical_attack_detector_grpc import \ from common.proto.asyncio.optical_attack_detector_grpc import \
OpticalAttackDetectorServiceStub OpticalAttackDetectorServiceStub
from common.proto.asyncio.optical_attack_detector_pb2 import DetectionRequest from common.proto.asyncio.optical_attack_detector_pb2 import DetectionRequest
from common.Settings import get_log_level, get_setting from common.Settings import get_log_level
DROP_COUNTER = Counter(
"tfs_opticalattackmanager_dropped_assessments",
"Dropped assessments due to detector timeout",
)
log_level = get_log_level() log_level = get_log_level()
logging.basicConfig(level=log_level) logging.basicConfig(level=log_level)
...@@ -41,6 +35,7 @@ async def detect_attack( ...@@ -41,6 +35,7 @@ async def detect_attack(
context_id: str, context_id: str,
service_id: str, service_id: str,
kpi_id: str, kpi_id: str,
drop_counter: Counter,
timeout: float = 20.0, timeout: float = 20.0,
) -> None: ) -> None:
try: try:
...@@ -61,7 +56,7 @@ async def detect_attack( ...@@ -61,7 +56,7 @@ async def detect_attack(
"Exception while processing service_id {}/{}".format(service_id, kpi_id) "Exception while processing service_id {}/{}".format(service_id, kpi_id)
) )
# LOGGER.exception(e) # LOGGER.exception(e)
DROP_COUNTER.inc() drop_counter.inc()
def delegate_services( def delegate_services(
...@@ -70,6 +65,7 @@ def delegate_services( ...@@ -70,6 +65,7 @@ def delegate_services(
end_index: int, end_index: int,
host: str, host: str,
port: str, port: str,
drop_counter: Counter,
monitoring_interval: float, monitoring_interval: float,
): ):
async def run_internal_loop(): async def run_internal_loop():
...@@ -81,6 +77,7 @@ def delegate_services( ...@@ -81,6 +77,7 @@ def delegate_services(
service["context"], service["context"],
service["service"], service["service"],
service["kpi"], service["kpi"],
drop_counter,
# allow at most 90% of the monitoring interval to succeed # allow at most 90% of the monitoring interval to succeed
monitoring_interval * 0.9, monitoring_interval * 0.9,
) )
......
...@@ -1380,7 +1380,7 @@ ...@@ -1380,7 +1380,7 @@
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
"drawStyle": "line", "drawStyle": "line",
"fillOpacity": 0, "fillOpacity": 29,
"gradientMode": "none", "gradientMode": "none",
"hideFrom": { "hideFrom": {
"legend": false, "legend": false,
...@@ -1397,7 +1397,7 @@ ...@@ -1397,7 +1397,7 @@
"spanNulls": false, "spanNulls": false,
"stacking": { "stacking": {
"group": "A", "group": "A",
"mode": "none" "mode": "normal"
}, },
"thresholdsStyle": { "thresholdsStyle": {
"mode": "off" "mode": "off"
...@@ -1416,7 +1416,8 @@ ...@@ -1416,7 +1416,8 @@
"value": 80 "value": 80
} }
] ]
} },
"unit": "mwatt"
}, },
"overrides": [] "overrides": []
}, },
...@@ -1445,10 +1446,71 @@ ...@@ -1445,10 +1446,71 @@
"uid": "${DS_PROMETHEUS}" "uid": "${DS_PROMETHEUS}"
}, },
"editorMode": "code", "editorMode": "code",
"expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\".+opticalattackdetector.+\"})/1000000", "exemplar": false,
"legendFormat": "Detector", "expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\".+opticalattackmanager.+\"})/1000",
"instant": false,
"legendFormat": "Manager",
"range": true, "range": true,
"refId": "A" "refId": "A"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\".+opticalattackdetector.+\"})/1000",
"hide": false,
"instant": false,
"legendFormat": "Detector",
"range": true,
"refId": "B"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\".+dbscan.+\"})/1000",
"hide": false,
"instant": false,
"interval": "",
"legendFormat": "UL Inference",
"range": true,
"refId": "C"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\"redis-server.+\"})/1000",
"hide": false,
"instant": false,
"interval": "",
"legendFormat": "Cache",
"range": true,
"refId": "D"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"exemplar": false,
"expr": "sum(scaph_process_power_consumption_microwatts{namespace=\"tfs\", cmdline=~\".+opticalattackmitigator.+\"})/1000",
"hide": false,
"instant": false,
"interval": "",
"legendFormat": "Mitigator",
"range": true,
"refId": "E"
} }
], ],
"title": "Energy consumption", "title": "Energy consumption",
...@@ -1463,7 +1525,7 @@ ...@@ -1463,7 +1525,7 @@
"list": [] "list": []
}, },
"time": { "time": {
"from": "now-15m", "from": "now-5m",
"to": "now" "to": "now"
}, },
"timepicker": {}, "timepicker": {},
......
...@@ -32,7 +32,7 @@ v1 = client.CoreV1Api() ...@@ -32,7 +32,7 @@ v1 = client.CoreV1Api()
caching_pod = None caching_pod = None
pods = v1.list_namespaced_pod(namespace=namespace) pods = v1.list_namespaced_pod(namespace=namespace)
for pod in pods.items: for pod in pods.items:
print(pod.metadata) # print(pod.metadata)
if "app" in pod.metadata.labels and "caching" in pod.metadata.labels["app"]: if "app" in pod.metadata.labels and "caching" in pod.metadata.labels["app"]:
caching_pod = pod caching_pod = pod
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment