server_status 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/.rvmrc +48 -0
- data/Gemfile +20 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +26 -0
- data/README.md +69 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/bin/statusd +10 -0
- data/lib/server_status/app.rb +46 -0
- data/lib/server_status/client.rb +68 -0
- data/lib/server_status/config.rb +4 -0
- data/lib/server_status.rb +19 -0
- data/public/css/bootstrap-fixed-footer.css +7 -0
- data/public/css/bootstrap-responsive.css +1088 -0
- data/public/css/bootstrap.css +6004 -0
- data/public/css/bootstrap.min.css +859 -0
- data/public/img/glyphicons-haflings-white.png +0 -0
- data/public/img/glyphicons-haflings.png +0 -0
- data/public/js/backbone.min.js +38 -0
- data/public/js/bootstrap.js +2036 -0
- data/public/js/bootstrap.min.js +7 -0
- data/public/js/jquery.min.js +2 -0
- data/public/js/underscore.min.js +5 -0
- data/spec/sample.yml +31 -0
- data/spec/server_status_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- data/views/index.slim +34 -0
- data/views/layout.slim +38 -0
- metadata +241 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.rvmrc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
|
7
|
+
# Only full ruby name is supported here, for short names use:
|
8
|
+
# echo "rvm use 1.9.3" > .rvmrc
|
9
|
+
environment_id="1.9.3@status"
|
10
|
+
|
11
|
+
# Uncomment the following lines if you want to verify rvm version per project
|
12
|
+
# rvmrc_rvm_version="1.16.17 (stable)" # 1.10.1 seams as a safe start
|
13
|
+
# eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
|
14
|
+
# echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
|
15
|
+
# return 1
|
16
|
+
# }
|
17
|
+
|
18
|
+
# First we attempt to load the desired environment directly from the environment
|
19
|
+
# file. This is very fast and efficient compared to running through the entire
|
20
|
+
# CLI and selector. If you want feedback on which environment was used then
|
21
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
22
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
|
23
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
24
|
+
then
|
25
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
26
|
+
[[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
|
27
|
+
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
|
28
|
+
else
|
29
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
30
|
+
rvm --create "$environment_id" || {
|
31
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
32
|
+
return 1
|
33
|
+
}
|
34
|
+
fi
|
35
|
+
|
36
|
+
# If you use bundler, this might be useful to you:
|
37
|
+
# if [[ -s Gemfile ]] && {
|
38
|
+
# ! builtin command -v bundle >/dev/null ||
|
39
|
+
# builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
|
40
|
+
# }
|
41
|
+
# then
|
42
|
+
# printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
|
43
|
+
# gem install bundler
|
44
|
+
# fi
|
45
|
+
# if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
|
46
|
+
# then
|
47
|
+
# bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
|
48
|
+
# fi
|
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
gem 'sinatra'
|
9
|
+
gem 'slim'
|
10
|
+
gem 'thin'
|
11
|
+
gem 'settingslogic'
|
12
|
+
gem 'rest-client'
|
13
|
+
|
14
|
+
group :development do
|
15
|
+
gem "rspec"
|
16
|
+
gem "yard"
|
17
|
+
gem "rdoc"
|
18
|
+
gem "bundler"
|
19
|
+
gem "jeweler"
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
daemons (1.1.9)
|
5
|
+
diff-lcs (1.1.3)
|
6
|
+
eventmachine (1.0.0)
|
7
|
+
git (1.2.5)
|
8
|
+
jeweler (1.8.4)
|
9
|
+
bundler (~> 1.0)
|
10
|
+
git (>= 1.2.5)
|
11
|
+
rake
|
12
|
+
rdoc
|
13
|
+
json (1.7.5)
|
14
|
+
mime-types (1.19)
|
15
|
+
rack (1.4.1)
|
16
|
+
rack-protection (1.2.0)
|
17
|
+
rack
|
18
|
+
rake (10.0.2)
|
19
|
+
rdoc (3.12)
|
20
|
+
json (~> 1.4)
|
21
|
+
rest-client (1.6.7)
|
22
|
+
mime-types (>= 1.16)
|
23
|
+
rspec (2.12.0)
|
24
|
+
rspec-core (~> 2.12.0)
|
25
|
+
rspec-expectations (~> 2.12.0)
|
26
|
+
rspec-mocks (~> 2.12.0)
|
27
|
+
rspec-core (2.12.0)
|
28
|
+
rspec-expectations (2.12.0)
|
29
|
+
diff-lcs (~> 1.1.3)
|
30
|
+
rspec-mocks (2.12.0)
|
31
|
+
settingslogic (2.0.8)
|
32
|
+
sinatra (1.3.3)
|
33
|
+
rack (~> 1.3, >= 1.3.6)
|
34
|
+
rack-protection (~> 1.2)
|
35
|
+
tilt (~> 1.3, >= 1.3.3)
|
36
|
+
slim (1.3.4)
|
37
|
+
temple (~> 0.5.5)
|
38
|
+
tilt (~> 1.3.3)
|
39
|
+
temple (0.5.5)
|
40
|
+
thin (1.5.0)
|
41
|
+
daemons (>= 1.0.9)
|
42
|
+
eventmachine (>= 0.12.6)
|
43
|
+
rack (>= 1.0.0)
|
44
|
+
tilt (1.3.3)
|
45
|
+
yard (0.8.3)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
|
50
|
+
DEPENDENCIES
|
51
|
+
bundler
|
52
|
+
jeweler
|
53
|
+
rdoc
|
54
|
+
rest-client
|
55
|
+
rspec
|
56
|
+
settingslogic
|
57
|
+
sinatra
|
58
|
+
slim
|
59
|
+
thin
|
60
|
+
yard
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
Copyright (c) 2012 Jeong, Jiung
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer in the documentation
|
11
|
+
and/or other materials provided with the distribution.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
14
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
15
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
16
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
17
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
18
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
19
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
20
|
+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
21
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
22
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
|
24
|
+
The views and conclusions contained in the software and documentation are those
|
25
|
+
of the authors and should not be interpreted as representing official policies,
|
26
|
+
either expressed or implied, of the FreeBSD Project.
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
Server Status
|
2
|
+
==========
|
3
|
+
[![Dependency Status](https://gemnasium.com/astral1/server_status.png)](https://gemnasium.com/astral1/server_status)
|
4
|
+
[![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/astral1/server_status)
|
5
|
+
|
6
|
+
서버의 상태를 체크하고 쉽게 확인하기 위한 도구입니다. 도메인 별로 port 상태와 대표 API의 동작 여부를 확인합니다.
|
7
|
+
|
8
|
+
사용법
|
9
|
+
----
|
10
|
+
```bash
|
11
|
+
gem install server_status
|
12
|
+
statusd <path to config file>
|
13
|
+
```
|
14
|
+
|
15
|
+
API
|
16
|
+
---
|
17
|
+
- **/servers** - 확인 대상의 목록
|
18
|
+
```
|
19
|
+
["google","test"]
|
20
|
+
```
|
21
|
+
- **/:server_name/status - 해당 대상의 상태
|
22
|
+
```
|
23
|
+
{"name":"google","code":404,"description":"Google Portal","is_open":true}
|
24
|
+
```
|
25
|
+
|
26
|
+
예제 설정
|
27
|
+
----
|
28
|
+
```yaml
|
29
|
+
port: 4568
|
30
|
+
servers:
|
31
|
+
google:
|
32
|
+
protocol: http
|
33
|
+
domain: www.google.com
|
34
|
+
ssl: false
|
35
|
+
description: Google Portal
|
36
|
+
port: 80
|
37
|
+
apis:
|
38
|
+
default:
|
39
|
+
url: /deaddead
|
40
|
+
details:
|
41
|
+
index:
|
42
|
+
description: Index Page
|
43
|
+
url: /
|
44
|
+
test:
|
45
|
+
protocol: http
|
46
|
+
domain: localhost
|
47
|
+
ssl: false
|
48
|
+
description: Test Dummy
|
49
|
+
port: 4567
|
50
|
+
apis:
|
51
|
+
default:
|
52
|
+
url: /
|
53
|
+
payload:
|
54
|
+
header:
|
55
|
+
content_type: application/json
|
56
|
+
params:
|
57
|
+
query: TEST
|
58
|
+
encode: json
|
59
|
+
method: get
|
60
|
+
```
|
61
|
+
|
62
|
+
Copyright
|
63
|
+
---------
|
64
|
+
|
65
|
+
이 프로젝트는 Simplified BSD 2.0 라이센스로 제공되고 있습니다.
|
66
|
+
|
67
|
+
Copyright (c) 2012 Jeong, Jiung. See LICENSE.txt for
|
68
|
+
further details.
|
69
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "server_status"
|
18
|
+
gem.homepage = "http://github.com/astral1/server_status"
|
19
|
+
gem.license = "BSD"
|
20
|
+
gem.summary = %Q{Server Status check}
|
21
|
+
gem.description = %Q{
|
22
|
+
Server Status check
|
23
|
+
}
|
24
|
+
gem.email = "ethernuiel@sanultari.com"
|
25
|
+
gem.authors = ["Jeong, Jiung"]
|
26
|
+
# dependencies defined in Gemfile
|
27
|
+
end
|
28
|
+
Jeweler::RubygemsDotOrgTasks.new
|
29
|
+
|
30
|
+
require 'rspec/core'
|
31
|
+
require 'rspec/core/rake_task'
|
32
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
33
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
34
|
+
end
|
35
|
+
task :default => :spec
|
36
|
+
|
37
|
+
require 'yard'
|
38
|
+
YARD::Rake::YardocTask.new
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/statusd
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
class ServerStatusApp < Sinatra::Base
|
2
|
+
set :root, GEM_ROOT
|
3
|
+
set :server, :thin
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def check server
|
7
|
+
server_config = ServerStatusConfig.servers[server.to_sym]
|
8
|
+
client = ServerStatusClient.new server_config
|
9
|
+
status_code = client.request.to_s
|
10
|
+
Status.new server, server_config[:description.to_s], status_code, client.is_port_open?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
get '/' do
|
15
|
+
@server_status = ServerStatusConfig.servers.keys.collect do |server|
|
16
|
+
ServerStatusApp.check server
|
17
|
+
end
|
18
|
+
|
19
|
+
slim :index
|
20
|
+
end
|
21
|
+
|
22
|
+
get '/servers' do
|
23
|
+
ServerStatusConfig.servers.keys.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
get '/:server/status' do
|
27
|
+
ServerStatusApp.check(params[:server].to_sym).to_json
|
28
|
+
end
|
29
|
+
|
30
|
+
class Status
|
31
|
+
attr_reader :code, :name, :description
|
32
|
+
|
33
|
+
def initialize name, description, code, is_open
|
34
|
+
@code, @name, @description, @is_open = code.to_i, name, description, is_open
|
35
|
+
end
|
36
|
+
|
37
|
+
def is_open?
|
38
|
+
@is_open
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_json
|
42
|
+
{name: @name, code: @code, description: @description, is_open: @is_open}.to_json
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'socket'
|
3
|
+
require 'timeout'
|
4
|
+
|
5
|
+
class ServerStatusClient
|
6
|
+
def initialize(hash)
|
7
|
+
@domain = hash[:domain.to_s]
|
8
|
+
@port = hash[:port.to_s]
|
9
|
+
@scheme = hash[:ssl.to_s] ? 'https' : 'http'
|
10
|
+
@url = "#@scheme://#@domain:#@port"
|
11
|
+
@default = hash[:apis.to_s][:default.to_s]
|
12
|
+
@payload = @default[:payload.to_s]
|
13
|
+
@payload ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def request
|
17
|
+
header, method, params = parse_params
|
18
|
+
Timeout::timeout(5) do
|
19
|
+
begin
|
20
|
+
case method
|
21
|
+
when :get
|
22
|
+
header[:params] = params
|
23
|
+
response = RestClient.get "#@url#{@default[:url.to_s]}", header
|
24
|
+
when :post
|
25
|
+
response = RestClient.post "#@url#{@default[:url.to_s]}", params.to_json, header
|
26
|
+
end
|
27
|
+
response.code
|
28
|
+
rescue => e
|
29
|
+
e.response.code
|
30
|
+
end
|
31
|
+
end
|
32
|
+
rescue Timeout::Error
|
33
|
+
return 408
|
34
|
+
end
|
35
|
+
|
36
|
+
def parse_params
|
37
|
+
header = {}
|
38
|
+
method = :get
|
39
|
+
params = {}
|
40
|
+
if @payload.has_key? :header.to_s
|
41
|
+
header = @payload[:header.to_s]
|
42
|
+
end
|
43
|
+
if @payload.has_key? :method.to_s
|
44
|
+
method = @payload[:method.to_s].downcase.to_sym
|
45
|
+
end
|
46
|
+
if @payload.has_key? :params.to_s
|
47
|
+
params = @payload[:params.to_s]
|
48
|
+
end
|
49
|
+
[header, method, params]
|
50
|
+
end
|
51
|
+
|
52
|
+
#noinspection RubyResolve
|
53
|
+
def is_port_open?
|
54
|
+
Timeout::timeout(1) do
|
55
|
+
begin
|
56
|
+
s = TCPSocket.new(@domain, @port)
|
57
|
+
s.close
|
58
|
+
return true
|
59
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
60
|
+
return false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
rescue Timeout::Error
|
64
|
+
return false
|
65
|
+
end
|
66
|
+
|
67
|
+
private :parse_params
|
68
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'slim'
|
3
|
+
require 'json'
|
4
|
+
require 'server_status/config'
|
5
|
+
require 'server_status/client'
|
6
|
+
|
7
|
+
Slim::Engine.set_default_options pretty: true
|
8
|
+
|
9
|
+
LIB_ROOT = File.expand_path File.dirname(__FILE__)
|
10
|
+
GEM_ROOT = File.expand_path '..', LIB_ROOT
|
11
|
+
STATIC_ROOT = File.expand_path 'public', GEM_ROOT
|
12
|
+
VIEW_ROOT = File.expand_path 'views', GEM_ROOT
|
13
|
+
|
14
|
+
require 'server_status/app'
|
15
|
+
|
16
|
+
def set_config file_name
|
17
|
+
ServerStatusConfig.source File.expand_path file_name
|
18
|
+
ServerStatusApp.set :port, ServerStatusConfig.port
|
19
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
html,body{height: 100%;}
|
2
|
+
.container{min-height: 100%;height: auto !important;height: 100%;margin: 0 auto -60px;}
|
3
|
+
.push,footer{height: 60px;}
|
4
|
+
footer{background-color: #f5f5f5;}
|
5
|
+
|
6
|
+
footer .credit{margin: 20px 0;text-align: center;}
|
7
|
+
.table td.center,.table th.center{text-align: center;}
|