Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
controller
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TFS
controller
Commits
22282375
Commit
22282375
authored
2 years ago
by
Carlos Natalino Da Silva
Browse files
Options
Downloads
Patches
Plain Diff
Improving Prometheus metrics declaration.
parent
598ccfa6
No related branches found
No related tags found
2 merge requests
!142
Release TeraFlowSDN 2.1
,
!97
Optical cybersecurity scenario
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/opticalattackdetector/service/OpticalAttackDetectorServiceServicerImpl.py
+8
-28
8 additions, 28 deletions
...ector/service/OpticalAttackDetectorServiceServicerImpl.py
with
8 additions
and
28 deletions
src/opticalattackdetector/service/OpticalAttackDetectorServiceServicerImpl.py
+
8
−
28
View file @
22282375
...
...
@@ -19,6 +19,8 @@ import random
import
grpc
import
numpy
as
np
import
redis
from
prometheus_client
import
Histogram
from
common.Constants
import
ServiceNameEnum
from
common.method_wrappers.Decorator
import
(
MetricsPool
,
MetricTypeEnum
,
safe_and_metered_rpc_method
)
...
...
@@ -36,7 +38,6 @@ from dbscanserving.client.DbscanServingClient import DbscanServingClient
from
monitoring.client.MonitoringClient
import
MonitoringClient
from
opticalattackmitigator.client.OpticalAttackMitigatorClient
import
\
OpticalAttackMitigatorClient
from
prometheus_client
import
Histogram
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -51,29 +52,11 @@ METRICS_POOL_DETAILS = MetricsPool(
},
)
metric_labels
=
dict
(
operation
=
"
detect
"
)
histogram_duration
:
Histogram
=
METRICS_POOL_DETAILS
.
get_or_create
(
METRIC_LABELS
=
dict
(
operation
=
"
detect
"
)
HISTOGRAM_DURATION
:
Histogram
=
METRICS_POOL_DETAILS
.
get_or_create
(
"
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
()
dbscanserving_client
:
DbscanServingClient
=
DbscanServingClient
()
attack_mitigator_client
:
OpticalAttackMitigatorClient
=
OpticalAttackMitigatorClient
()
...
...
@@ -197,8 +180,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
detection_sample
.
append
(
random
.
uniform
(
5000.0
,
6000.0
))
# adding the sample to the cache and recovering the cache
with
histogram_duration
.
labels
(
step
=
"
cachefetch
"
,
**
metric_labels
).
time
():
# with CACHE_RESPONSE_TIME.time():
with
HISTOGRAM_DURATION
.
labels
(
step
=
"
cachefetch
"
,
**
METRIC_LABELS
).
time
():
r
.
rpush
(
"
opm_{}
"
.
format
(
s_uuid
.
replace
(
"
-
"
,
"
_
"
)),
pickle
.
dumps
(
tuple
(
detection_sample
)),
...
...
@@ -215,8 +197,7 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
detection_sample
.
features
.
append
(
feature
)
detection_request
.
samples
.
append
(
detection_sample
)
with
histogram_duration
.
labels
(
step
=
"
uldetection
"
,
**
metric_labels
).
time
():
# with DETECTION_RESPONSE_TIME.time():
with
HISTOGRAM_DURATION
.
labels
(
step
=
"
uldetection
"
,
**
METRIC_LABELS
).
time
():
response
:
dbscan
.
DetectionResponse
=
dbscanserving_client
.
Detect
(
detection_request
)
...
...
@@ -236,15 +217,14 @@ class OpticalAttackDetectorServiceServicerImpl(OpticalAttackDetectorServiceServi
else
:
kpi
.
kpi_value
.
int32Val
=
0
with
histogram_duration
.
labels
(
step
=
"
includekpi
"
,
**
metric_labels
).
time
():
# with MONITORING_RESPONSE_TIME.time():
with
HISTOGRAM_DURATION
.
labels
(
step
=
"
includekpi
"
,
**
METRIC_LABELS
).
time
():
monitoring_client
.
IncludeKpi
(
kpi
)
# if -1 in response.cluster_indices: # attack detected
if
kpi
.
kpi_value
.
int32Val
==
-
1
:
attack
=
AttackDescription
()
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():
response
:
AttackResponse
=
attack_mitigator_client
.
NotifyAttack
(
attack
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment