sysdog 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sysdog.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/lib/config.yml ADDED
@@ -0,0 +1,7 @@
1
+ email:
2
+ server: your_mail_server
3
+ server_alias: your_mail_server_alias_name
4
+ port: 25
5
+ address: send_mail_address
6
+ password: password
7
+ auth_type: login
@@ -0,0 +1,28 @@
1
+ require 'net/smtp'
2
+ require 'iconv'
3
+ require 'yaml'
4
+ class Email
5
+ attr :to, true
6
+ def initialize
7
+ @email = YAML.load_file(File.dirname(__FILE__) + "/../config.yml")
8
+ end
9
+ def send(title,content)
10
+ Net::SMTP.start( @email['email']['server'],
11
+ @email['email']['port'].to_s,
12
+ @email['email']['server_alias'],
13
+ @email['email']['address'],
14
+ @email['email']['password'].to_s,
15
+ @email['email']['auth_type'].to_sym) {|smtp|
16
+ #@email['email']['password'].to_s,
17
+ smtp.send_mail <<EndOfMail, "#{@email['email']['address']}", "#{@to}"
18
+ From: #{Sysdog.name} #{Sysdog::VERSION} <#{@email['email']['address']}>
19
+ To: <#{@to}>
20
+ Subject: #{title}
21
+ Date: #{Time.new}
22
+ Content-type: text/html
23
+
24
+ <html><body>#{content}\n\r\t\t\tPower By #{Sysdog.name} #{Sysdog::VERSION}</body</html>
25
+ EndOfMail
26
+ }
27
+ end
28
+ end
@@ -0,0 +1,16 @@
1
+ require 'net/http'
2
+ module Sysdog
3
+ class << self
4
+ def site_state(host)
5
+ begin
6
+ Net::HTTP.version_1_2
7
+ Net::HTTP.start(host, 80) {|http|
8
+ response = http.get('/')
9
+ return response.code
10
+ }
11
+ rescue
12
+ return 0
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Sysdog
2
+ PROC = {'version' => '/proc/version',
3
+ 'loadavg' => '/proc/loadavg',
4
+ 'meminfo'=>'/proc/meminfo'}
5
+ class << self
6
+ def read_info(file)
7
+ fp = File.open(file,'r')
8
+ fp.readlines
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module Sysdog
2
+ VERSION = "0.0.3"
3
+ end
data/lib/sysdog.rb ADDED
@@ -0,0 +1,44 @@
1
+ dir = File.dirname(__FILE__)
2
+ $LOAD_PATH.unshift dir unless $LOAD_PATH.include?(dir)
3
+ require "sysdog/version"
4
+ require "sysdog/email"
5
+ require "sysdog/http"
6
+ require "sysdog/sysinfo"
7
+ #require File.join(File.dirname(__FILE__), 'sysdog')
8
+ module Sysdog
9
+ # Your code goes here...
10
+ class << self
11
+ def run(hostname,mailto)
12
+ mail = Email.new
13
+ mail.to = mailto
14
+ http_code = Sysdog.site_state(hostname).to_i
15
+ if http_code == 200
16
+ lavg = Sysdog.read_info(Sysdog::PROC['loadavg'])[0].split(" ")
17
+ if lavg[0].to_f > 0.1 and lavg[1].to_f > 0.1
18
+ mail.send(hostname + ' System load average to hight.',hostname + ":\n\rSystem load average to hight.")
19
+ end
20
+ else
21
+ mail.send(hostname + "Can't open the site!",hostname + "\n\r" + 'Can\'t open the site!')
22
+ end
23
+ end
24
+ def report(hostname,mailto)
25
+ mail = Email.new
26
+ mail.to = mailto
27
+ lavg = Sysdog.read_info(Sysdog::PROC['loadavg'])[0].gsub(" ","</td><td>")
28
+ content = %Q{
29
+ <table border='1' width='60%' style='text-align:center;'>
30
+ <tr><td colspan='5' style='text-align:center;font-weight:bold;font-color:#eee;'>System Load Average</td></tr>
31
+ <tr><td>1min</td><td>10min</td><td>15min</td><td>Process</td><td>ProID</td></tr>
32
+ <tr><td>#{lavg}</td></tr>
33
+ </table>
34
+ }
35
+ mail.send(hostname + ' system load average',hostname + ":\n\r" + content)
36
+ end
37
+ end
38
+ end
39
+
40
+ #Usage
41
+ #hostname = "the web site domain"
42
+ #mailto = 'someone@somemailaddress'
43
+ #Sysdog.run(hostname,mailto)
44
+ #Sysdog.report(hostname,mailto)
data/sysdog.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sysdog/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sysdog"
7
+ s.version = Sysdog::VERSION
8
+ s.authors = ["23c"]
9
+ s.email = ["railscn@yeah.net"]
10
+ s.homepage = ""
11
+ s.summary = %q{Linux system monitor}
12
+ s.description = %q{Watch website and system load avg.}
13
+
14
+ s.rubyforge_project = "sysdog"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sysdog
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - 23c
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-03 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Watch website and system load avg.
23
+ email:
24
+ - railscn@yeah.net
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/config.yml
36
+ - lib/sysdog.rb
37
+ - lib/sysdog/email.rb
38
+ - lib/sysdog/http.rb
39
+ - lib/sysdog/sysinfo.rb
40
+ - lib/sysdog/version.rb
41
+ - sysdog.gemspec
42
+ has_rdoc: true
43
+ homepage: ""
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options: []
48
+
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ requirements: []
70
+
71
+ rubyforge_project: sysdog
72
+ rubygems_version: 1.5.2
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Linux system monitor
76
+ test_files: []
77
+