check-cpu-steal 0.1.2 → 0.1.3
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 +4 -4
- data/lib/check_cpu_steal/cpu_stats.rb +35 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7483a2285198b7845e8811a1efa9439122a95d0
|
4
|
+
data.tar.gz: dd64bdea0b4078dc540d4ce17a3ed6ecb3e5904a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a7a06ecd792cb9e6099f664a94ced743a60d86fdf9098df67b59c3b9d258f6fb3d97f49603561f44dc7a64ec4457cd2574ac45ae004373ffc7e7fdb5f423fda
|
7
|
+
data.tar.gz: 23ed05f179bf9aa491edf4ab181c7b86d2ca4842ba2822c62b80957b8025a2ef85886001b2ced253af343cd471abbe3be2e71116f13cf927a094ba2363930a32
|
@@ -0,0 +1,35 @@
|
|
1
|
+
#
|
2
|
+
# Stat collection and calculation
|
3
|
+
#
|
4
|
+
class CpuStats
|
5
|
+
CLASSES = [:user, :nice, :system, :idle, :iowait, :irq,
|
6
|
+
:softirq, :steal, :guest, :guest_nice].freeze
|
7
|
+
|
8
|
+
def initialize(sleep_time = 5)
|
9
|
+
@now = stats
|
10
|
+
sleep sleep_time
|
11
|
+
@later = stats
|
12
|
+
@now[:total] = @now.values.inject(:+)
|
13
|
+
@later[:total] = @later.values.inject(:+)
|
14
|
+
end
|
15
|
+
|
16
|
+
def read_proc(file = '/proc/stat')
|
17
|
+
File.foreach(file).first
|
18
|
+
end
|
19
|
+
|
20
|
+
def stats
|
21
|
+
info = read_proc
|
22
|
+
stats = info.split(/\s+/)
|
23
|
+
stats.shift
|
24
|
+
stats.map(&:to_f)
|
25
|
+
Hash[CLASSES.zip(stats)]
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_stat_diff(stat_name)
|
29
|
+
@later[stat_name] - @now[stat_name]
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_stat_pct(stat_name)
|
33
|
+
get_stat_diff[stat_name] / get_stat_diff[:total]
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: check-cpu-steal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Flippin
|
@@ -73,6 +73,7 @@ executables:
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- lib/check_cpu_steal/cpu_stats.rb
|
76
77
|
- bin/check_cpu_steal.rb
|
77
78
|
homepage: https://github.com/opentable/check-cpu-steal
|
78
79
|
licenses:
|