Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Commit 94bf38c

Browse files
committed
[metrics] add namespace, subsystem and refactor names
1 parent 1e227fd commit 94bf38c

File tree

2 files changed

+63
-16
lines changed

2 files changed

+63
-16
lines changed

pycti/connector/opencti_connector_helper.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,20 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
912912
False,
913913
False,
914914
)
915+
metrics_namespace = get_config_variable(
916+
"CONNECTOR_METRICS_NAMESPACE",
917+
["connector", "metrics_namespace"],
918+
config,
919+
False,
920+
"",
921+
)
922+
metrics_subsystem = get_config_variable(
923+
"CONNECTOR_METRICS_SUBSYSTEM",
924+
["connector", "metrics_subsystem"],
925+
config,
926+
False,
927+
"",
928+
)
915929
metrics_port = get_config_variable(
916930
"CONNECTOR_METRICS_PORT", ["connector", "metrics_port"], config, True, 9095
917931
)
@@ -946,7 +960,11 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
946960
# For retro compatibility
947961

948962
self.metric = OpenCTIMetricHandler(
949-
self.connector_logger, expose_metrics, metrics_port
963+
self.connector_logger,
964+
expose_metrics,
965+
metrics_namespace,
966+
metrics_subsystem,
967+
metrics_port,
950968
)
951969
# Register the connector in OpenCTI
952970
self.connector = OpenCTIConnector(

pycti/connector/opencti_metric_handler.py

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44

55

66
class OpenCTIMetricHandler:
7-
def __init__(self, connector_logger, activated: bool = False, port: int = 9095):
7+
def __init__(
8+
self,
9+
connector_logger,
10+
activated: bool = False,
11+
namespace: str = "",
12+
subsystem: str = "",
13+
port: int = 9095,
14+
):
815
"""
916
Init of OpenCTIMetricHandler class.
1017
1118
Parameters
1219
----------
1320
activated : bool, default False
1421
If True use metrics in client and connectors.
22+
namespace: str, default empty
23+
Namespace for the prometheus metrics.
24+
subsystem: str, default empty
25+
Subsystem for the prometheus metrics.
1526
port : int, default 9095
1627
Port for prometheus server.
1728
"""
@@ -22,35 +33,53 @@ def __init__(self, connector_logger, activated: bool = False, port: int = 9095):
2233
start_http_server(port)
2334
self._metrics = {
2435
"bundle_send": Counter(
25-
"bundle_send",
26-
"Number of bundle send",
36+
"bundles_sent_total",
37+
"Number of bundles sent",
38+
namespace=namespace,
39+
subsystem=subsystem,
2740
),
2841
"record_send": Counter(
29-
"record_send",
30-
"Number of record (objects per bundle) send",
42+
"records_sent_total",
43+
"Number of records (objects per bundle) sent",
44+
namespace=namespace,
45+
subsystem=subsystem,
3146
),
3247
"run_count": Counter(
33-
"run_count",
48+
"runs_total",
3449
"Number of run",
50+
namespace=namespace,
51+
subsystem=subsystem,
3552
),
3653
"ping_api_count": Counter(
37-
"ping_api_count",
38-
"Number of ping to the api",
54+
"ping_api_total",
55+
"Number of pings to the API",
56+
namespace=namespace,
57+
subsystem=subsystem,
3958
),
4059
"ping_api_error": Counter(
41-
"ping_api_error",
42-
"Number of error when pinging the api",
60+
"ping_api_errors_total",
61+
"Number of errors when pinging the API",
62+
namespace=namespace,
63+
subsystem=subsystem,
4364
),
4465
"error_count": Counter(
45-
"error_count",
46-
"Number of error",
66+
"errors_total",
67+
"Number of errors",
68+
namespace=namespace,
69+
subsystem=subsystem,
4770
),
4871
"client_error_count": Counter(
49-
"client_error_count",
50-
"Number of client error",
72+
"client_errors_total",
73+
"Number of client errors",
74+
namespace=namespace,
75+
subsystem=subsystem,
5176
),
5277
"state": Enum(
53-
"state", "State of connector", states=["idle", "running", "stopped"]
78+
"state",
79+
"State of connector",
80+
states=["idle", "running", "stopped"],
81+
namespace=namespace,
82+
subsystem=subsystem,
5483
),
5584
}
5685

0 commit comments

Comments
 (0)