Skip to content

Instantly share code, notes, and snippets.

@mizzy
Last active December 16, 2015 06:38
Show Gist options
  • Select an option

  • Save mizzy/5392470 to your computer and use it in GitHub Desktop.

Select an option

Save mizzy/5392470 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'net/http'
require 'string-irc'
channels = %w( #test )
status_file = '/tmp/.ghe-overload'
pcpu_threshold = 80
idle = `snmpget -v 2c -c "public" ghe.example.jp .1.3.6.1.4.1.2021.11.11.0 | awk -F" " '{ print $4 }'`.strip
pcpu = 100 - idle.to_i
if pcpu < pcpu_threshold && File.exists?(status_file)
message = StringIrc.new('GHE 落ち着きました').green
`rm #{status_file}`
elsif pcpu >= pcpu_threshold && ! File.exists?('/tmp/.ghe-overload')
message = StringIrc.new('GHE がいっぱいいっぱいです(CPU 高負荷)').red
`touch #{status_file}`
end
channels.each do |channel|
if message
Net::HTTP.start('ikachan.example.jp', 4979) {|http|
body = "channel=#{channel}"
res = http.post('/join', body)
body = "channel=#{channel}&message=#{message}"
res = http.post('/notice', body)
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment