feat(gateway): add write/active-read/error metrics
This commit is contained in:
@@ -156,3 +156,38 @@ NOTIFICATIONS_SENT = Counter(
|
|||||||
'Total number of notifications sent',
|
'Total number of notifications sent',
|
||||||
NOTIFICATION_LABELS,
|
NOTIFICATION_LABELS,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# --- Gateway: Write metrics ---
|
||||||
|
OPC_WRITE_TOTAL = Counter(
|
||||||
|
'opc_write_total', 'OPC active write attempts',
|
||||||
|
['pod_id', 'server_name', 'model_id', 'result'], # result: success|error
|
||||||
|
)
|
||||||
|
OPC_WRITE_LATENCY = Histogram(
|
||||||
|
'opc_write_latency_seconds', 'OPC active write latency', ['pod_id', 'server_name'],
|
||||||
|
)
|
||||||
|
OPC_WRITE_STATUS_BY_MODEL = Gauge(
|
||||||
|
'opc_write_status_by_model', 'Last write status per model (1=ok,0=error)',
|
||||||
|
['pod_id', 'model_id', 'status'],
|
||||||
|
)
|
||||||
|
# --- Gateway: Active read metrics ---
|
||||||
|
OPC_ACTIVE_READ_TOTAL = Counter(
|
||||||
|
'opc_active_read_total', 'OPC active read attempts',
|
||||||
|
['pod_id', 'server_name', 'result'],
|
||||||
|
)
|
||||||
|
OPC_ACTIVE_READ_LATENCY = Histogram(
|
||||||
|
'opc_active_read_latency_seconds', 'OPC active read latency', ['pod_id', 'server_name'],
|
||||||
|
)
|
||||||
|
OPC_READ_LAG = Gauge(
|
||||||
|
'opc_read_lag_seconds', 'Lag between OPC source timestamp and machine time',
|
||||||
|
['pod_id', 'server_name'],
|
||||||
|
)
|
||||||
|
OPC_TAG_VALUE = Gauge(
|
||||||
|
'opc_tag_value', 'Last value read per tag/model', ['pod_id', 'tag_name', 'model_id'],
|
||||||
|
)
|
||||||
|
# --- Gateway: connection/error metrics ---
|
||||||
|
OPC_DISCONNECTIONS_TOTAL = Counter(
|
||||||
|
'opc_disconnections_total', 'OPC disconnections', ['pod_id', 'server_name'],
|
||||||
|
)
|
||||||
|
OPC_ERROR_BY_TYPE = Counter(
|
||||||
|
'opc_error_by_type_total', 'OPC errors by type', ['pod_id', 'server_name', 'error_type'],
|
||||||
|
)
|
||||||
|
|||||||
@@ -213,3 +213,16 @@ def test_notifications_sent():
|
|||||||
assert isinstance(metrics.NOTIFICATIONS_SENT, Counter)
|
assert isinstance(metrics.NOTIFICATIONS_SENT, Counter)
|
||||||
assert metrics.NOTIFICATIONS_SENT._name == 'notifications_sent' # REMOVED _total
|
assert metrics.NOTIFICATIONS_SENT._name == 'notifications_sent' # REMOVED _total
|
||||||
assert set(metrics.NOTIFICATIONS_SENT._labelnames) == {'pod_id', 'level', 'block'}
|
assert set(metrics.NOTIFICATIONS_SENT._labelnames) == {'pod_id', 'level', 'block'}
|
||||||
|
|
||||||
|
|
||||||
|
def test_gateway_metrics_exist():
|
||||||
|
"""Verify the new OPC Gateway metrics (write, active read, error) are defined."""
|
||||||
|
metrics.OPC_WRITE_TOTAL.labels(pod_id='p', server_name='s', model_id='1', result='success')
|
||||||
|
metrics.OPC_WRITE_LATENCY.labels(pod_id='p', server_name='s')
|
||||||
|
metrics.OPC_ACTIVE_READ_TOTAL.labels(pod_id='p', server_name='s', result='success')
|
||||||
|
metrics.OPC_ACTIVE_READ_LATENCY.labels(pod_id='p', server_name='s')
|
||||||
|
metrics.OPC_WRITE_STATUS_BY_MODEL.labels(pod_id='p', model_id='1', status='ok')
|
||||||
|
metrics.OPC_TAG_VALUE.labels(pod_id='p', tag_name='t', model_id='1')
|
||||||
|
metrics.OPC_READ_LAG.labels(pod_id='p', server_name='s')
|
||||||
|
metrics.OPC_ERROR_BY_TYPE.labels(pod_id='p', server_name='s', error_type='BadTimeout')
|
||||||
|
metrics.OPC_DISCONNECTIONS_TOTAL.labels(pod_id='p', server_name='s')
|
||||||
|
|||||||
Reference in New Issue
Block a user