simple_server_monitoring 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/bin/send_server_monitor_report +30 -0
- data/lib/simple_server_monitoring.rb +5 -0
- data/lib/simple_server_monitoring/reporter.rb +92 -0
- data/lib/simple_server_monitoring/version.rb +3 -0
- data/lib/simple_server_monitoring/views/email_template.html.erb +20 -0
- data/simple_server_monitoring.gemspec +23 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc6e78a27a42642c126a92e6a793d691e2c79d80
|
4
|
+
data.tar.gz: a31913fa4fe812188ae1cd1ea9168e3a26412a18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b6350097a88ec4df164473002589657bfd64577db458f45365d9523bd4c2dd03e656297c6de118bc2ba8c4702420a966cd02108e01ae7d12b0be0575b907d2d5
|
7
|
+
data.tar.gz: f29cf2545828bcf58325bcc46b9f1e196db45ac97b3e9795f432e6ed271bc32369cb2308fce669ff1466bc7838c030454383714924aad125b6aee6785bb166bd
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Semenyuk Dmitriy
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# SimpleServerMonitoring
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it yourself as:
|
8
|
+
|
9
|
+
$ gem install simple_server_monitoring
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```
|
14
|
+
send_server_monitor_report --from robot@nsa.gov --to "John Doe <johndoe@email.net>","Someone Else <someone@else.com>" --proccesses-file ~/processes.yml
|
15
|
+
```
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative "../lib/simple_server_monitoring/reporter"
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
from, to, processes_file = nil
|
6
|
+
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: send_server_monitor_report --from \"John Doe <john.doe@nsa.gov\" --to some@email.net --proccesses-file ~/processes.yml"
|
9
|
+
|
10
|
+
opts.separator ""
|
11
|
+
opts.separator "Specific options:"
|
12
|
+
|
13
|
+
# All arguments are mandatory.
|
14
|
+
opts.on("--from johndoe@email.net", String, "Sender address") do |from_email|
|
15
|
+
from = from_email
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on(%(--to "John Doe <johndoe@email.net>","Someone Else <someone@else.com>"), Array, "Receivers of server status report address") do |to_email|
|
19
|
+
to = to_email
|
20
|
+
end
|
21
|
+
|
22
|
+
opts.on("--processes-file processes_file", String,
|
23
|
+
"Process configuration file in YAML format. It should be like that:\n\nmysql: 1\nnginx: 5\nthin: 3'") do |processes_file_name|
|
24
|
+
processes_file = processes_file_name
|
25
|
+
end
|
26
|
+
end.parse!(ARGV)
|
27
|
+
|
28
|
+
reporter = SimpleServerMonitoring::Reporter.new(to: to, from: from, processes_file: processes_file)
|
29
|
+
puts reporter.report
|
30
|
+
reporter.send_report_email
|
@@ -0,0 +1,92 @@
|
|
1
|
+
module SimpleServerMonitoring
|
2
|
+
require "erb"
|
3
|
+
require "yaml"
|
4
|
+
require "net/smtp"
|
5
|
+
|
6
|
+
class Reporter
|
7
|
+
attr_reader :report
|
8
|
+
|
9
|
+
def initialize(options = {})
|
10
|
+
@to, @processes_file, @from = options.values_at(:to, :processes_file, :from)
|
11
|
+
@report = build_report
|
12
|
+
end
|
13
|
+
|
14
|
+
def send_report_email
|
15
|
+
send_email @to, subject: @report.subject, body: @report.body, content_type: "text/html", from: @from
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def build_report
|
21
|
+
running_processes = `ps -ef`.split("\n")
|
22
|
+
hostname = `hostname`
|
23
|
+
template_variables = {
|
24
|
+
free_storage_space: `df -h /`,
|
25
|
+
free_ram: `free 2> /dev/null`, # for cases where there is no `free`
|
26
|
+
uptime: `uptime`,
|
27
|
+
running_processes: running_processes,
|
28
|
+
hostname: hostname,
|
29
|
+
important_processes: []
|
30
|
+
}
|
31
|
+
|
32
|
+
failed_process_constraints = []
|
33
|
+
|
34
|
+
load_process_constraints.each do |name_of_process, expected_processes_count|
|
35
|
+
processes = running_processes.select { |process| process =~ /#{name_of_process}/i }
|
36
|
+
|
37
|
+
unless processes.count == expected_processes_count
|
38
|
+
failed_process_constraints.push(process: name_of_process, expected: expected_processes_count, actual: processes.count)
|
39
|
+
end
|
40
|
+
|
41
|
+
template_variables[:important_processes].push name: name_of_process, processes: processes
|
42
|
+
end
|
43
|
+
|
44
|
+
if failed_process_constraints.any?
|
45
|
+
report_status = "errors: #{failed_process_constraints.map { |c| c[:process] }.join(", ")}"
|
46
|
+
else
|
47
|
+
report_status = "OK"
|
48
|
+
end
|
49
|
+
|
50
|
+
Report.new(
|
51
|
+
subject: "#{report_status}, #{hostname}, #{Time.now.utc}, Server Monitoring".gsub("\n", ""),
|
52
|
+
status: report_status,
|
53
|
+
body: ERB.new(File.read(File.expand_path("../views/email_template.html.erb", __FILE__))).result(binding)
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
class Report
|
58
|
+
attr_accessor :subject, :body, :status
|
59
|
+
|
60
|
+
def initialize(options = {})
|
61
|
+
self.subject, self.body, self.status = options.values_at(:subject, :body, :status)
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_s
|
65
|
+
{status: status, subject: subject, body: body}.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def load_process_constraints
|
70
|
+
YAML.load_file(File.expand_path(@processes_file, __FILE__))
|
71
|
+
end
|
72
|
+
|
73
|
+
def send_email(receiver_emails, options = {})
|
74
|
+
options[:server] ||= "localhost"
|
75
|
+
options[:from_alias] ||= "Simple Server Mailer"
|
76
|
+
options[:content_type] ||= "text/plain"
|
77
|
+
|
78
|
+
msg = <<-END_OF_MESSAGE
|
79
|
+
From: #{options[:from_alias]} <#{options.fetch(:from)}>
|
80
|
+
To: #{receiver_emails.join(", ")}
|
81
|
+
Subject: #{options.fetch(:subject)}
|
82
|
+
Content-Type: #{options[:content_type]}; charset=utf-8
|
83
|
+
|
84
|
+
#{options.fetch(:body)}
|
85
|
+
END_OF_MESSAGE
|
86
|
+
|
87
|
+
Net::SMTP.start(options[:server]) do |smtp|
|
88
|
+
smtp.send_message msg, options[:from], receiver_emails
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<h1><%= template_variables[:hostname] %> <small>Server Monitoring</small></h1>
|
2
|
+
|
3
|
+
<h3>Uptime</h3>
|
4
|
+
<p><pre><code><%= template_variables[:uptime] %></code></pre></p>
|
5
|
+
|
6
|
+
<h3>Free Storage Space</h3>
|
7
|
+
<p><pre><code><%= template_variables[:free_storage_space] %></code></pre></p>
|
8
|
+
|
9
|
+
<h3>Free RAM</h3>
|
10
|
+
<p><pre><code><%= template_variables[:free_ram] %></code></pre></p>
|
11
|
+
|
12
|
+
|
13
|
+
<h3>Important Processes Status</h3>
|
14
|
+
<% template_variables[:important_processes].each do |process| %>
|
15
|
+
<h4><%= process[:name] %></h4>
|
16
|
+
<p><pre><code><%= process[:processes].join("\n") %></code></pre></p>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<h3>Running processes</h3>
|
20
|
+
<p><pre><code><%= template_variables[:running_processes].join("\n")%></code></pre></p>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_server_monitoring/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_server_monitoring"
|
8
|
+
spec.version = SimpleServerMonitoring::VERSION
|
9
|
+
spec.authors = ["Semenyuk Dmitriy"]
|
10
|
+
spec.email = ["mail@semenyukdmitriy.com"]
|
11
|
+
spec.description = %q{Simple server monitoring}
|
12
|
+
spec.summary = %q{Sends you email with key indicators of your server}
|
13
|
+
spec.homepage = "https://github.com/dmitrydims/simple_server_monitoring"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_server_monitoring
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Semenyuk Dmitriy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Simple server monitoring
|
42
|
+
email:
|
43
|
+
- mail@semenyukdmitriy.com
|
44
|
+
executables:
|
45
|
+
- send_server_monitor_report
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/send_server_monitor_report
|
55
|
+
- lib/simple_server_monitoring.rb
|
56
|
+
- lib/simple_server_monitoring/reporter.rb
|
57
|
+
- lib/simple_server_monitoring/version.rb
|
58
|
+
- lib/simple_server_monitoring/views/email_template.html.erb
|
59
|
+
- simple_server_monitoring.gemspec
|
60
|
+
homepage: https://github.com/dmitrydims/simple_server_monitoring
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.5
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Sends you email with key indicators of your server
|
84
|
+
test_files: []
|