riemann-rpush 0.0.3 → 0.0.4

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: 78fd53dc3d251144a8e4a2e3166ccf3258f6eb70
4
- data.tar.gz: 3a6b5a485e7384476999362a57791cfd3cdecc55
3
+ metadata.gz: 2f63311c03d5e1f6f5414b2234b043323b59f60d
4
+ data.tar.gz: 6100e82f93f010e90255e59acb4c7e82376661df
5
5
  SHA512:
6
- metadata.gz: 41405ff53ee71dac6eb7a309435f0fcf1db0e0635726957244f11ce6e425703be68b032d29f3c4a7fbf7a585d2e90bdf4a23a74b26e7635a0053e2565358441c
7
- data.tar.gz: 590fb77a8a52e21ec2e8d69cbd56104dfafad0798682d0e79854ebe5a0d511ba28d80c4153e9e8125648773599e8b993e6830a6800fa5c88c119975969186578
6
+ metadata.gz: 3145b9e3d34da18fc7658a26faf69b08186d2f9425fd42a2ed01bdaf2e3d98b8d39c7adb367ee91e2e481d0b787b66d89a8b71506896661f101455292df025a8
7
+ data.tar.gz: e7e0fbbe6c6238bb1e0cf317e00af7c52ab94ba5b75220d6e000820714ceb036f20e5a69b9e9c439f68d6621d53cf8a86f92de090096a46c3ae8115b796c32d8
data/bin/riemann-rpush CHANGED
@@ -11,6 +11,7 @@ class Riemann::Tools::Rpush
11
11
  opt :redis_url, "Redis URL", :default => ''
12
12
  opt :queue_size_warning, "Queue size warning threshold", :type => Integer, :default => 20
13
13
  opt :queue_size_critical, "Queue size critical threshold", :type => Integer, :default => 100
14
+ opt :treat_sent_as, "Treat already sent notifications as", :type => String, :default => 'apns'
14
15
 
15
16
  def initialize
16
17
  @redis = ::Redis.new({url: opts[:redis_url]})
@@ -19,23 +20,71 @@ class Riemann::Tools::Rpush
19
20
  end
20
21
 
21
22
  def tick
22
- queue_size = @redis.scard('rpush:notifications:all')
23
+ keys = @redis.smembers('rpush:notifications:all')
23
24
 
24
- state = if queue_size >= @queue_size_critical
25
+ types_count(keys).each_pair do |type, count|
26
+ deliver_type_count(type, count)
27
+ end
28
+
29
+ deliver_total(keys.size)
30
+ end
31
+
32
+ private
33
+ def types_count(keys)
34
+ keys.inject({
35
+ 'apns' => 0,
36
+ 'gcm' => 0,
37
+ 'wns' => 0
38
+ }) do |h, key|
39
+ type = get_notification_type(key)
40
+ if type
41
+ h[type] ||= 0
42
+ h[type] += 1
43
+ end
44
+ h
45
+ end
46
+ end
47
+
48
+ def get_notification_type(key)
49
+ type = @redis.hget("rpush:notifications:#{key}", 'type')
50
+ type.encode("ASCII-8BIT", invalid: :replace, replace: '').match(/Redis::(.*)::Notification/)[1].downcase
51
+ rescue
52
+ opts.fetch(:treat_sent_as)
53
+ end
54
+
55
+ def deliver_total(total)
56
+ state = if total >= @queue_size_critical
25
57
  'critical'
26
- elsif queue_size >= @queue_size_warning
58
+ elsif total >= @queue_size_warning
27
59
  'warning'
28
60
  else
29
61
  'ok'
30
62
  end
31
63
 
32
64
  msg = {
33
- metric: queue_size,
65
+ metric: total,
34
66
  service: 'rpush queue size',
35
67
  state: state
36
68
  }
37
69
  report msg
38
70
  end
71
+
72
+ def deliver_type_count(type, count)
73
+ state = if count >= @queue_size_critical
74
+ 'critical'
75
+ elsif count >= @queue_size_warning
76
+ 'warning'
77
+ else
78
+ 'ok'
79
+ end
80
+
81
+ msg = {
82
+ metric: count,
83
+ service: "rpush #{type}-queue size",
84
+ state: state
85
+ }
86
+ report msg
87
+ end
39
88
  end
40
89
 
41
90
  Riemann::Tools::Rpush.run
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "riemann-rpush"
7
- spec.version = '0.0.3'
7
+ spec.version = '0.0.4'
8
8
  spec.authors = ["Fernando Alonso"]
9
9
  spec.email = ["krakatoa1987@gmail.com"]
10
10
  spec.summary = %q{Riemann agent to collect Rpush metrics}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riemann-rpush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Alonso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-03 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: riemann-tools