88from datadog_checks .n8n .metrics import METRIC_MAP
99
1010DEFAULT_READY_ENDPOINT = '/healthz/readiness'
11- DEFAULT_HEALTH_ENDPOINT = '/healthz'
1211DEFAULT_VERSION_ENDPOINT = '/rest/settings'
1312
1413
@@ -25,7 +24,6 @@ def __init__(self, name, init_config, instances=None):
2524 self .openmetrics_endpoint = self .instance ["openmetrics_endpoint" ]
2625 self .tags = self .instance .get ('tags' , [])
2726 self ._ready_endpoint = DEFAULT_READY_ENDPOINT
28- self ._health_endpoint = DEFAULT_HEALTH_ENDPOINT
2927 self ._version_endpoint = DEFAULT_VERSION_ENDPOINT
3028 # Get the N8N API port if specified, otherwise use the default 5678.
3129 self .server_port = str (self .instance .get ('server_port' , 5678 ))
@@ -69,33 +67,20 @@ def _submit_version_metadata(self):
6967 except Exception as e :
7068 self .log .debug ("Error retrieving version metadata: %s" , e )
7169
72- def _check_n8n_health (self ):
73- endpoint = urljoin (self .openmetrics_endpoint , self ._health_endpoint )
74- response = self .http .get (endpoint )
75-
76- # Any 4xx or 5xx response from the API endpoint (/healthz) means the n8n process is not responding
77- if 400 <= response .status_code and response .status_code < 600 :
78- self .service_check ('health.status' , AgentCheck .CRITICAL , self .tags )
79- if response .status_code == 200 :
80- self .service_check ('health.status' , AgentCheck .OK , self .tags )
81- else :
82- self .service_check ('health.status' , AgentCheck .UNKNOWN , self .tags )
83-
8470 def _check_n8n_readiness (self ):
8571 endpoint = urljoin (self .openmetrics_endpoint , self ._ready_endpoint )
8672 response = self .http .get (endpoint )
8773
88- # Any 4xx or 5xx response from the API endpoint (/healthz/readiness)
89- # means the n8n Database is not ready to accept requests
90- if 400 <= response .status_code and response .status_code < 600 :
91- self .service_check ('health.status' , AgentCheck .CRITICAL , self .tags )
92- if response .status_code == 200 :
93- self .service_check ('health.status' , AgentCheck .OK , self .tags )
74+ # Check if status_code is available
75+ if response .status_code is None :
76+ self .log .warning ("The readiness endpoint did not return a status code" )
9477 else :
95- self .service_check ('health.status' , AgentCheck .UNKNOWN , self .tags )
78+ metric_tags = self .tags + [f'status_code:{ response .status_code } ' ]
79+
80+ # Submit metric with value 1 and status_code as tag
81+ self .gauge ('readiness.check' , 1 , tags = metric_tags )
9682
9783 def check (self , instance ):
9884 super ().check (instance )
9985 self ._submit_version_metadata ()
100- self ._check_n8n_health ()
10186 self ._check_n8n_readiness ()
0 commit comments