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

Commit 6691e18

Browse files
authored
[metrics] add namespace, subsystem and refactor names for Prometheus
1 parent b5cbbb3 commit 6691e18

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
@@ -1060,6 +1060,20 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
10601060
config,
10611061
default=False,
10621062
)
1063+
metrics_namespace = get_config_variable(
1064+
"CONNECTOR_METRICS_NAMESPACE",
1065+
["connector", "metrics_namespace"],
1066+
config,
1067+
False,
1068+
"",
1069+
)
1070+
metrics_subsystem = get_config_variable(
1071+
"CONNECTOR_METRICS_SUBSYSTEM",
1072+
["connector", "metrics_subsystem"],
1073+
config,
1074+
False,
1075+
"",
1076+
)
10631077
metrics_port = get_config_variable(
10641078
"CONNECTOR_METRICS_PORT",
10651079
["connector", "metrics_port"],
@@ -1100,7 +1114,11 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
11001114
# For retro compatibility
11011115

11021116
self.metric = OpenCTIMetricHandler(
1103-
self.connector_logger, expose_metrics, metrics_port
1117+
self.connector_logger,
1118+
expose_metrics,
1119+
metrics_namespace,
1120+
metrics_subsystem,
1121+
metrics_port,
11041122
)
11051123
# Register the connector in OpenCTI
11061124
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)