city-watch 0.5.6 → 0.5.7

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- city-watch (0.5.5)
4
+ city-watch (0.5.7)
5
5
  rack
6
6
  rack-mount
7
7
  redis
@@ -1,7 +1,30 @@
1
1
  module DataSets
2
2
 
3
- def data_set(name,&block)
4
-
3
+ def dataset(name,&block)
4
+ @datasets ||= {}
5
+ @datasets[name] = block
6
+ end
7
+
8
+ def run_dataset_collector(dat)
9
+ @datasets.map do |(name,dataset)|
10
+ dataset.call(dat)
11
+ end if @datasets
12
+ end
13
+
14
+ def get_data_set(data_set_name,s_time,e_time=Time.now,host=host)
15
+ CityWatch.redis.zrevrangebyscore(data_set_key(data_set_name,host), s_time.to_i, e_time.to_i, :with_scores => true).map do |(val,score)|
16
+ timestamp,value = val.split(",")
17
+ [Time.at(timestamp.to_i),value]
18
+ end
19
+ end
20
+
21
+ def data_set_key(data_set_name,host=host)
22
+ CityWatch.redis.sadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::data_sets", data_set_name
23
+ "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::data_set::#{data_set_name}"
24
+ end
25
+
26
+ def add_to_data_set(data_set_name,val,time=Time.now,host=host)
27
+ CityWatch.redis.zadd data_set_key(data_set_name,host), time.to_i, "#{Time.now.to_i},#{val}"
5
28
  end
6
29
 
7
30
  end
@@ -4,7 +4,7 @@ module Rules
4
4
  @rules ||= {}
5
5
  @rules[name] = block
6
6
  end
7
-
7
+
8
8
  def run_rules(dat)
9
9
  @rules.map do |(name,rule)|
10
10
  rule.call(dat)
@@ -0,0 +1,15 @@
1
+ module Status
2
+
3
+ def set_status_var(var,val,host=host)
4
+ CityWatch.redis.hset "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::status", var, val
5
+ end
6
+
7
+ def status_vars(host=host)
8
+ CityWatch.redis.hgetall "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::status"
9
+ end
10
+
11
+ def status_var(var,host=host)
12
+ CityWatch.redis.hget "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::status", var
13
+ end
14
+
15
+ end
@@ -3,6 +3,7 @@ require 'city_watch/util/rules'
3
3
  require 'city_watch/util/flags'
4
4
  require 'city_watch/util/notifications'
5
5
  require 'city_watch/util/datasets'
6
+ require 'city_watch/util/status'
6
7
 
7
8
  module Watchman
8
9
 
@@ -21,6 +22,7 @@ module Watchman
21
22
  CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::summary", rcv_time, Yajl::Encoder.encode(sum)
22
23
  end
23
24
  run_rules(dat)
25
+ run_dataset_collector(dat)
24
26
  send_alerts!
25
27
  return 0, sum || nil
26
28
  end
@@ -59,6 +61,7 @@ module Watchman
59
61
  base.extend(Flags)
60
62
  base.extend(Notifications)
61
63
  base.extend(DataSets)
64
+ base.extend(Status)
62
65
  base.extend(ClassMethods)
63
66
  Watchmen.register(base)
64
67
  end
@@ -21,4 +21,8 @@ class DiskUsage
21
21
 
22
22
  end
23
23
 
24
+ dataset(:save_dataset) do |data|
25
+ add_to_data_set(:root_disk_usage,data[:summary].to_f)
26
+ end
27
+
24
28
  end
@@ -5,7 +5,7 @@ class SystemInfo
5
5
  require 'sysinfo'
6
6
 
7
7
  def self.data
8
- SysInfo.new.to_hash.merge({:summary => ["ipaddress_internal", "uptime"]})
8
+ SysInfo.new.to_hash.merge({:summary => ["ipaddress_internal"]})
9
9
  end
10
10
 
11
11
  end
@@ -2,9 +2,12 @@ class Uptime
2
2
 
3
3
  include Watchman
4
4
 
5
+ set_default :uptime_file, '/proc/uptime'
6
+
5
7
  def self.data
8
+ return {} if !File.exists?(option(:uptime_file))
6
9
  out = {}
7
- out[:uptime], out[:idle] = File.read('/proc/uptime').strip.split.map {|t| Float(t) }
10
+ out[:uptime], out[:idle] = File.read(option(:uptime_file)).strip.split.map {|t| Float(t) }
8
11
  base = out.dup
9
12
  [[:minutes,Proc.new{|t| t / 60 }],[:hours,Proc.new{|t| t / (60*60) }],[:days,Proc.new{|t| t / (60*60*24) }]].each do |(id,func)|
10
13
  base.each do |k,v|
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CityWatch
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: city-watch
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.6
5
+ version: 0.5.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bragg
@@ -134,6 +134,7 @@ files:
134
134
  - lib/city_watch/util/notifications.rb
135
135
  - lib/city_watch/util/rules.rb
136
136
  - lib/city_watch/util/run_command.rb
137
+ - lib/city_watch/util/status.rb
137
138
  - lib/city_watch/util/watchman.rb
138
139
  - lib/city_watch/watchmen.rb
139
140
  - lib/city_watch/watchmen/cpu_usage.rb