ServState 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78853b8c0e8801be6c3d102791077475493e17f8
4
- data.tar.gz: 5b57356325c26b54c3ed78ce1947dc0bc1ddaccc
3
+ metadata.gz: 8094d6f2af00a90fddbe2526287dbddbd1ec7069
4
+ data.tar.gz: f959f046a02048c93d73907c8eef2a9d70cc1e56
5
5
  SHA512:
6
- metadata.gz: 8718ae09e06c93252ed414af93c96c4d9bdb84d9a7103d90a85a5501ab38a2dbb6a2c5f7a2f0af7d80cb2ab5865b8ffec0d90abc426ff6051b254b147fc63a89
7
- data.tar.gz: c636ef88de14aeda491a7f21031affd57f557d1435fc583f51af4a0b5ed6576258b8361f9a03d6c2cfce9061d306361e164dfcfa1da883dec3da8cc870cbbe5e
6
+ metadata.gz: b2c6665fcf7529da5af4e07232fe40d0d8881061dafe89e47a35f58d0bbf0abc709b49b702a5b82a8fb214c3ab707fb25c31aa478955a2f6552edfc6825fe08e
7
+ data.tar.gz: 710eeca9e4c2a74aec668421331b959ca9d127653b47982f778fa6616df8cbdadfb4638696ad046acb2002d6aa10eb79249cefb2f86b63549bb812270dea994c
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # ServState
2
2
 
3
- Very simple tool to watch your LINUX server status.
3
+ Very simple tool to watch your LINUX server status.
4
+ [Demo page](http://162.243.90.233:8080/)
4
5
 
5
6
  ## Installation
6
7
 
@@ -8,8 +9,27 @@
8
9
 
9
10
  ## Usage
10
11
 
12
+ Defaults:
13
+ port is 8080
14
+ without password
15
+
16
+ Default:
17
+
11
18
  $ servstate
12
19
 
20
+ Set port:
21
+
22
+ $ servstate -port 8081
23
+
24
+ Set password:
25
+
26
+ $ servstate -pass mypass
27
+
28
+ Show help:
29
+
30
+ $ servstate -h
31
+
32
+
13
33
  ## Contributing
14
34
 
15
35
  1. Fork it
data/ServState.gemspec CHANGED
@@ -19,9 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
 
22
- spec.add_dependency "sinatra"
23
- spec.add_dependency "rack"
24
- spec.add_dependency "sass"
22
+ spec.add_dependency "sinatra", "~>1.4"
23
+ spec.add_dependency "rack", "~>1.5"
24
+ spec.add_dependency "sass", "~>3.2"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
27
27
  spec.add_development_dependency "rake"
data/bin/servstate CHANGED
@@ -1,9 +1,38 @@
1
1
  #!/usr/bin/env ruby
2
2
  require "rack"
3
3
  APP_ROOT = File.expand_path(File.dirname(__FILE__)) #пригодится
4
+
5
+ pass=false
6
+ port=8080
7
+
8
+ if ARGV.size==1 and (ARGV[0]=='-h' or ARGV[0]=='--help')
9
+ puts "ServState usage\nDefault port: 8080\nDefault password: no password\nSet port: -port XXXX\nSet password: -pass *****"
10
+ exit
11
+ end
12
+
13
+ if ARGV.size.odd?
14
+ puts "Something wrong with params"
15
+ exit
16
+ end
17
+
18
+ ARGV.each_slice(2) { |slice|
19
+ case slice[0]
20
+ when '-port'
21
+ port=slice[1].to_i
22
+ when '-pass'
23
+ pass=slice[1]
24
+ end
25
+ }
26
+
27
+ APP_OPTIONS={
28
+ password: pass,
29
+ port: port
30
+ }
31
+
4
32
  require_relative "./../lib/ServState.rb"
5
33
 
6
34
  #добавить настройки порта и прочее
35
+
7
36
  Thread.new{ # thread for calculate cpu and network load and other long time operations
8
37
  while true
9
38
  Info.update
@@ -11,11 +40,18 @@ Thread.new{ # thread for calculate cpu and network load and other long time oper
11
40
  end
12
41
  }
13
42
 
43
+
14
44
  puts " ____ ____ _ _ "
15
45
  puts "/ ___| ___ _ ____ __/ ___|| |_ __ _| |_ ___ "
16
46
  puts "\\___ \\ / _ \\ '__\\ \\ / /\\___ \\| __/ _` | __/ _ \\"
17
47
  puts " ___) | __/ | \\ V / ___) | || (_| | || __/"
18
48
  puts "|____/ \\___|_| \\_/ |____/ \\__\\__,_|\\__\\___|"
49
+ puts "\nPORT: #{port}"
50
+ if(pass)
51
+ puts "PASSWORD: #{pass}"
52
+ else
53
+ puts "WITHOUT PASSWORD"
54
+ end
19
55
  puts "\n"*3
20
56
 
21
- Rack::Handler::WEBrick.run ServStateApp
57
+ Rack::Handler::WEBrick.run(ServStateApp,:Port => APP_OPTIONS[:port])
@@ -3,6 +3,8 @@ class Info
3
3
  @@old_total_usage=0
4
4
  @@old_traffic=Hash.new
5
5
  @@old_time_for_traffic=Time.now
6
+ @@cpu_stat_value=0
7
+ @@traffic_speed_value=0
6
8
  def self.hostname
7
9
  `hostname`.chomp
8
10
  end
@@ -12,17 +12,50 @@ require_relative 'info'
12
12
 
13
13
  class ServStateApp < Sinatra::Base
14
14
 
15
+ enable :sessions
15
16
 
16
17
  get '/' do
17
- @name=Info.hostname
18
- erb :index
18
+ if session[:login] or not APP_OPTIONS[:password]
19
+ @name=Info.hostname
20
+ erb :index
21
+ else
22
+ redirect '/login'
23
+ end
19
24
  end
20
25
 
21
26
  get("/style.css") do
22
27
  scss "css/style".to_sym
23
28
  end
24
29
  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
30
+ if session[:login] or not APP_OPTIONS[:password]
31
+ content_type :json
32
+ { :cpu => Info.get_cpu_stat,
33
+ :uptime => Info.uptime,
34
+ :mem_usage => Info.ram_usage,
35
+ :disks_usage => Info.disk_usage,
36
+ :interfaces => Info.interfaces,
37
+ :network => Info.get_traffic_speed }.to_json
38
+ end
39
+ end
40
+
41
+ get '/login' do
42
+ unless(APP_OPTIONS[:password])
43
+ redirect '/'
44
+ end
45
+ session[:login]=false;
46
+ @name=Info.hostname
47
+ erb :login
48
+ end
49
+
50
+ post '/login' do
51
+ unless(APP_OPTIONS[:password])
52
+ redirect '/'
53
+ end
54
+ if(params[:pass])==APP_OPTIONS[:password]
55
+ session[:login]=true;
56
+ redirect '/'
57
+ else
58
+ redirect '/login'
59
+ end
27
60
  end
28
61
  end
@@ -21,29 +21,32 @@ $(document).ready(function() {
21
21
  function renew(){
22
22
  $.getJSON("renew.json",function(data){
23
23
  console.log(data);
24
- $('#uptime').text(data.uptime.days+' days '+data.uptime.hours+':'+data.uptime.minutes);
24
+ $('#uptime').text(data.uptime.days+' days '+data.uptime.hours+'h '+data.uptime.minutes+'m');
25
25
 
26
26
  $('#cpu_total').css('width',data.cpu+'%');
27
27
  $('#cpu_total').text(data.cpu+'%');
28
28
  danger('#cpu_total_handler',data.cpu);
29
29
 
30
30
  danger('#ram_usage_handler',data.mem_usage.ram_per);
31
+ $('#ram').text('('+data.mem_usage.ram[1]+'/'+data.mem_usage.ram[0]+')');
31
32
  $('#ram_usage').css('width',data.mem_usage.ram_per+'%');
32
33
  $('#ram_usage').text(data.mem_usage.ram_per+'%');
33
34
 
34
35
  danger('#swap_usage_handler',data.mem_usage.swap_per);
36
+ $('#swap').text('('+data.mem_usage.swap[1]+'/'+data.mem_usage.swap[0]+')');
35
37
  $('#swap_usage').css('width',data.mem_usage.swap_per+'%');
36
38
  $('#swap_usage').text(data.mem_usage.swap_per+'%');
37
39
 
38
40
  var disks=[]
39
41
  $.each(data.disks_usage, function(key, value){
40
- disks.push('<div class="uk-width-medium-1-2"><p>'+key+'</p><div class="uk-progress"><div class="uk-progress-bar" style="width: '+value[0]+'%">'+value[0]+'%</div></div></div>');
42
+ disks.push('<div class="uk-width-medium-1-2"><p>'+key+' <span class="uk-text-muted">('+value[2]+'/'+value[1]+')</span></p><div class="uk-progress"><div class="uk-progress-bar" style="width: '+value[0]+'%">'+value[0]+'%</div></div></div>');
41
43
  });
42
44
  $('#disks').html(disks.join(''));
43
45
 
44
46
  var interfaces=[]
45
47
  $.each(data.network, function(key, value){
46
- interfaces.push('<div class="uk-width-medium-1-4"><div class="uk-panel uk-panel-box"><p class="uk-text-bold">'+key+'</p><p class="uk-text-info">Down: '+value[0]+'Mbps</p><p class="uk-text-success">Up: '+value[1]+'Mbps</p></div></div>');
48
+ ip=(data.interfaces[key])?(data.interfaces[key]):('');
49
+ interfaces.push('<div class="uk-width-medium-1-4"><div class="uk-panel uk-panel-box"><p><span class="uk-text-bold">'+key+' </span><span id="ram" class="uk-text-muted">'+ip+'</span></p><p class="uk-text-info">Down: '+value[0]+'Mbps</p><p class="uk-text-success">Up: '+value[1]+'Mbps</p></div></div>');
47
50
  });
48
51
  $('#traffic').html(interfaces.join(''));
49
52
  });
@@ -1,3 +1,3 @@
1
1
  module ServState
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -13,3 +13,8 @@
13
13
  .uk-panel {
14
14
  margin-bottom: 10px;
15
15
  }
16
+ .login {
17
+ width: 200px;
18
+ height: 100px;
19
+ margin: 0 auto;
20
+ }
@@ -1,9 +1,9 @@
1
1
  <!doctype html>
2
2
  <html>
3
3
  <head>
4
- <title>Test Wrapper Page</title>
4
+ <title><%=@name %></title>
5
5
  <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6
- <script type="text/javascript" src="js/uikit.js"></script>
6
+ <script type="text/javascript" src="js/uikit.min.js"></script>
7
7
  <link rel="stylesheet" href="css/uikit.gradient.min.css">
8
8
 
9
9
  <!-- Custom includes -->
@@ -21,8 +21,6 @@
21
21
  <div class="uk-width-medium-1-2">
22
22
  <h4>Uptime</h4>
23
23
  <p id="uptime"></p>
24
- </div>
25
- <div class="uk-width-medium-1-2">
26
24
  <h4>CPU usage</h4>
27
25
  <div class="uk-progress" id="cpu_total_handler">
28
26
  <div class="uk-progress-bar" id="cpu_total" style="width: 0%"></div>
@@ -30,11 +28,11 @@
30
28
  </div>
31
29
  <div class="uk-width-medium-1-2">
32
30
  <h4>Memory usage</h4>
33
- <p>Ram</p>
31
+ <p>RAM <span id="ram" alt="(used/total)" class="uk-text-muted"></span></p>
34
32
  <div class="uk-progress" id="ram_usage_handler">
35
33
  <div class="uk-progress-bar" id="ram_usage" style="width: 0%"></div>
36
34
  </div>
37
- <p>Swap</p>
35
+ <p>Swap <span id="swap" class="uk-text-muted"></span></p>
38
36
  <div class="uk-progress">
39
37
  <div class="uk-progress-bar" id="swap_usage" style="width: 0%"></div>
40
38
  </div>
@@ -0,0 +1,25 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title><%=@name %> login</title>
5
+ <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
6
+ <script type="text/javascript" src="js/uikit.min.js"></script>
7
+ <link rel="stylesheet" href="css/uikit.gradient.min.css">
8
+
9
+ <!-- Custom includes -->
10
+ <script type="text/javascript" src="js/app.js"></script>
11
+ <link rel="stylesheet" href="style.css">
12
+ </head>
13
+ <body>
14
+
15
+ <div class="login uk-panel uk-panel-box">
16
+ <form class="uk-form" method="post">
17
+ <legend>Login to ServState</legend>
18
+ <fieldset>
19
+ <input type="password" name="pass" class="uk-width-1-1 uk-form-large" placeholder="password">
20
+ </fieldset>
21
+ </form>
22
+ </div>
23
+
24
+ </body>
25
+ </html>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ServState
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Sergienko
@@ -9,50 +9,50 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-25 00:00:00.000000000 Z
12
+ date: 2013-11-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: '0'
20
+ version: '1.4'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - '>='
25
+ - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: '0'
27
+ version: '1.4'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rack
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - '>='
32
+ - - ~>
33
33
  - !ruby/object:Gem::Version
34
- version: '0'
34
+ version: '1.5'
35
35
  type: :runtime
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - '>='
39
+ - - ~>
40
40
  - !ruby/object:Gem::Version
41
- version: '0'
41
+ version: '1.5'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: sass
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - '>='
46
+ - - ~>
47
47
  - !ruby/object:Gem::Version
48
- version: '0'
48
+ version: '3.2'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - '>='
53
+ - - ~>
54
54
  - !ruby/object:Gem::Version
55
- version: '0'
55
+ version: '3.2'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -100,24 +100,19 @@ files:
100
100
  - lib/ServState.rb
101
101
  - lib/ServState/info.rb
102
102
  - lib/ServState/main.rb
103
- - lib/ServState/public/css/uikit.almost-flat.css
104
- - lib/ServState/public/css/uikit.almost-flat.min.css
105
- - lib/ServState/public/css/uikit.css
106
- - lib/ServState/public/css/uikit.gradient.css
107
103
  - lib/ServState/public/css/uikit.gradient.min.css
108
- - lib/ServState/public/css/uikit.min.css
109
104
  - lib/ServState/public/fonts/FontAwesome.otf
110
105
  - lib/ServState/public/fonts/fontawesome-webfont.eot
111
106
  - lib/ServState/public/fonts/fontawesome-webfont.ttf
112
107
  - lib/ServState/public/fonts/fontawesome-webfont.woff
113
108
  - lib/ServState/public/js/app.js
114
- - lib/ServState/public/js/uikit.js
115
109
  - lib/ServState/public/js/uikit.min.js
116
110
  - lib/ServState/version.rb
117
111
  - lib/ServState/views/css/base.scss
118
112
  - lib/ServState/views/css/custom.scss
119
113
  - lib/ServState/views/css/style.scss
120
114
  - lib/ServState/views/index.erb
115
+ - lib/ServState/views/login.erb
121
116
  homepage: http://github.com/ololyay/ServState
122
117
  licenses:
123
118
  - MIT