ServState 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 +21 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/Rakefile +1 -0
- data/ServState.gemspec +29 -0
- data/bin/servstate +21 -0
- data/lib/ServState/info.rb +120 -0
- data/lib/ServState/main.rb +28 -0
- data/lib/ServState/public/css/uikit.almost-flat.css +7743 -0
- data/lib/ServState/public/css/uikit.almost-flat.min.css +3 -0
- data/lib/ServState/public/css/uikit.css +6990 -0
- data/lib/ServState/public/css/uikit.gradient.css +7859 -0
- data/lib/ServState/public/css/uikit.gradient.min.css +3 -0
- data/lib/ServState/public/css/uikit.min.css +3 -0
- data/lib/ServState/public/fonts/FontAwesome.otf +0 -0
- data/lib/ServState/public/fonts/fontawesome-webfont.eot +0 -0
- data/lib/ServState/public/fonts/fontawesome-webfont.ttf +0 -0
- data/lib/ServState/public/fonts/fontawesome-webfont.woff +0 -0
- data/lib/ServState/public/js/app.js +69 -0
- data/lib/ServState/public/js/uikit.js +2078 -0
- data/lib/ServState/public/js/uikit.min.js +3 -0
- data/lib/ServState/version.rb +3 -0
- data/lib/ServState/views/css/base.scss +2 -0
- data/lib/ServState/views/css/custom.scss +15 -0
- data/lib/ServState/views/css/style.scss +2 -0
- data/lib/ServState/views/index.erb +61 -0
- data/lib/ServState.rb +6 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 78853b8c0e8801be6c3d102791077475493e17f8
|
4
|
+
data.tar.gz: 5b57356325c26b54c3ed78ce1947dc0bc1ddaccc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8718ae09e06c93252ed414af93c96c4d9bdb84d9a7103d90a85a5501ab38a2dbb6a2c5f7a2f0af7d80cb2ab5865b8ffec0d90abc426ff6051b254b147fc63a89
|
7
|
+
data.tar.gz: c636ef88de14aeda491a7f21031affd57f557d1435fc583f51af4a0b5ed6576258b8361f9a03d6c2cfce9061d306361e164dfcfa1da883dec3da8cc870cbbe5e
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
.rvmrc
|
19
|
+
ServState/lib/SerState/.sass-cache
|
20
|
+
bin/.sass-cache
|
21
|
+
.sass-cache
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 2.0.0@servstate --create
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Denis Sergienko
|
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,19 @@
|
|
1
|
+
# ServState
|
2
|
+
|
3
|
+
Very simple tool to watch your LINUX server status.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install ServState
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ servstate
|
12
|
+
|
13
|
+
## Contributing
|
14
|
+
|
15
|
+
1. Fork it
|
16
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
17
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
18
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
19
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/ServState.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ServState/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ServState"
|
8
|
+
spec.version = ServState::VERSION
|
9
|
+
spec.authors = ["Denis Sergienko","Igor Kroosh"]
|
10
|
+
spec.email = ["olol.toor@gmail.com"]
|
11
|
+
spec.description = %q{Simple tool to watch your linux server state}
|
12
|
+
spec.summary = %q{http://github.com/ololyay/ServState}
|
13
|
+
spec.homepage = "http://github.com/ololyay/ServState"
|
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
|
+
|
22
|
+
spec.add_dependency "sinatra"
|
23
|
+
spec.add_dependency "rack"
|
24
|
+
spec.add_dependency "sass"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
27
|
+
spec.add_development_dependency "rake"
|
28
|
+
|
29
|
+
end
|
data/bin/servstate
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "rack"
|
3
|
+
APP_ROOT = File.expand_path(File.dirname(__FILE__)) #пригодится
|
4
|
+
require_relative "./../lib/ServState.rb"
|
5
|
+
|
6
|
+
#добавить настройки порта и прочее
|
7
|
+
Thread.new{ # thread for calculate cpu and network load and other long time operations
|
8
|
+
while true
|
9
|
+
Info.update
|
10
|
+
sleep(5)
|
11
|
+
end
|
12
|
+
}
|
13
|
+
|
14
|
+
puts " ____ ____ _ _ "
|
15
|
+
puts "/ ___| ___ _ ____ __/ ___|| |_ __ _| |_ ___ "
|
16
|
+
puts "\\___ \\ / _ \\ '__\\ \\ / /\\___ \\| __/ _` | __/ _ \\"
|
17
|
+
puts " ___) | __/ | \\ V / ___) | || (_| | || __/"
|
18
|
+
puts "|____/ \\___|_| \\_/ |____/ \\__\\__,_|\\__\\___|"
|
19
|
+
puts "\n"*3
|
20
|
+
|
21
|
+
Rack::Handler::WEBrick.run ServStateApp
|
@@ -0,0 +1,120 @@
|
|
1
|
+
class Info
|
2
|
+
@@old_usage=0
|
3
|
+
@@old_total_usage=0
|
4
|
+
@@old_traffic=Hash.new
|
5
|
+
@@old_time_for_traffic=Time.now
|
6
|
+
def self.hostname
|
7
|
+
`hostname`.chomp
|
8
|
+
end
|
9
|
+
#hash[interface name] => ipaddr as string
|
10
|
+
def self.interfaces
|
11
|
+
ifconfig=`ifconfig -a`
|
12
|
+
ifconfig=ifconfig.lines.map do |line|
|
13
|
+
line.chomp
|
14
|
+
end
|
15
|
+
key=''
|
16
|
+
faces=Hash.new
|
17
|
+
ifconfig.each do |line|
|
18
|
+
unless line.start_with?' ' or line.start_with?'lo'
|
19
|
+
key=line.split[0]
|
20
|
+
end
|
21
|
+
if line.include? 'inet addr:' and key
|
22
|
+
faces[key]=line.split[1][5..-1]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
faces
|
26
|
+
end
|
27
|
+
# hash with fixnum values
|
28
|
+
def self.uptime
|
29
|
+
upt=Hash.new
|
30
|
+
upt[:total_sec]=IO.read('/proc/uptime').split.first.to_i
|
31
|
+
upt[:days]=upt[:total_sec]/86400
|
32
|
+
upt[:hours]=(upt[:total_sec]-upt[:days]*86400)/3600
|
33
|
+
upt[:minutes]=(upt[:total_sec]-upt[:days]*86400-upt[:hours]*3600)/60
|
34
|
+
upt[:seconds]=upt[:total_sec]-upt[:days]*86400-upt[:hours]*3600-upt[:minutes]*60
|
35
|
+
upt
|
36
|
+
end
|
37
|
+
# fixnum % of cpu load
|
38
|
+
def self.cpu_stat
|
39
|
+
if @@old_total_usage==0 # first call
|
40
|
+
@@old_usage=IO.readlines('/proc/stat').grep(/^cpu /).first.split[1..3].collect{|i| i.to_i}.inject(:+)
|
41
|
+
@@old_total_usage=IO.readlines('/proc/stat').grep(/^cpu /).first.split.collect{|i| i.to_i}.inject(:+)
|
42
|
+
sleep 1
|
43
|
+
end
|
44
|
+
new_usage=IO.readlines('/proc/stat').grep(/^cpu /).first.split[1..3].collect{|i| i.to_i}.inject(:+)
|
45
|
+
usage=new_usage-@@old_usage
|
46
|
+
|
47
|
+
new_total_usage=IO.readlines('/proc/stat').grep(/^cpu /).first.split.collect{|i| i.to_i}.inject(:+)
|
48
|
+
total_usage=new_total_usage-@@old_total_usage
|
49
|
+
|
50
|
+
@@old_usage=new_usage
|
51
|
+
@@old_total_usage=new_total_usage
|
52
|
+
|
53
|
+
((usage/total_usage.to_f)*100).to_i
|
54
|
+
end
|
55
|
+
# hash[mount point] => [usage %, total space in gb, used space in gb, free space in gb ]
|
56
|
+
def self.disk_usage
|
57
|
+
disk_usage=Hash.new
|
58
|
+
df=`df`.lines.grep(/^\/dev/)
|
59
|
+
df.each do |line|
|
60
|
+
line=line.split
|
61
|
+
name = line[5..-1].join(' ').chomp
|
62
|
+
usage_per = line[4].chop.to_i
|
63
|
+
total = (line[1].to_f/1048576).round 2
|
64
|
+
used = (line[2].to_f/1048576).round 2
|
65
|
+
available = (line[3].to_f/1048576).round 2
|
66
|
+
disk_usage[name]=[usage_per,total,used,available]
|
67
|
+
end
|
68
|
+
disk_usage
|
69
|
+
end
|
70
|
+
def self.ram_usage
|
71
|
+
usage=Hash.new
|
72
|
+
ram=`free`.lines
|
73
|
+
# [memory type]=[total, used] in Gb
|
74
|
+
usage[:ram]=[(ram[1].split[1].to_f/1048576).round(2),(ram[2].split[2].to_f/1048576).round(2)]
|
75
|
+
usage[:ram_per]=(100*(ram[2].split[2].to_f/1048576)/(ram[1].split[1].to_f/1048576)).round
|
76
|
+
usage[:swap]=[(ram[3].split[1].to_f/1048576).round(2),(ram[3].split[2].to_f/1048576).round(2)]
|
77
|
+
usage[:swap_per]=(100*(ram[3].split[2].to_f/1048576)/(ram[3].split[1].to_f/1048576)).round if ram[3].split[1].to_f!=0
|
78
|
+
usage
|
79
|
+
end
|
80
|
+
def self.traffic_stat
|
81
|
+
new_traffic=Hash.new
|
82
|
+
lines=IO.readlines('/proc/net/dev').grep(/:/)
|
83
|
+
lines.each do |line|
|
84
|
+
line=line.split
|
85
|
+
new_traffic[line[0].chop.to_sym]=[line[1].to_i,line[9].to_i] # [receive bytes, transmit bytes]
|
86
|
+
end
|
87
|
+
if @@old_traffic.size==0
|
88
|
+
@@old_traffic=new_traffic
|
89
|
+
end
|
90
|
+
speeds=Hash.new
|
91
|
+
time_diff=Time.new-@@old_time_for_traffic
|
92
|
+
@@old_time_for_traffic=Time.new
|
93
|
+
new_traffic.each do |interface,data|
|
94
|
+
down=data[0]-@@old_traffic[interface][0]
|
95
|
+
up=data[1]-@@old_traffic[interface][1]
|
96
|
+
speeds[interface]=[(down/1024/128/time_diff).round(2),(up/1024/128/time_diff).round(2)]
|
97
|
+
end
|
98
|
+
@@old_traffic=new_traffic
|
99
|
+
speeds
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
def self.update
|
104
|
+
@@cpu_stat_value=self.cpu_stat # run different long-time operations in different threads
|
105
|
+
Thread.new{
|
106
|
+
@@traffic_speed_value=self.traffic_stat
|
107
|
+
}
|
108
|
+
# network will be here
|
109
|
+
end
|
110
|
+
# operations of getting cpu load or network load take a few seconds
|
111
|
+
# we will calculate this values in another thread
|
112
|
+
# and just return values by this functions
|
113
|
+
def self.get_cpu_stat
|
114
|
+
@@cpu_stat_value
|
115
|
+
end
|
116
|
+
def self.get_traffic_speed
|
117
|
+
@@traffic_speed_value
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
require 'sinatra/base'
|
3
|
+
require 'json'
|
4
|
+
require 'date'
|
5
|
+
require 'sass'
|
6
|
+
|
7
|
+
require_relative 'info'
|
8
|
+
# require_relative 'controllers/assets'
|
9
|
+
# require_relative 'controllers/home'
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
class ServStateApp < Sinatra::Base
|
14
|
+
|
15
|
+
|
16
|
+
get '/' do
|
17
|
+
@name=Info.hostname
|
18
|
+
erb :index
|
19
|
+
end
|
20
|
+
|
21
|
+
get("/style.css") do
|
22
|
+
scss "css/style".to_sym
|
23
|
+
end
|
24
|
+
get '/renew.json' do
|
25
|
+
content_type :json
|
26
|
+
{ :cpu => Info.get_cpu_stat, :uptime => Info.uptime, :mem_usage => Info.ram_usage, :disks_usage => Info.disk_usage, :network => Info.get_traffic_speed }.to_json
|
27
|
+
end
|
28
|
+
end
|