perus 0.1.9 → 0.1.10
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/perus/pinger/commands/kill_process.rb +1 -1
- data/lib/perus/pinger/pinger.rb +15 -12
- data/lib/perus/server/app.rb +15 -6
- data/lib/perus/server/models/metric.rb +8 -2
- data/lib/perus/server/models/system.rb +8 -0
- data/lib/perus/server/views/systems/form.erb +1 -0
- data/lib/perus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4c31e7e80547a4efe91311c2f149e943eb52ea4
|
4
|
+
data.tar.gz: 676cbbb27a25a6a2778e540cb9c9641ee0c07601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5926cc09e9a6267fc6b00d6a6449791c464431a55446624dd56a51ba8b35f5cf1e56e38202bf53d712fa31806dc9ba329e43f8193e7b71195f08f9713d167d8
|
7
|
+
data.tar.gz: 3dfd536f991cf0f7b125901fea602361b667027a6a1e36ff76353798ae5e2e4abe3204480a933f7ce6fba7159c83ddfe3dd818b383c629ef579c0420e49f83e0
|
@@ -3,7 +3,7 @@ module Perus::Pinger
|
|
3
3
|
description 'Kills all instances of a process. Valid values for
|
4
4
|
"process_name" are contained in the pinger config file.'
|
5
5
|
option :process_name, restricted: true
|
6
|
-
option :signal, default: '
|
6
|
+
option :signal, default: 'TERM'
|
7
7
|
|
8
8
|
def run
|
9
9
|
result = shell("killall -#{options.signal} #{options.process_name}")
|
data/lib/perus/pinger/pinger.rb
CHANGED
@@ -6,7 +6,6 @@ require 'uri'
|
|
6
6
|
|
7
7
|
DEFAULT_PINGER_OPTIONS = {
|
8
8
|
'__anonymous__' => {
|
9
|
-
'system_id' => 1,
|
10
9
|
'server' => 'http://127.0.0.1:3000/'
|
11
10
|
},
|
12
11
|
|
@@ -72,15 +71,7 @@ module Perus::Pinger
|
|
72
71
|
|
73
72
|
def initialize(options_path = DEFAULT_PINGER_OPTIONS_PATH)
|
74
73
|
Pinger.options.load(options_path, DEFAULT_PINGER_OPTIONS)
|
75
|
-
|
76
|
-
# cache urls on initialisation since the urls depend on values known
|
77
|
-
# at startup and that won't change over the object lifetime
|
78
|
-
config_path = URI("systems/#{Pinger.options.system_id}/config")
|
79
|
-
pinger_path = URI("systems/#{Pinger.options.system_id}/ping")
|
80
|
-
server_uri = URI(Pinger.options.server)
|
81
|
-
|
82
|
-
@config_url = (server_uri + config_path).to_s
|
83
|
-
@pinger_url = (server_uri + pinger_path).to_s
|
74
|
+
@server_uri = URI(Pinger.options.server)
|
84
75
|
|
85
76
|
@metrics = []
|
86
77
|
@metric_results = {}
|
@@ -103,10 +94,19 @@ module Perus::Pinger
|
|
103
94
|
# configuration
|
104
95
|
#----------------------
|
105
96
|
def load_config
|
97
|
+
if Pinger.options.system_id.nil?
|
98
|
+
config_path = URI("systems/config_for_ip")
|
99
|
+
else
|
100
|
+
config_path = URI("systems/#{Pinger.options.system_id}/config")
|
101
|
+
end
|
102
|
+
|
103
|
+
config_url = (@server_uri + config_path).to_s
|
104
|
+
|
106
105
|
# load the system config by requesting it from the perus server
|
107
|
-
json = JSON.parse(RestClient.get(
|
106
|
+
json = JSON.parse(RestClient.get(config_url))
|
108
107
|
json['metrics'] ||= []
|
109
108
|
json['actions'] ||= []
|
109
|
+
@system_id = json['id']
|
110
110
|
|
111
111
|
# load metric and command modules based on the config
|
112
112
|
json['metrics'].each do |config|
|
@@ -207,8 +207,11 @@ module Perus::Pinger
|
|
207
207
|
@metric_errors.reject! {|metric, errors| errors.empty?}
|
208
208
|
add_to_payload(payload, 'metric_errors', @metric_errors)
|
209
209
|
|
210
|
+
pinger_path = URI("systems/#{@system_id}/ping")
|
211
|
+
pinger_url = (@server_uri + pinger_path).to_s
|
212
|
+
|
210
213
|
begin
|
211
|
-
RestClient.post(
|
214
|
+
RestClient.post(pinger_url, payload)
|
212
215
|
rescue => e
|
213
216
|
puts 'Ping failed with exception'
|
214
217
|
puts format_exception(e)
|
data/lib/perus/server/app.rb
CHANGED
@@ -148,7 +148,7 @@ module Perus::Server
|
|
148
148
|
system = System.with_pk!(params['id'])
|
149
149
|
system.last_updated = timestamp
|
150
150
|
|
151
|
-
if request.ip == '127.0.0.1'
|
151
|
+
if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
|
152
152
|
system.ip = request.env['HTTP_X_FORWARDED_FOR']
|
153
153
|
else
|
154
154
|
system.ip = request.ip
|
@@ -173,12 +173,21 @@ module Perus::Server
|
|
173
173
|
# system config
|
174
174
|
get '/systems/:id/config' do
|
175
175
|
system = System.with_pk!(params['id'])
|
176
|
-
config = {
|
177
|
-
metrics: system.config.metric_hashes,
|
178
|
-
actions: system.pending_actions.map(&:config_hash).flatten
|
179
|
-
}
|
180
176
|
content_type :json
|
181
|
-
|
177
|
+
system.config_hash.to_json
|
178
|
+
end
|
179
|
+
|
180
|
+
# config of system based on request ip
|
181
|
+
get '/systems/config_for_ip' do
|
182
|
+
if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
|
183
|
+
ip = request.env['HTTP_X_FORWARDED_FOR']
|
184
|
+
else
|
185
|
+
ip = request.ip
|
186
|
+
end
|
187
|
+
|
188
|
+
system = System.where(ip: ip).first
|
189
|
+
content_type :json
|
190
|
+
system.config_hash.to_json
|
182
191
|
end
|
183
192
|
|
184
193
|
# render all errors in html to replace the shortened subset on the system page
|
@@ -33,8 +33,14 @@ module Perus::Server
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def values_over_period(period)
|
36
|
-
|
37
|
-
|
36
|
+
if period.keys.include?(:hours)
|
37
|
+
min_timeout = Time.now.to_i - (period[:hours] * 60 * 60)
|
38
|
+
elsif period.keys.include?(:mins)
|
39
|
+
min_timeout = Time.now.to_i - (period[:mins] * 60)
|
40
|
+
else
|
41
|
+
raise 'invalid period - must be :hours or :mins'
|
42
|
+
end
|
43
|
+
|
38
44
|
values_dataset.where("timestamp >= #{min_timeout}")
|
39
45
|
end
|
40
46
|
|
@@ -52,6 +52,14 @@ module Perus::Server
|
|
52
52
|
pending_actions.collect(&:config_hashes).flatten
|
53
53
|
end
|
54
54
|
|
55
|
+
def config_hash
|
56
|
+
{
|
57
|
+
id: id,
|
58
|
+
metrics: config.metric_hashes,
|
59
|
+
actions: pending_actions.map(&:config_hash).flatten
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
55
63
|
|
56
64
|
# ---------------------------------------
|
57
65
|
# metrics
|
data/lib/perus/version.rb
CHANGED