-
Notifications
You must be signed in to change notification settings - Fork 812
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add HDFS check using snakebite #551
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d767032
add HDFS check using snakebite
dcrosta 6ff3a94
add 'in_use' (percent used) gauge
dcrosta d2ae1e2
HDFSCheck: safely import snakebite.client
dcrosta bc904f3
HDFSCheck: raise exception rather than logging and returning
dcrosta 1e40685
HDFSCheck: split hostport into 2 configuration items
dcrosta 1165b07
whitespace
dcrosta File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from checks import AgentCheck | ||
|
||
|
||
class HDFSCheck(AgentCheck): | ||
"""Report on free space and space used in HDFS. | ||
""" | ||
|
||
def check(self, instance): | ||
try: | ||
import snakebite.client | ||
except ImportError: | ||
raise ImportError('HDFSCheck requires the snakebite module') | ||
|
||
if 'namenode' not in instance: | ||
raise ValueError('Missing key \'namenode\' in HDFSCheck config') | ||
|
||
host, port = instance['namenode'], instance.get('port', 8020) | ||
if not isinstance(port, int): | ||
# PyYAML converts the number to an int for us | ||
raise ValueError('Port %r is not an integer' % port) | ||
|
||
hdfs = snakebite.client.Client(host, port) | ||
stats = hdfs.df() | ||
# {'used': 2190859321781L, | ||
# 'capacity': 76890897326080L, | ||
# 'under_replicated': 0L, | ||
# 'missing_blocks': 0L, | ||
# 'filesystem': 'hdfs://hostname:port', | ||
# 'remaining': 71186818453504L, | ||
# 'corrupt_blocks': 0L} | ||
|
||
self.gauge('hdfs.used', stats['used']) | ||
self.gauge('hdfs.free', stats['remaining']) | ||
self.gauge('hdfs.capacity', stats['capacity']) | ||
self.gauge('hdfs.in_use', float(stats['used']) / float(stats['capacity'])) | ||
self.gauge('hdfs.under_replicated', stats['under_replicated']) | ||
self.gauge('hdfs.missing_blocks', stats['missing_blocks']) | ||
self.gauge('hdfs.corrupt_blocks', stats['corrupt_blocks']) | ||
|
||
if __name__ == '__main__': | ||
check, instances = HDFSCheck.from_yaml('./hdfs.yaml') | ||
for instance in instances: | ||
check.check(instance) | ||
print "Events: %r" % check.get_events() | ||
print "Metrics: %r" % check.get_metrics() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
init_config: | ||
# HDFS check does not require any init_config | ||
|
||
instances: | ||
# Each instance requires a namenode hostname. | ||
# Port defaults to 8020. | ||
- namenode: namenode.example.com | ||
port: 8020 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be surrounded by a try except to catch a possible ZeroDivisionError or the capacity will never be 0 ? (I don't really know hdfs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that if you like. It's very unlikely for the capacity (in bytes) to be 0 -- that would probably only happen if the hadoop cluster were seriously broken.