Skip to content

Instantly share code, notes, and snippets.

@ianrumford
Last active December 11, 2015 01:39
Show Gist options
  • Save ianrumford/4524859 to your computer and use it in GitHub Desktop.
Save ianrumford/4524859 to your computer and use it in GitHub Desktop.
Riemann Feeds blog_feed_jmx1.rb
#!/usr/bin/jruby
# riemann feeds
# A simple JMX feed monitoring the Hadoop YARN NameNode
require 'riemann-feeds' # bootstrap rieeman feeds
#$DEBUG = true # force diags
# The external YAML configration files
credentials_jmx_path = './etc/credentialsJMX.yaml'
jmxconfig_namenode_path = './etc/jmxconfigNameNode.yaml'
config_riemann_path = './etc/configRiemann.yaml'
# The bytes to gigabytes conversion proc
bytes2GB = (1024 * 1024 * 1024).to_f
bytes_2_gigabytes = ->(b) { b.to_f / bytes2GB }
# Create the feed specification
# Note the include_configuration array which pulls in the yaml files
feedspec_namenode = {
type: :JMX,
name: 'YARN NameNode',
configuration:
{ include_configuration: [credentials_jmx_path,
jmxconfig_namenode_path,
config_riemann_path,
],
event_defaults: {service: 'NameNode', status: 'ok', tags: ['YARN', 'NameNode']},
beans: [
{ bean_name: 'Hadoop:service=NameNode,name=NameNodeActivity',
event_defaults: { tags: ['Activity', 'Files'] },
attributes: {include: ['files_created', 'files_deleted']},
},
{ bean_name: 'java.lang:type=OperatingSystem',
event_defaults: { tags: ['OS'] },
attributes: {
include: ['free_physical_memory_size',
'free_swap_space_size',
'total_swap_space_size',
'system_load_average',
'available_processors'
],
definitions: {
'free_physical_memory_size' =>
{ event_defaults: { tags: ['FreeMem']}, # more tags
metric: bytes_2_gigabytes,
select: ->(e) {(r = e[:metric]) ? (r < 1.0) : true}, # only pass through events where free memory less than 1GB
map: ->(e) {e[:status] = 'critical'; e },
},
}
}
}
]
}
}
# Make a feed handler
feed_handler = Riemann::Feeds::FeedHandler.new
# Show the feed to the handler
feed_handler.import_feed_or_croak(feedspec_namenode)
# Now tell the handler to run the feed
feed_handler.run_feed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment