Module: Sysdog
- Defined in:
- lib/sysdog.rb,
lib/sysdog/http.rb,
lib/sysdog/sysinfo.rb,
lib/sysdog/version.rb
Constant Summary collapse
- PROC =
{'version' => '/proc/version', 'loadavg' => '/proc/loadavg', 'meminfo'=>'/proc/meminfo'}
- VERSION =
"0.0.4"
Class Method Summary collapse
- .read_info(file) ⇒ Object
- .report(hostname, mailto) ⇒ Object
- .run(hostname, mailto) ⇒ Object
- .site_state(host) ⇒ Object
Class Method Details
.read_info(file) ⇒ Object
6 7 8 9 |
# File 'lib/sysdog/sysinfo.rb', line 6 def read_info(file) fp = File.open(file,'r') fp.readlines end |
.report(hostname, mailto) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sysdog.rb', line 23 def report(hostname,mailto) mail = Email.new mail.to = mailto lavg = Sysdog.read_info(Sysdog::PROC['loadavg'])[0].gsub(" ","</td><td>") content = %Q{ <table border='1' width='60%' style='text-align:center;'> <tr><td colspan='5' style='text-align:center;font-weight:bold;font-color:#eee;'>System Load Average</td></tr> <tr><td>1min</td><td>10min</td><td>15min</td><td>Process</td><td>ProID</td></tr> <tr><td>#{lavg}</td></tr> </table> } mail.send(hostname + ' system load average',hostname + ":\n\r" + content) end |
.run(hostname, mailto) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sysdog.rb', line 10 def run(hostname,mailto) mail = Email.new mail.to = mailto http_code = Sysdog.site_state(hostname).to_i if http_code == 200 lavg = Sysdog.read_info(Sysdog::PROC['loadavg'])[0].split(" ") if lavg[0].to_f > 0.1 and lavg[1].to_f > 0.1 mail.send(hostname + ' System load average to hight.',hostname + ":\n\rSystem load average to hight.") end else mail.send(hostname + "Can't open the site! ",hostname + "\n\r" + 'Can\'t open the site!') end end |
.site_state(host) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/sysdog/http.rb', line 4 def site_state(host) begin Net::HTTP.version_1_2 Net::HTTP.start(host, 80) {|http| response = http.get('/') return response.code } rescue return 0 end end |