city-watch 0.5.3 → 0.5.4

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.2)
4
+ city-watch (0.5.3)
5
5
  rack
6
6
  rack-mount
7
7
  redis
@@ -1,3 +1,4 @@
1
+ :debug: true
1
2
  :unicorn:
2
3
  :port: 62001
3
4
  :redis:
@@ -1,3 +1,4 @@
1
+ :debug: true
1
2
  :unicorn:
2
3
  :port: 62002
3
4
  :redis:
@@ -9,9 +9,9 @@ class Server
9
9
  Watchmen.each do |watchman|
10
10
  flags = watchman.get_flags(server)
11
11
  alerts = watchman.get_alerts(server,2)
12
- if (flags && flags.keys.count > 0) || (alerts && alerts.count > 0)
12
+ if (flags && flags.count > 0) || (alerts && alerts.count > 0)
13
13
  output << "<h3>" << watchman.name.to_s << "</h3><ul>"
14
- if flags && flags.keys.count > 0
14
+ if flags && flags.count > 0
15
15
  output << "<li class=\"alert\"><strong>Flags:</strong> <pre><code>" << Yajl::Encoder.encode(flags,:pretty => true, :indent => " ") << "</code></pre></li>"
16
16
  end
17
17
  if alerts && alerts.count > 0
@@ -0,0 +1,36 @@
1
+ module Alerts
2
+ module ClassMethods
3
+
4
+ def send_alert(message,dat=nil)
5
+ CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time})
6
+ end
7
+
8
+ def alerts
9
+ @alerts ||= []
10
+ if block_given?
11
+ @alerts.each do |a|
12
+ yield a
13
+ end
14
+ else
15
+ @alerts
16
+ end
17
+ nil
18
+ end
19
+
20
+ def get_alerts(host=host,num=5)
21
+ CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1
22
+ end
23
+
24
+ def send_alerts!
25
+ get_alerts.map do |alert|
26
+ puts "Alert: #{alert.inspect}" if CityWatch.debug?
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+ def self.included(base)
33
+ base.extend(ClassMethods)
34
+ end
35
+
36
+ end
@@ -36,7 +36,8 @@ module Collector
36
36
 
37
37
  data[:watchmen].each do |watchman,dat|
38
38
  if watch_obj = Watchmen.get(watchman)
39
- status, summary[watchman] = watch_obj.process(dat,rcv_time,host)
39
+ status, sum = watch_obj.process(dat,rcv_time,host)
40
+ summary[watchman] = sum if sum
40
41
  end
41
42
  end
42
43
 
@@ -0,0 +1,63 @@
1
+ module Flags
2
+ module ClassMethods
3
+
4
+ def set_flag(name)
5
+ unless get_flag(name)
6
+ flag_flapped name, :on
7
+ CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 1
8
+ end
9
+ end
10
+
11
+ def clear_flag(name)
12
+ if get_flag(name)
13
+ flag_flapped name, :off
14
+ CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 0
15
+ end
16
+ end
17
+
18
+ def flag_flapped(name,new_val)
19
+ puts "Flag flipped: #{name} -> #{new_val}" if CityWatch.debug?
20
+ end
21
+
22
+ def get_flag(name,host=host)
23
+ @host = host
24
+ CityWatch.redis.getbit("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name)) == 1 ? true : false
25
+ end
26
+
27
+ def get_flags(host=host)
28
+ @host = host
29
+ out = []
30
+ map = flag_map
31
+ map.each_index do |idx|
32
+ out << map[idx] if get_flag(map[idx])
33
+ end
34
+ out
35
+ end
36
+
37
+ def flag_map_key
38
+ "#{CityWatch.config[:prefix]}::#{self.name}::flag_map"
39
+ end
40
+
41
+ def flag_map
42
+ CityWatch.redis.lrange flag_map_key, 0, -1
43
+ end
44
+
45
+ def flag_position(name)
46
+ if (map = flag_map) && map.include?(name.to_s)
47
+ map.index(name.to_s)
48
+ else
49
+ new_flag(name)
50
+ end
51
+ end
52
+
53
+ def new_flag(name)
54
+ CityWatch.redis.rpush(flag_map_key, name) - 1
55
+ end
56
+
57
+ end
58
+
59
+ def self.included(base)
60
+ base.extend(ClassMethods)
61
+ end
62
+
63
+ end
@@ -0,0 +1,21 @@
1
+ module Rules
2
+ module ClassMethods
3
+
4
+ def add_rule(name,&block)
5
+ @rules ||= {}
6
+ @rules[name] = block
7
+ end
8
+
9
+ def run_rules(dat)
10
+ @rules.map do |(name,rule)|
11
+ rule.call(dat)
12
+ end if @rules
13
+ end
14
+
15
+ end
16
+
17
+ def self.included(base)
18
+ base.extend(ClassMethods)
19
+ end
20
+
21
+ end
@@ -1,3 +1,7 @@
1
+ require 'city_watch/util/alerts'
2
+ require 'city_watch/util/rules'
3
+ require 'city_watch/util/flags'
4
+
1
5
  module Watchman
2
6
 
3
7
  def data
@@ -15,6 +19,7 @@ module Watchman
15
19
  CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::summary", rcv_time, Yajl::Encoder.encode(sum)
16
20
  end
17
21
  run_rules(dat)
22
+ send_alerts!
18
23
  return 0, sum || nil
19
24
  end
20
25
 
@@ -26,97 +31,6 @@ module Watchman
26
31
  @rcv_time || Time.now.to_i
27
32
  end
28
33
 
29
- def add_rule(name,&block)
30
- @rules ||= {}
31
- @rules[name] = block
32
- end
33
-
34
- def run_rules(dat)
35
- @rules.map do |(name,rule)|
36
- rule.call(dat)
37
- end if @rules
38
- end
39
-
40
- def send_alert(message,dat=nil)
41
- CityWatch.redis.zadd "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", rcv_time, Yajl::Encoder.encode({:message => message, :data => dat, :when => rcv_time})
42
- end
43
-
44
- def alerts
45
- @alerts ||= []
46
- if block_given?
47
- @alerts.each do |a|
48
- yield a
49
- end
50
- else
51
- @alerts
52
- end
53
- nil
54
- end
55
-
56
- def get_alerts(host=host,num=5)
57
- CityWatch.redis.zrevrange "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::alerts", 0, num - 1
58
- end
59
-
60
- def send_alerts!
61
- @alerts.map do |alert|
62
- puts "Alert: #{alert.inspect}" #if CityWatch.debug?
63
- end if @alerts
64
- end
65
-
66
- def set_flag(name)
67
- unless get_flag(name)
68
- flag_flapped name, :on
69
- end
70
- CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 1
71
- end
72
-
73
- def clear_flag(name)
74
- if get_flag(name)
75
- flag_flapped name, :off
76
- end
77
- CityWatch.redis.setbit "#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name), 0
78
- end
79
-
80
- def flag_flapped(name,new_val)
81
- # should have some event to watch for a flag switching position
82
- puts "Flag flipped: #{name} -> #{new_val}" #if CityWatch.debug?
83
- end
84
-
85
- def get_flag(name,host=host)
86
- @host = host
87
- CityWatch.redis.getbit("#{CityWatch.config[:prefix]}::#{host}::#{self.name}::flags", flag_position(name)) ? true : false
88
- end
89
-
90
- def get_flags(host=host)
91
- @host = host
92
- out = {}
93
- map = flag_map
94
- map.each_index do |idx|
95
- out[map[idx]] = get_flag(map[idx])
96
- end
97
- out
98
- end
99
-
100
- def flag_map_key
101
- "#{CityWatch.config[:prefix]}::#{self.name}::flag_map"
102
- end
103
-
104
- def flag_map
105
- CityWatch.redis.lrange flag_map_key, 0, -1
106
- end
107
-
108
- def flag_position(name)
109
- if (map = flag_map) && map.include?(name.to_s)
110
- map.index(name.to_s)
111
- else
112
- new_flag(name)
113
- end
114
- end
115
-
116
- def new_flag(name)
117
- CityWatch.redis.rpush(flag_map_key, name) - 1
118
- end
119
-
120
34
  def set_default(k,val)
121
35
  opts[k] = val
122
36
  end
@@ -138,6 +52,9 @@ module Watchman
138
52
  end
139
53
 
140
54
  def self.included(base)
55
+ base.extend(Alerts::ClassMethods)
56
+ base.extend(Rules::ClassMethods)
57
+ base.extend(Flags::ClassMethods)
141
58
  base.extend(ClassMethods)
142
59
  Watchmen.register(base)
143
60
  end
@@ -2,7 +2,7 @@ class DiskUsage
2
2
 
3
3
  include Watchman
4
4
 
5
- set_default :usage_threshold, 60
5
+ set_default :usage_threshold, 75
6
6
 
7
7
  def self.data
8
8
  dat = DF.data
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CityWatch
2
- VERSION = "0.5.3"
2
+ VERSION = "0.5.4"
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.3
5
+ version: 0.5.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - John Bragg
@@ -127,7 +127,10 @@ files:
127
127
  - lib/city_watch/commands/mpstat.rb
128
128
  - lib/city_watch/commands/netstat.rb
129
129
  - lib/city_watch/commands/ps.rb
130
+ - lib/city_watch/util/alerts.rb
130
131
  - lib/city_watch/util/collector.rb
132
+ - lib/city_watch/util/flags.rb
133
+ - lib/city_watch/util/rules.rb
131
134
  - lib/city_watch/util/run_command.rb
132
135
  - lib/city_watch/util/watchman.rb
133
136
  - lib/city_watch/watchmen.rb