Sha256: 9889f1db726dc083ffcf297b28bde0e21ce528555622d76084fafdf1cc7e16b9

Contents?: true

Size: 1.68 KB

Versions: 28

Compression:

Stored size: 1.68 KB

Contents

#!/usr/bin/env ruby
#
# Example munin plugin for querying stats out of db
# See munin plugin docs http://munin.projects.linpro.no/wiki/Documentation#Plugins
#
# Scripts added to RUBBER_ROOT/script/munin automatically
# get installed as munin plugins by rubber

# remove this line to enable
exit 0

# load just rubber config without loading rails (you can load rails
# if you want, but may be slow if your app loads a lot of plugins)

require "rubber"
env = ENV["RUBBER_ENV"] ||= "development"
root = File.join(File.dirname(__FILE__), '../..')
Rubber::initialize(root, env)
RUBBER_CONFIG = Rubber::Configuration.rubber_env
RUBBER_INSTANCES = Rubber::Configuration.rubber_instances

# Print config info need by munin for generating graphs
if ARGV[0] == "config"
  puts 'graph_title User Count'
  puts 'graph_vlabel Users'
  puts 'graph_category Examples'
  puts 'graph_scale no'
  puts 'tusers.label total users'
  puts 'tusers.type GAUGE'
  puts 'nusers.label user delta'
  puts 'nusers.type COUNTER'
  exit 0
end


query = <<-EOF
  select count(id) from users;
EOF

# pick a non-critical db if possible
source = RUBBER_INSTANCES.for_role("mysql_util").first
source ||= RUBBER_INSTANCES.for_role("mysql_slave").first
source ||= RUBBER_INSTANCES.for_role("mysql_master").first
db_host = source ? source.full_name : 'localhost'

command = "mysql -u #{RUBBER_ENV.db_slave_user}"
command << " --password=#{RUBBER_ENV.db_pass}"
command << " -h #{db_host}"
command << " #{RUBBER_ENV.db_name} --skip-column-names"

# execute a sql query to get some data
data = `echo "#{query}" | #{command}`
fail "Couldn't execute command" if $?.exitstatus > 0

# print graph data values
puts "tusers.value #{data}"
puts "nusers.value #{data}"

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
sml-rubber-0.9.1 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.10 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.11 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.13 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.3 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.4 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.5 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.6 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.7 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.8 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
sml-rubber-0.9.9 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
wr0ngway-rubber-1.0.0 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
wr0ngway-rubber-1.0.1 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
axtro-rubber-1.0.2.8 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
axtro-rubber-1.0.2.7 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
rubber-1.1.5 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
rubber-1.1.4 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
rubber-1.1.3 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
rubber-1.1.2 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb
rubber-1.1.1 generators/vulcanize/templates/munin/script/munin/example_mysql_query.rb