pycti.connector.opencti_metric_handler ====================================== .. py:module:: pycti.connector.opencti_metric_handler .. autoapi-nested-parse:: OpenCTI Metric Handler module. This module provides Prometheus metrics support for OpenCTI connectors, allowing monitoring of connector performance and health. Classes ------- .. autoapisummary:: pycti.connector.opencti_metric_handler.OpenCTIMetricHandler Module Contents --------------- .. py:class:: OpenCTIMetricHandler(connector_logger, activated: bool = False, namespace: str = '', subsystem: str = '', port: int = 9095) Handler for Prometheus metrics in OpenCTI connectors. This class manages Prometheus metrics for monitoring connector behavior, including bundle sends, records processed, run counts, API pings, and errors. When activated, it starts an HTTP server to expose metrics for scraping by Prometheus or compatible monitoring systems. :param connector_logger: Logger instance for the connector :type connector_logger: logging.Logger :param activated: Whether to enable metrics collection and exposure :type activated: bool :param namespace: Prometheus metrics namespace prefix :type namespace: str :param subsystem: Prometheus metrics subsystem prefix :type subsystem: str :param port: Port number for the Prometheus HTTP server :type port: int .. rubric:: Example >>> handler = OpenCTIMetricHandler( ... connector_logger=logger, ... activated=True, ... namespace="opencti", ... subsystem="connector", ... port=9095 ... ) >>> handler.inc("bundle_send") >>> handler.state("running") Initialize the OpenCTIMetricHandler instance. :param connector_logger: Logger instance for the connector :type connector_logger: logging.Logger :param activated: Whether to enable metrics (default: False) :type activated: bool :param namespace: Prometheus metrics namespace prefix (default: "") :type namespace: str :param subsystem: Prometheus metrics subsystem prefix (default: "") :type subsystem: str :param port: Port for Prometheus HTTP server (default: 9095) :type port: int .. py:attribute:: activated :value: False .. py:attribute:: connector_logger .. py:method:: inc(name: str, n: int = 1) -> None Increment a counter metric by a specified amount. Increments the named counter metric. If metrics are not activated or the metric does not exist, this method does nothing. Available counter metrics: - bundle_send: Number of bundles sent - record_send: Number of records sent - run_count: Number of connector runs - ping_api_count: Number of API pings - ping_api_error: Number of API ping errors - error_count: Total number of errors - client_error_count: Number of client errors :param name: Name of the counter metric to increment :type name: str :param n: Amount to increment the counter by (default: 1) :type n: int .. rubric:: Example >>> handler.inc("bundle_send") >>> handler.inc("record_send", 10) .. py:method:: state(state: str, name: str = 'state') -> None Set the state of an Enum metric. Updates the named Enum metric to the specified state value. If metrics are not activated or the metric does not exist, this method does nothing. Available states for the default "state" metric: - idle: Connector is idle - running: Connector is running - stopped: Connector is stopped :param state: State value to set (must be a valid state for the metric) :type state: str :param name: Name of the Enum metric to update (default: "state") :type name: str .. rubric:: Example >>> handler.state("running") >>> handler.state("idle", "state")