server-status 1.0 → 1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: af20ee25a465ed5e45e9a0018dcacb9afc3f94e4
4
- data.tar.gz: 3110214e2c5ce45799d213a9e97505b5ce82dd6a
3
+ metadata.gz: c631120c269c1d0110d0874751628df18aba72ae
4
+ data.tar.gz: e4aa38bb8bfd2b05c69428ec316263f52255427b
5
5
  SHA512:
6
- metadata.gz: c7c22c4d49b1c6fee75812769db130051a98406729dcc39e96c508e535e06c35bc93a4a64dd2821be07790a47e32ce722f41ea964d8fcbce4d99d30b411547c9
7
- data.tar.gz: be97a5537f8c72f8d570fbdab9c8d945baa5aef74f96a85616ba48a58448bdc6899452f8e105579d4f0683e71f3273d1adaa4257f6bc55c7cbedc910a85e8421
6
+ metadata.gz: fe9874cf9a45db31b80cc4a58ebd477e9a6c8401d677b74922fc74af003207f5eba7c835e497935ca36ea1df016887fc58e3062bf186f1086954a382ba3df0c4
7
+ data.tar.gz: 211d71252fe2d10305fcb4d498810500ac773cea7b88780004b422947a663e4c0c69d40b3c5f298eac1d474b9a8e5d12a74aec9973c283f27b47d120d4c4faee
data/README.md CHANGED
@@ -1,11 +1,13 @@
1
1
  # Server Status
2
2
 
3
- [![Code Climate](https://codeclimate.com/github/jamesbrooks/server-status.png)](https://codeclimate.com/github/JamesBrooks/git-runner)
4
- [![Gem Version](https://badge.fury.io/rb/server-status.png)](http://badge.fury.io/rb/git-runner)
5
- [![Dependency Status](https://gemnasium.com/jamesbrooks/server-status.png)](https://gemnasium.com/JamesBrooks/git-runner)
3
+ [![Code Climate](https://codeclimate.com/github/jamesbrooks/server-status/badges/gpa.svg)](https://codeclimate.com/github/jamesbrooks/server-status)
4
+ [![Gem Version](https://badge.fury.io/rb/server-status.svg)](http://badge.fury.io/rb/server-status)
5
+ [![Dependency Status](https://gemnasium.com/jamesbrooks/server-status.svg)](https://gemnasium.com/JamesBrooks/server-status)
6
6
 
7
7
  Command line tool for quickly fetching and displaying vital host metrics.
8
8
 
9
+ ![Screnshot](https://raw.github.com/jamesbrooks/server-status/master/screenshot.jpg)
10
+
9
11
  ## Installation
10
12
 
11
13
  `gem install server-status`
data/lib/server-status.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'open3'
2
2
  require 'commander'
3
3
  require 'colorize'
4
+ require 'tty-progressbar'
4
5
 
5
6
  require 'server-status/version'
6
7
  require 'server-status/application'
@@ -27,6 +27,7 @@ module ServerStatus
27
27
  c.option '--[no-]disk-usage'
28
28
  c.option '--[no-]inode-usage'
29
29
  c.option '--[no-]memory-usage'
30
+ c.option '--[no-]clock-drift'
30
31
  c.option '--[no-]package-updates'
31
32
  c.option '--[no-]reboot-required'
32
33
 
@@ -38,6 +39,7 @@ module ServerStatus
38
39
  disk_usage: true,
39
40
  inode_usage: true,
40
41
  memory_usage: true,
42
+ clock_drift: true,
41
43
  package_updates: true,
42
44
  reboot_required: true
43
45
  }.merge(@config.options))
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module ServerStatus
2
4
  class HostSet
3
5
  attr_accessor :config, :options, :hosts
@@ -10,9 +12,14 @@ module ServerStatus
10
12
  end
11
13
 
12
14
  def fetch_statuses
15
+ progress_bar = TTY::ProgressBar.new("Querying hosts [:bar]", total: @hosts.size, clear: true, hide_cursor: true)
16
+ semaphore = Mutex.new
17
+ completed_hosts = 0
18
+
13
19
  threads = @hosts.map do |host|
14
20
  Thread.new do
15
21
  host.fetch_status(status_command)
22
+ semaphore.synchronize { progress_bar.advance }
16
23
  end
17
24
  end
18
25
 
@@ -12,15 +12,14 @@ module ServerStatus
12
12
  def generate_table
13
13
  str = "\n"
14
14
 
15
- # Report any failures
16
- if (failed_hosts = @host_set.hosts.reject(&:feteched_status?)).any?
17
- failed_hosts.each do |host|
18
- str << "Failure #{host.name} - #{host.status[:error]}\n".colorize(:red)
15
+ # Gather failures
16
+ failed_columns = if (failed_hosts = @host_set.hosts.reject(&:feteched_status?)).any?
17
+ failed_hosts.map do |host|
18
+ { name: host.name, error: host.status[:error].strip }
19
19
  end
20
-
21
- str << "\n"
22
20
  end
23
21
 
22
+
24
23
  columns = [ :host ] + @host_set.hosts.detect(&:feteched_status?).status.keys
25
24
 
26
25
  # Process status values
@@ -58,6 +57,18 @@ module ServerStatus
58
57
  str << "\n"
59
58
  end
60
59
 
60
+ # Display failures at the end
61
+ if failed_columns
62
+ str << "\nFAILED HOSTS".colorize(:blue)
63
+ str << "\n"
64
+ failed_columns.each do |host|
65
+ str << host[:name]
66
+ str << ' ' * (COLUMN_SPACING + column_widths[:host] - host[:name].uncolorize.size)
67
+ str << host[:error].colorize(:red)
68
+ str << "\n"
69
+ end
70
+ end
71
+
61
72
  str << "\n"
62
73
  str
63
74
  end
@@ -90,6 +101,25 @@ module ServerStatus
90
101
  format_percentage(used / (used + available))
91
102
  end
92
103
 
104
+ def format_clock_drift(val)
105
+ if val == ""
106
+ return "??? ms".colorize(:red)
107
+ end
108
+
109
+ # Drift in milliseconds
110
+ drift = (val.to_f * 1000).round
111
+
112
+ color = if drift.abs < 2000
113
+ :normal
114
+ elsif drift.abs < 30_000
115
+ :yellow
116
+ else
117
+ :red
118
+ end
119
+
120
+ "#{drift} ms".colorize(color)
121
+ end
122
+
93
123
  def format_package_updates(val)
94
124
  str = ''
95
125
 
@@ -5,7 +5,6 @@ module ServerStatus
5
5
 
6
6
  def initialize(options)
7
7
  @options = options
8
- @parts = []
9
8
  end
10
9
 
11
10
  def requested_options
@@ -13,39 +12,45 @@ module ServerStatus
13
12
  end
14
13
 
15
14
  def to_script
15
+ parts = []
16
+
16
17
  if @options.os
17
- @parts << "lsb_release -d | cut -f2"
18
+ parts << "lsb_release -d | cut -f2"
18
19
  end
19
20
 
20
21
  if @options.uptime
21
- @parts << "cat /proc/uptime | cut -d\" \" -f1"
22
+ parts << "cat /proc/uptime | cut -d\" \" -f1"
22
23
  end
23
24
 
24
25
  if @options.load
25
- @parts << "cat /proc/loadavg | cut -d\" \" -f -3"
26
+ parts << "cat /proc/loadavg | cut -d\" \" -f -3"
26
27
  end
27
28
 
28
29
  if @options.disk_usage
29
- @parts << "df -h | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
30
+ parts << "df -h | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
30
31
  end
31
32
 
32
33
  if @options.inode_usage
33
- @parts << "df -hi | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
34
+ parts << "df -hi | awk '/\\/$/' | sed 's/ \\+/ /g' | cut -d\" \" -f5"
34
35
  end
35
36
 
36
37
  if @options.memory_usage
37
- @parts << "free -m | sed -n 3p | sed 's/ \\+/ /g' | cut -d\" \" -f 3-"
38
+ parts << "free -m | sed -n 3p | sed 's/ \\+/ /g' | cut -d\" \" -f 3-"
39
+ end
40
+
41
+ if @options.clock_drift
42
+ parts << "ntpdate -q pool.ntp.org | head -1 | cut -d \" \" -f 6 | sed \"s/.$//\""
38
43
  end
39
44
 
40
45
  if @options.package_updates
41
- @parts << "cat /var/lib/update-notifier/updates-available 2>/dev/null"
46
+ parts << "cat /var/lib/update-notifier/updates-available 2>/dev/null"
42
47
  end
43
48
 
44
49
  if @options.reboot_required
45
- @parts << "if [ -f /var/run/reboot-required ]; then echo 1 ; fi"
50
+ parts << "if [ -f /var/run/reboot-required ]; then echo 1 ; fi"
46
51
  end
47
52
 
48
- @parts.join("\necho '#{SEPARATOR}'\n")
53
+ parts.join("\necho '#{SEPARATOR}'\n")
49
54
  end
50
55
  end
51
56
  end
@@ -1,3 +1,3 @@
1
1
  module ServerStatus
2
- VERSION = '1.0'
2
+ VERSION = '1.1'
3
3
  end
data/screenshot.jpg ADDED
Binary file
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_dependency "commander", "~> 4.3"
21
21
  spec.add_dependency "colorize", "~> 0.7.7"
22
+ spec.add_dependency "tty-progressbar", "~> 0.10.1"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.11"
24
25
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: server-status
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2017-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.7.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: tty-progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.10.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.10.1
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,7 @@ files:
94
108
  - lib/server-status/report.rb
95
109
  - lib/server-status/status_command.rb
96
110
  - lib/server-status/version.rb
111
+ - screenshot.jpg
97
112
  - server-status.gemspec
98
113
  homepage: https://github.com/jamesbrooks/server-status
99
114
  licenses: []
@@ -114,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
129
  version: '0'
115
130
  requirements: []
116
131
  rubyforge_project:
117
- rubygems_version: 2.5.1
132
+ rubygems_version: 2.6.10
118
133
  signing_key:
119
134
  specification_version: 4
120
135
  summary: Command line tool for quickly fetching and displaying vital host metrics