perus 0.1.13 → 0.1.14

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: cba6a606d7b4de0dc9c1de7acf3f77b504ecc8e2
4
- data.tar.gz: ecfc89824684d7340e5dcad9c5a4c37c74f2242b
3
+ metadata.gz: 3df40bd6deb3e165e357bb4227dbe0b834d33bf5
4
+ data.tar.gz: 4c31499544a9d3e97bd3fb7e99308df0cbe4776f
5
5
  SHA512:
6
- metadata.gz: 5e0216550de7327f01a58a25facde55802f166532cd894930fdf422ca20eef908709f13e4952906cc9dc4994cc3f6054b38ce6d0332d7301572dbb2b2a682348
7
- data.tar.gz: bfe4830fbfe10f75c71fab1537a03d49ec52668f5e0b91bb74337c5bc8533e474622bf0bbdf472b1700f1fb596aee2d7dee129be64369305ff4f0e1de94a4dad
6
+ metadata.gz: 44f0105e7f52fb732e0effef6635ba31150af32db4daecee4e2e54b9618e2bec66c4ebd94a9854a32de21154b0b83342b54133698165ee0401e061482c28b56d
7
+ data.tar.gz: e08dce48e0555f801f3646b67de6489a0f44024409440e2f7a0bae229de4a7a304b644988104a2049fde254e3415948e123fb775442ab7d6041f867e746769c4
@@ -104,6 +104,7 @@ module Perus::Server
104
104
 
105
105
  get '/admin/stats' do
106
106
  @stats = Stats.new
107
+ @queue_length = Server.ping_queue.length
107
108
  erb :stats
108
109
  end
109
110
 
@@ -147,31 +148,30 @@ module Perus::Server
147
148
 
148
149
  # receive data from a client
149
150
  post '/systems/:id/ping' do
150
- Server.ping_queue.post do
151
- timestamp = Time.now.to_i
151
+ timestamp = Time.now.to_i
152
+ ping_params = params.dup
152
153
 
154
+ if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
155
+ system_ip = request.env['HTTP_X_FORWARDED_FOR']
156
+ else
157
+ system_ip = request.ip
158
+ end
159
+
160
+ Server.ping_queue << Proc.new do
153
161
  # update the system with its last known ip and update time
154
- system = System.with_pk!(params['id'])
162
+ system = System.with_pk!(ping_params['id'])
155
163
  system.last_updated = timestamp
156
-
157
- if request.ip == '127.0.0.1' && ENV['RACK_ENV'] == 'production'
158
- system.ip = request.env['HTTP_X_FORWARDED_FOR']
159
- else
160
- system.ip = request.ip
161
- end
164
+ system.ip = system_ip
165
+ system.save
162
166
 
163
167
  # errors is either nil or a hash of the format - module: [err, ...]
164
- system.save_metric_errors(params, timestamp)
168
+ system.save_metric_errors(ping_params, timestamp)
165
169
 
166
170
  # add each new value, a later process cleans up old values
167
- system.save_values(params, timestamp)
171
+ system.save_values(ping_params, timestamp)
168
172
 
169
173
  # save action return values and prevent them from running again
170
- system.save_actions(params, timestamp)
171
-
172
- # ip, last updated, uploads and metrics are now updated. these are
173
- # stored on the system.
174
- system.save
174
+ system.save_actions(ping_params, timestamp)
175
175
  end
176
176
 
177
177
  content_type :json
@@ -5,6 +5,7 @@ require 'concurrent'
5
5
  module Perus::Server
6
6
  module DB
7
7
  MAX_VACUUM_ATTEMPTS = 5
8
+ MAX_CLEAN_ATTEMPTS = 5
8
9
 
9
10
  def self.db
10
11
  @db
@@ -80,11 +81,29 @@ module Perus::Server
80
81
  # are removed from a system, the accompanying metric record is also
81
82
  # removed.
82
83
  cleanup_task = Concurrent::TimerTask.new do
83
- begin
84
- start = Time.now
85
- Perus::Server::DB.cleanup
86
- Stats.cleaned!(Time.now - start)
87
- rescue
84
+ attempts = 0
85
+ complete = false
86
+
87
+ while !complete && attempts < MAX_CLEAN_ATTEMPTS
88
+ begin
89
+ puts "Cleaning, attempt #{attempts + 1}"
90
+ start = Time.now
91
+ Perus::Server::DB.cleanup
92
+ Stats.cleaned!(Time.now - start)
93
+ complete = true
94
+ puts "Cleaning complete"
95
+
96
+ rescue
97
+ attempts += 1
98
+ if attempts < MAX_CLEAN_ATTEMPTS
99
+ puts "Clean failed, will reattempt after short sleep"
100
+ sleep(5)
101
+ end
102
+ end
103
+ end
104
+
105
+ if !complete
106
+ puts "Clean failed more than MAX_CLEAN_ATTEMPTS"
88
107
  Stats.cleaned!('failed')
89
108
  end
90
109
  end
@@ -98,12 +117,14 @@ module Perus::Server
98
117
  # cached so lookups can be done against the db, rather than running
99
118
  # each alert for each system on a page load.
100
119
  cache_alerts_task = Concurrent::TimerTask.new do
101
- begin
102
- start = Time.now
103
- Perus::Server::Alert.cache_active_alerts
104
- Stats.alerts_cached!(Time.now - start)
105
- rescue
106
- Stats.alerts_cached!('failed')
120
+ if Server.ping_queue.empty?
121
+ begin
122
+ start = Time.now
123
+ Perus::Server::Alert.cache_active_alerts
124
+ Stats.alerts_cached!(Time.now - start)
125
+ rescue
126
+ Stats.alerts_cached!('failed')
127
+ end
107
128
  end
108
129
  end
109
130
 
@@ -9,7 +9,6 @@ Sequel.migration do
9
9
  Integer :config_id
10
10
  String :links, text: true
11
11
  String :ip
12
- String :metrics, text: true
13
12
  Integer :last_updated
14
13
  end
15
14
  end
@@ -509,6 +509,7 @@ article.graph {
509
509
  }
510
510
 
511
511
  #actions-menu {
512
+ padding-bottom: 50px;
512
513
  }
513
514
 
514
515
  #actions-menu p {
@@ -1,4 +1,4 @@
1
- require 'concurrent'
1
+ require 'thread'
2
2
  require 'thin'
3
3
 
4
4
  DEFAULT_SERVER_OPTIONS = {
@@ -25,6 +25,21 @@ module Perus::Server
25
25
  # initialise/migrate the db and start cleanup/caching timers
26
26
  DB.start
27
27
  DB.start_timers
28
+
29
+ # ping data is processed in a thread pool
30
+ Thread.new do
31
+ while true
32
+ ping = Server.ping_queue.pop
33
+ begin
34
+ ping.call
35
+ rescue => e
36
+ puts e.inspect
37
+ if e.backtrace.is_a?(Array)
38
+ puts e.backtrace.join("\n") + "\n"
39
+ end
40
+ end
41
+ end
42
+ end
28
43
  end
29
44
 
30
45
  def run
@@ -36,16 +51,7 @@ module Perus::Server
36
51
  end
37
52
 
38
53
  def self.ping_queue
39
- # ping data is processed in a thread pool
40
- @ping_queue ||= Concurrent::ThreadPoolExecutor.new(
41
- min_threads: 2,
42
- max_threads: 2,
43
- max_queue: 0
44
- )
45
- end
46
-
47
- def self.shutdown
48
- @ping_queue.shutdown
54
+ @ping_queue ||= Queue.new
49
55
  end
50
56
 
51
57
  def self.options
@@ -1,5 +1,7 @@
1
1
  <h1>Background Stats</h1>
2
2
 
3
+ <p>Ping queue length: <%= @queue_length %></p>
4
+
3
5
  <h2 class="stats">Vacuuming</h2>
4
6
  <dl>
5
7
  <dt>Last Vacuum</dt>
@@ -1,3 +1,3 @@
1
1
  module Perus
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: perus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Will Cannings