perus 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/perus/options.rb +7 -2
- data/lib/perus/pinger/command.rb +9 -2
- data/lib/perus/pinger/commands/upstart_start.rb +12 -0
- data/lib/perus/pinger/commands/upstart_stop.rb +12 -0
- data/lib/perus/pinger/metrics/running.rb +20 -0
- data/lib/perus/pinger/pinger.rb +1 -1
- data/lib/perus/pinger.rb +3 -0
- data/lib/perus/server/app.rb +6 -1
- data/lib/perus/server/db.rb +1 -1
- data/lib/perus/server/models/metric.rb +11 -0
- data/lib/perus/server/models/system.rb +5 -1
- data/lib/perus/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb71157c8e99e2d438be1de8effd475492a88e20
|
4
|
+
data.tar.gz: 937cae814206ed5fc94d1ef613d76881b1139247
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b29144c8a6f3b45bd0038dbfbeea93d52adde137368557dddf049c9a1faacfe2235c1a9c1e208e07634bf146024dfb3f4a06a672955df683122813af399a4942
|
7
|
+
data.tar.gz: 9cd259d515b06c7c25da09cfec9f7f133b337688afbcb883ee30263bb040bd42d75cf5602ca037a12d7b6a9cea0e2c4dff2c06619163cb71980618df9320d8ee
|
data/lib/perus/options.rb
CHANGED
@@ -2,7 +2,7 @@ require 'iniparse'
|
|
2
2
|
|
3
3
|
module Perus
|
4
4
|
class Options
|
5
|
-
def initialize
|
5
|
+
def initialize
|
6
6
|
@defaults = {}
|
7
7
|
end
|
8
8
|
|
@@ -12,7 +12,12 @@ module Perus
|
|
12
12
|
else
|
13
13
|
user_options = {}
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
|
+
# options are only one level deep, so resolve conflicts
|
17
|
+
# by just merging the two conflicting hashes again
|
18
|
+
@options = defaults.merge(user_options) do |key, default, user|
|
19
|
+
default.merge(user)
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
def method_missing(name, *params, &block)
|
data/lib/perus/pinger/command.rb
CHANGED
@@ -126,8 +126,15 @@ module Perus::Pinger
|
|
126
126
|
class ShellCommandError < StandardError; end
|
127
127
|
def shell(command)
|
128
128
|
out, err, status = Open3.capture3(command)
|
129
|
-
|
130
|
-
|
129
|
+
|
130
|
+
unless err.empty?
|
131
|
+
raise ShellCommandError.new(err.strip)
|
132
|
+
end
|
133
|
+
|
134
|
+
if status.exitstatus > 0
|
135
|
+
raise ShellCommandError.new("#{out.strip}; exit: #{status.exitstatus}")
|
136
|
+
end
|
137
|
+
|
131
138
|
out
|
132
139
|
end
|
133
140
|
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Perus::Pinger
|
2
|
+
class UpstartStart < Command
|
3
|
+
description 'Start the upstart job specified with "job". Valid values
|
4
|
+
for "job" are contained in the pinger config file.'
|
5
|
+
option :job, restricted: true
|
6
|
+
|
7
|
+
def run
|
8
|
+
result = shell("sudo start #{option.job}")
|
9
|
+
true # shell will capture any errors
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Perus::Pinger
|
2
|
+
class UpstartStop < Command
|
3
|
+
description 'Stop the upstart job specified with "job". Valid values
|
4
|
+
for "job" are contained in the pinger config file.'
|
5
|
+
option :job, restricted: true
|
6
|
+
|
7
|
+
def run
|
8
|
+
result = shell("sudo stop #{option.job}")
|
9
|
+
true # shell will capture any errors
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Perus::Pinger
|
2
|
+
class Running < Command
|
3
|
+
description 'Reports "yes" if "process_path" is running, "no"
|
4
|
+
otherwise. Valid values for "process_path" are contained
|
5
|
+
in the pinger config file.'
|
6
|
+
option :process_path, restricted: true
|
7
|
+
metric!
|
8
|
+
|
9
|
+
def run
|
10
|
+
begin
|
11
|
+
ps_result = shell("ps aux | grep -v grep | grep #{options.process_path}")
|
12
|
+
rescue ShellCommandError
|
13
|
+
ps_result = ''
|
14
|
+
end
|
15
|
+
|
16
|
+
metric_name = "#{File.basename(options.process_path)}_running"
|
17
|
+
{metric_name => ps_result.empty? ? 'no' : 'yes'}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/perus/pinger/pinger.rb
CHANGED
data/lib/perus/pinger.rb
CHANGED
@@ -15,6 +15,8 @@ module Perus
|
|
15
15
|
require './pinger/commands/upgrade'
|
16
16
|
require './pinger/commands/script'
|
17
17
|
require './pinger/commands/sleep'
|
18
|
+
require './pinger/commands/upstart_start'
|
19
|
+
require './pinger/commands/upstart_stop'
|
18
20
|
|
19
21
|
# metrics
|
20
22
|
require './pinger/metrics/chrome'
|
@@ -26,6 +28,7 @@ module Perus
|
|
26
28
|
require './pinger/metrics/temp'
|
27
29
|
require './pinger/metrics/value'
|
28
30
|
require './pinger/metrics/uptime'
|
31
|
+
require './pinger/metrics/running'
|
29
32
|
|
30
33
|
# pinger
|
31
34
|
require './pinger/pinger'
|
data/lib/perus/server/app.rb
CHANGED
@@ -147,7 +147,12 @@ module Perus::Server
|
|
147
147
|
# update the system with its last known ip and update time
|
148
148
|
system = System.with_pk!(params['id'])
|
149
149
|
system.last_updated = timestamp
|
150
|
-
|
150
|
+
|
151
|
+
if request.ip == '127.0.0.1'
|
152
|
+
system.ip = request.env['HTTP_X_FORWARDED_FOR']
|
153
|
+
else
|
154
|
+
system.ip = request.ip
|
155
|
+
end
|
151
156
|
|
152
157
|
# errors is either nil or a hash of the format - module: [err, ...]
|
153
158
|
system.save_metric_errors(params, timestamp)
|
data/lib/perus/server/db.rb
CHANGED
@@ -62,7 +62,7 @@ module Perus::Server
|
|
62
62
|
keep_hours = Server.options.keep_hours
|
63
63
|
|
64
64
|
# remove old values
|
65
|
-
min_timestamp = Time.now.to_i - (keep_hours * 60)
|
65
|
+
min_timestamp = Time.now.to_i - (keep_hours * 60 * 60)
|
66
66
|
values = Value.where("timestamp < #{min_timestamp}")
|
67
67
|
puts "Deleting #{values.count} values"
|
68
68
|
values.each(&:destroy)
|
@@ -32,6 +32,17 @@ module Perus::Server
|
|
32
32
|
system.values_dataset.where(metric: name)
|
33
33
|
end
|
34
34
|
|
35
|
+
def values_over_period(period)
|
36
|
+
raise 'invalid period' unless period.keys.include?(:hours)
|
37
|
+
min_timeout = Time.now.to_i - (period[:hours] * 60 * 60)
|
38
|
+
values_dataset.where("timestamp >= #{min_timeout}")
|
39
|
+
end
|
40
|
+
|
41
|
+
def num_values_over_period(period)
|
42
|
+
values = values_over_period(period)
|
43
|
+
values.map(&:num_value)
|
44
|
+
end
|
45
|
+
|
35
46
|
def after_destroy
|
36
47
|
super
|
37
48
|
File.unlink(path) if file && File.exists?(path)
|
@@ -94,7 +94,11 @@ module Perus::Server
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def latest(name)
|
97
|
-
values_dataset.where(metric: name).order_by(
|
97
|
+
values_dataset.where(metric: name.to_s).order_by(:timestamp).last
|
98
|
+
end
|
99
|
+
|
100
|
+
def metric(name)
|
101
|
+
metrics_dataset.where(name: name.to_s).first
|
98
102
|
end
|
99
103
|
|
100
104
|
|
data/lib/perus/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: perus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Cannings
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -214,11 +214,14 @@ files:
|
|
214
214
|
- lib/perus/pinger/commands/sleep.rb
|
215
215
|
- lib/perus/pinger/commands/upgrade.rb
|
216
216
|
- lib/perus/pinger/commands/upload.rb
|
217
|
+
- lib/perus/pinger/commands/upstart_start.rb
|
218
|
+
- lib/perus/pinger/commands/upstart_stop.rb
|
217
219
|
- lib/perus/pinger/metrics/chrome.rb
|
218
220
|
- lib/perus/pinger/metrics/cpu.rb
|
219
221
|
- lib/perus/pinger/metrics/hd.rb
|
220
222
|
- lib/perus/pinger/metrics/mem.rb
|
221
223
|
- lib/perus/pinger/metrics/process.rb
|
224
|
+
- lib/perus/pinger/metrics/running.rb
|
222
225
|
- lib/perus/pinger/metrics/screenshot.rb
|
223
226
|
- lib/perus/pinger/metrics/temp.rb
|
224
227
|
- lib/perus/pinger/metrics/uptime.rb
|