Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed collectd roles

  • Loading branch information...
commit 30248cc12748db2900bdb48e06f7a413f25a3a06 1 parent 3855a5a
@karlbright karlbright authored
View
107 script/collectd/collectd-runner.rb
@@ -1,107 +0,0 @@
-#!/usr/bin/env ruby
-
-STDOUT.sync = STDERR.sync = true
-
-action = ARGV[0]
-run_script = ARGV[1]
-
-if ARGV.size > 2 || (action == 'run' && run_script.nil?)
- puts "usage: #{File.basename(__FILE__)} [config | run script]"
- puts "\tWith no arguments run all scripts in plugin dir in an infinite loop"
- puts "\tWith config action, lists scripts that would be run"
- puts "\tWith run action, runs the given script"
- exit 1
-end
-
-HOSTNAME = ENV["COLLECTD_HOSTNAME"] || `hostname -f`.chomp
-INTERVAL = (ENV["COLLECTD_INTERVAL"] || 60).to_i
-
-env = ENV["RUBBER_ENV"] ||= "development"
-root = File.expand_path(File.dirname(__FILE__) + '/../..')
-
-STDERR.reopen("#{root}/log/collectd-runner.log", "a") unless action == 'run'
-
-require "rubber"
-Rubber::initialize(root, env)
-
-# Gives us a way to run a single script
-if action == 'run'
- load ARGV[1]
- exit
-end
-
-# for each script in our source tree, call that script to generate collectd data
-#
-# scripts directly in script_dir get run for each host
-# scripts in script_dir/role/role_name only get run if current host is a member of that role
-# scripts in script_dir/host/host_name only get run if current host is that host_name
-
-scripts = []
-this_script = File.expand_path(__FILE__)
-script_dir = "#{Rubber.root}/script/collectd"
-
-Dir["#{script_dir}/**/*"].each do |script|
- next if File.directory?(script)
- next if script == this_script
-
- # skip scripts not specific to the current host or roles
- #
- relative = script.gsub("#{script_dir}/", "")
- segments = relative.split("/")
- if segments[0] == 'host'
- next unless segments[1] == Rubber.config.host
- end
- if segments[0] == 'role'
- next unless Array(Rubber.config.roles).include?(segments[1])
- end
-
- scripts << script
-end
-
-# Allows collectd conf to see if it needs to setup an Exec Plugin block
-if ARGV[0] == 'config'
- puts scripts.join("\n")
- exit
-end
-
-# Collectd scripts can run indefinately, outputting values
-# every INTERVAL. We do this for all the rubber/collectd
-# scripts so that we keep the ruby vm loaded for faster
-# execution time at the expense of the ruby vm memory usage.
-#
-# Foreach rubber/collectd plugin script, load it in a fork
-# to run so that our master loop doesn't get compromised by
-# a bad script, segfault, etc.
-#
-STDERR.puts "#{Time.now}: Starting rubber-collectd execution loop"
-loop do
- start_time = Time.now.to_i
-
- scripts.each do |script|
- fork do
- begin
- load script
- rescue Exception => e
- STDERR.puts("#{script}: #{e}")
- end
- end
- end
- Process.waitall
-
- run_time = Time.now.to_i - start_time
- begin
- puts "PUTVAL #{HOSTNAME}/rubber/gauge-collectd_runner interval=#{INTERVAL} N:#{run_time}"
- rescue Errno::EPIPE
- STDERR.puts "#{Time.now}: Exiting rubber-collectd execution loop"
- exit
- end
-
- sleep_time = INTERVAL - run_time
- if sleep_time < 0
- sleep_time = INTERVAL
- STDERR.puts("Plugins taking longer (#{run_time}s) than #{INTERVAL}s")
- end
-
- sleep sleep_time
-
-end
View
19 script/collectd/role/examples/example_db_query.rb
@@ -1,19 +0,0 @@
-query = <<-EOF
- select count(id) from users;
-EOF
-
-# pick a non-critical db if possible
-source = Rubber.instances.for_role("db").first
-source ||= Rubber.instances.for_role("db", "primary" => true).first
-db_host = source ? source.full_name : 'localhost'
-
-command = "psql -U#{Rubber.config.db_slave_user}"
-command << " -h #{db_host}"
-command << " #{Rubber.config.db_name} --tuples-only --no-align"
-
-# 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 "PUTVAL #{HOSTNAME}/users/total interval=#{INTERVAL} N:#{data}"
View
1  script/collectd/role/examples/example_simple.rb
@@ -1 +0,0 @@
-puts "PUTVAL #{HOSTNAME}/example/rand_value interval=#{INTERVAL} N:#{rand(100)}"
View
31 script/collectd/role/postgresql_slave/replication_status.rb
@@ -1,31 +0,0 @@
-require 'pg'
-
-master = Rubber.instances.for_role('postgresql_master').first.full_name
-slave = "localhost"
-opts = { :dbname => Rubber.config.db_name,
- :user => Rubber.config.db_user,
- :password => Rubber.config.db_pass }
-mconn = PGconn.open(opts.merge({:host => master}))
-sconn = PGconn.open(opts.merge({:host => slave}))
-
-mval = mconn.exec("select pg_current_xlog_location()")[0]["pg_current_xlog_location"]
-sresult = sconn.exec("select pg_last_xlog_receive_location(), pg_last_xlog_replay_location()")[0]
-sval_receive = sresult["pg_last_xlog_receive_location"]
-sval_replay = sresult["pg_last_xlog_replay_location"]
-
-
-def numeric(val)
- # First part is logid, second part is record offset
- parts = val.split("/")
- raise "Invalid location" if parts.size != 2 && parts.any {|p| p.to_s.strip.size == 0}
- result = (0xFFFFFFFF * parts[0].to_i) + parts[1].to_i(16)
- return result
-end
-
-
-master_offset = numeric(mval)
-receive_offset = numeric(sval_receive)
-replay_offset = numeric(sval_replay)
-
-puts "PUTVAL #{HOSTNAME}/postgresql/gauge-replication_receive_delay interval=#{INTERVAL} N:#{master_offset - receive_offset}"
-puts "PUTVAL #{HOSTNAME}/postgresql/gauge-replication_replay_delay interval=#{INTERVAL} N:#{master_offset - replay_offset}"
View
12 script/collectd/role/web_tools/global_worker_stats.rb
@@ -1,12 +0,0 @@
-require "resque"
-
-redis_server = Rubber.instances.for_role('redis_master').first.full_name rescue nil
-redis_server ||= 'localhost' if Rubber.env == 'development'
-Resque.redis = "#{redis_server}:6379"
-
-queue_sizes = {}
-Resque.redis.smembers("queues").each do |queue_name|
- queue_size = Resque.redis.llen("queue:#{queue_name}")
-
- puts "PUTVAL #{HOSTNAME}/resque_worker/gauge-#{queue_name}_queued interval=#{INTERVAL} N:#{queue_size}"
-end
View
8 script/collectd/role/web_tools/resque_jobs_processed.rb
@@ -1,8 +0,0 @@
-require "resque"
-
-redis_server = Rubber.instances.for_role('redis_master').first.full_name rescue nil
-redis_server ||= 'localhost' if Rubber.env == 'development'
-Resque.redis = "#{redis_server}:6379"
-
-puts "PUTVAL #{HOSTNAME}/resque/derive-jobs_processed interval=#{INTERVAL} N:#{Resque.redis.get("stat:processed").to_i}"
-puts "PUTVAL #{HOSTNAME}/resque/derive-jobs_failed interval=#{INTERVAL} N:#{Resque.redis.get("stat:failed").to_i}"
Please sign in to comment.
Something went wrong with that request. Please try again.