Skip to content

Instantly share code, notes, and snippets.

@sawanoboly
Created June 28, 2012 05:32
Show Gist options
  • Save sawanoboly/3009323 to your computer and use it in GitHub Desktop.
Save sawanoboly/3009323 to your computer and use it in GitHub Desktop.
Create Collectd server and client. for giraffi test
require 'yaml'
require 'erb'
CLI_NUM = ENV["CLI_NUM"] || 10
INTERVAL = ENV["INTERVAL"] || 5
task :default do
puts "default do nothing"
puts p
end
desc "create config"
task :configure do
# clear old configs
puts `rm -rf /opt/collectd/_etc/*`
config = YAML.load_file("./tpl/keys.yml")
config.each do |x,y|
@i = INTERVAL.to_i
@x = x
Dir.mkdir( "_etc/" + @x.to_s) if not File.directory?("_etc/" + @x.to_s)
@y=y
# create Server
server_cnf = ERB.new(File.read("./tpl/server.erb")).result
File.open( "_etc/" + @x.to_s + "/server.conf","w") do |file|
file.puts(server_cnf)
puts "created #{file.path}"
end
# create client
CLI_NUM.to_i.times do |z|
@z = z
client_cnf = server_cnf = ERB.new(File.read("./tpl/client.erb")).result
File.open( "_etc/" + @x.to_s + "/#{@x}-#{@z}.conf","w") do |file|
file.puts(client_cnf)
puts "created #{file.path}"
end
end
end
end
desc "run all collectd"
task :run do
puts `find /opt/collectd/_etc/ -type f | xargs --replace /opt/collectd/sbin/collectd -C {}`
end
desc "stop all collectd"
task :stop do
puts `kill \`pgrep collectd\``
end
desc "clear all configs (rm -rf)"
task :clean do
puts `rm -rf /opt/collectd/_etc/*`
end
q
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment