1
- # (C) Datadog, Inc. 2010-2017
1
+ # (C) Datadog, Inc. 2018
2
2
# All rights reserved
3
- # Licensed under Simplified BSD License (see LICENSE)
3
+ # Licensed under a 3-clause BSD style license (see LICENSE)
4
4
5
5
6
6
'''
40
40
from simplejson import JSONDecodeError
41
41
42
42
# Project
43
- from checks import AgentCheck
43
+ from datadog_checks . checks import AgentCheck
44
44
45
45
# Service check names
46
46
JMX_SERVICE_CHECK = 'hdfs.namenode.jmx.can_connect'
59
59
60
60
# HDFS metrics
61
61
HDFS_NAME_SYSTEM_STATE_METRICS = {
62
- 'CapacityTotal' : ('hdfs.namenode.capacity_total' , GAUGE ),
63
- 'CapacityUsed' : ('hdfs.namenode.capacity_used' , GAUGE ),
64
- 'CapacityRemaining' : ('hdfs.namenode.capacity_remaining' , GAUGE ),
65
- 'TotalLoad' : ('hdfs.namenode.total_load' , GAUGE ),
66
- 'FsLockQueueLength' : ('hdfs.namenode.fs_lock_queue_length' , GAUGE ),
67
- 'BlocksTotal' : ('hdfs.namenode.blocks_total' , GAUGE ),
68
- 'MaxObjects' : ('hdfs.namenode.max_objects' , GAUGE ),
69
- 'FilesTotal' : ('hdfs.namenode.files_total' , GAUGE ),
70
- 'PendingReplicationBlocks' : ('hdfs.namenode.pending_replication_blocks' , GAUGE ),
71
- 'UnderReplicatedBlocks' : ('hdfs.namenode.under_replicated_blocks' , GAUGE ),
72
- 'ScheduledReplicationBlocks' : ('hdfs.namenode.scheduled_replication_blocks' , GAUGE ),
73
- 'PendingDeletionBlocks' : ('hdfs.namenode.pending_deletion_blocks' , GAUGE ),
74
- 'NumLiveDataNodes' : ('hdfs.namenode.num_live_data_nodes' , GAUGE ),
75
- 'NumDeadDataNodes' : ('hdfs.namenode.num_dead_data_nodes' , GAUGE ),
76
- 'NumDecomLiveDataNodes' : ('hdfs.namenode.num_decom_live_data_nodes' , GAUGE ),
77
- 'NumDecomDeadDataNodes' : ('hdfs.namenode.num_decom_dead_data_nodes' , GAUGE ),
78
- 'VolumeFailuresTotal' : ('hdfs.namenode.volume_failures_total' , GAUGE ),
79
- 'EstimatedCapacityLostTotal' : ('hdfs.namenode.estimated_capacity_lost_total' , GAUGE ),
80
- 'NumDecommissioningDataNodes' : ('hdfs.namenode.num_decommissioning_data_nodes' , GAUGE ),
81
- 'NumStaleDataNodes' : ('hdfs.namenode.num_stale_data_nodes' , GAUGE ),
82
- 'NumStaleStorages' : ('hdfs.namenode.num_stale_storages' , GAUGE ),
62
+ 'CapacityTotal' : ('hdfs.namenode.capacity_total' , GAUGE ),
63
+ 'CapacityUsed' : ('hdfs.namenode.capacity_used' , GAUGE ),
64
+ 'CapacityRemaining' : ('hdfs.namenode.capacity_remaining' , GAUGE ),
65
+ 'TotalLoad' : ('hdfs.namenode.total_load' , GAUGE ),
66
+ 'FsLockQueueLength' : ('hdfs.namenode.fs_lock_queue_length' , GAUGE ),
67
+ 'BlocksTotal' : ('hdfs.namenode.blocks_total' , GAUGE ),
68
+ 'MaxObjects' : ('hdfs.namenode.max_objects' , GAUGE ),
69
+ 'FilesTotal' : ('hdfs.namenode.files_total' , GAUGE ),
70
+ 'PendingReplicationBlocks' : ('hdfs.namenode.pending_replication_blocks' , GAUGE ),
71
+ 'UnderReplicatedBlocks' : ('hdfs.namenode.under_replicated_blocks' , GAUGE ),
72
+ 'ScheduledReplicationBlocks' : ('hdfs.namenode.scheduled_replication_blocks' , GAUGE ),
73
+ 'PendingDeletionBlocks' : ('hdfs.namenode.pending_deletion_blocks' , GAUGE ),
74
+ 'NumLiveDataNodes' : ('hdfs.namenode.num_live_data_nodes' , GAUGE ),
75
+ 'NumDeadDataNodes' : ('hdfs.namenode.num_dead_data_nodes' , GAUGE ),
76
+ 'NumDecomLiveDataNodes' : ('hdfs.namenode.num_decom_live_data_nodes' , GAUGE ),
77
+ 'NumDecomDeadDataNodes' : ('hdfs.namenode.num_decom_dead_data_nodes' , GAUGE ),
78
+ 'VolumeFailuresTotal' : ('hdfs.namenode.volume_failures_total' , GAUGE ),
79
+ 'EstimatedCapacityLostTotal' : ('hdfs.namenode.estimated_capacity_lost_total' , GAUGE ),
80
+ 'NumDecommissioningDataNodes' : ('hdfs.namenode.num_decommissioning_data_nodes' , GAUGE ),
81
+ 'NumStaleDataNodes' : ('hdfs.namenode.num_stale_data_nodes' , GAUGE ),
82
+ 'NumStaleStorages' : ('hdfs.namenode.num_stale_storages' , GAUGE ),
83
83
}
84
84
85
85
HDFS_NAME_SYSTEM_METRICS = {
86
- 'MissingBlocks' : ('hdfs.namenode.missing_blocks' , GAUGE ),
87
- 'CorruptBlocks' : ('hdfs.namenode.corrupt_blocks' , GAUGE )
86
+ 'MissingBlocks' : ('hdfs.namenode.missing_blocks' , GAUGE ),
87
+ 'CorruptBlocks' : ('hdfs.namenode.corrupt_blocks' , GAUGE )
88
88
}
89
89
90
+
90
91
class HDFSNameNode (AgentCheck ):
91
92
92
93
def check (self , instance ):
@@ -100,26 +101,21 @@ def check(self, instance):
100
101
tags = list (set (tags ))
101
102
102
103
# Get metrics from JMX
103
- self ._hdfs_namenode_metrics (jmx_address , disable_ssl_validation ,
104
- HDFS_NAME_SYSTEM_STATE_BEAN ,
105
- HDFS_NAME_SYSTEM_STATE_METRICS , tags )
104
+ self ._hdfs_namenode_metrics (jmx_address , disable_ssl_validation , HDFS_NAME_SYSTEM_STATE_BEAN ,
105
+ HDFS_NAME_SYSTEM_STATE_METRICS , tags )
106
106
107
- self ._hdfs_namenode_metrics (jmx_address , disable_ssl_validation ,
108
- HDFS_NAME_SYSTEM_BEAN ,
109
- HDFS_NAME_SYSTEM_METRICS , tags )
107
+ self ._hdfs_namenode_metrics (jmx_address , disable_ssl_validation , HDFS_NAME_SYSTEM_BEAN ,
108
+ HDFS_NAME_SYSTEM_METRICS , tags )
110
109
111
- self .service_check (JMX_SERVICE_CHECK ,
112
- AgentCheck .OK ,
113
- tags = tags ,
114
- message = 'Connection to %s was successful' % jmx_address )
110
+ self .service_check (JMX_SERVICE_CHECK , AgentCheck .OK , tags = tags ,
111
+ message = 'Connection to %s was successful' % jmx_address )
115
112
116
113
def _hdfs_namenode_metrics (self , jmx_uri , disable_ssl_validation , bean_name , metrics , tags ):
117
114
'''
118
115
Get HDFS namenode metrics from JMX
119
116
'''
120
- response = self ._rest_request_to_json (jmx_uri , disable_ssl_validation ,
121
- JMX_PATH ,
122
- query_params = {'qry' :bean_name }, tags = tags )
117
+ response = self ._rest_request_to_json (jmx_uri , disable_ssl_validation , JMX_PATH ,
118
+ query_params = {'qry' : bean_name }, tags = tags )
123
119
124
120
beans = response .get ('beans' , [])
125
121
@@ -169,38 +165,30 @@ def _rest_request_to_json(self, address, disable_ssl_validation, object_path, qu
169
165
self .log .debug ('Attempting to connect to "%s"' % url )
170
166
171
167
try :
172
- response = requests .get (url , timeout = self .default_integration_http_timeout , verify = not disable_ssl_validation )
168
+ response = requests .get (url , timeout = self .default_integration_http_timeout ,
169
+ verify = not disable_ssl_validation )
173
170
response .raise_for_status ()
174
171
response_json = response .json ()
175
172
176
173
except Timeout as e :
177
- self .service_check (JMX_SERVICE_CHECK ,
178
- AgentCheck .CRITICAL ,
179
- tags = tags ,
180
- message = "Request timeout: {0}, {1}" .format (url , e ))
174
+ self .service_check (JMX_SERVICE_CHECK , AgentCheck .CRITICAL , tags = tags ,
175
+ message = "Request timeout: {}, {}" .format (url , e ))
181
176
raise
182
177
183
178
except (HTTPError ,
184
179
InvalidURL ,
185
180
ConnectionError ) as e :
186
- self .service_check (JMX_SERVICE_CHECK ,
187
- AgentCheck .CRITICAL ,
188
- tags = tags ,
189
- message = "Request failed: {0}, {1}" .format (url , e ))
181
+ self .service_check (JMX_SERVICE_CHECK , AgentCheck .CRITICAL , tags = tags ,
182
+ message = "Request failed: {}, {}" .format (url , e ))
190
183
raise
191
184
192
185
except JSONDecodeError as e :
193
- self .service_check (JMX_SERVICE_CHECK ,
194
- AgentCheck .CRITICAL ,
195
- tags = tags ,
196
- message = 'JSON Parse failed: {0}, {1}' .format (url , e ))
186
+ self .service_check (JMX_SERVICE_CHECK , AgentCheck .CRITICAL , tags = tags ,
187
+ message = 'JSON Parse failed: {}, {}' .format (url , e ))
197
188
raise
198
189
199
190
except ValueError as e :
200
- self .service_check (JMX_SERVICE_CHECK ,
201
- AgentCheck .CRITICAL ,
202
- tags = tags ,
203
- message = str (e ))
191
+ self .service_check (JMX_SERVICE_CHECK , AgentCheck .CRITICAL , tags = tags , message = str (e ))
204
192
raise
205
193
206
194
return response_json
0 commit comments