bipbip 0.4.1 → 0.4.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 440ef769282f3bb2cc5e0dbb28c2a370344442a6
4
- data.tar.gz: 6e0b30d526ed8e4f48dab8f28a6e72d45d05b6b2
3
+ metadata.gz: fb3d5c73ae182538b9124ccc2566a2fb804e3e68
4
+ data.tar.gz: 54b73d42901422967d03df4312fea8cfcd7cbfef
5
5
  SHA512:
6
- metadata.gz: 2f307bd0b5dc52f69bea87d2212b7f3344474aaac2023d014da7e79e21ffa9da95c5b6b2e5b51aa46ac47ea2234ead09190aefd7103da0ccc09866329f49d639
7
- data.tar.gz: be6893be5535fe9afbf1ed8c4534c9900b82820afd9751baa9b099d8124a11bc562e6d6fce6beb7da6f306cc93a421ca32538e59787d28162f63cd4f081d2d9b
6
+ metadata.gz: cf4f339ec65ee85308adfe30fff5be549974d45ff509671745703fd3ca9fd2777ea730e39de6f94f9593b9eca6d3f1daafeca2c914c5d222e68ed9cc7ed9b2fb
7
+ data.tar.gz: ae58a1394f344b64992cd2c5ef51ca9c3aaa5724a8cd70f83b2c38dfcade088d26e5e6b2b65b413ca221e534ffb5257015fe8d2237eb72a43935456c8f0dfa7c
data/README.md CHANGED
@@ -93,6 +93,17 @@ services:
93
93
  plugin: fastcgi-php-opcache
94
94
  host: localhost
95
95
  port: 9000
96
+ -
97
+ plugin: log-parser
98
+ path: /var/log/syslog
99
+ regexp_timestamp: '^\w+ \d{1,2} \d{2}\:\d{2}\:\d{2}'
100
+ matchers:
101
+ -
102
+ name: oom_killer
103
+ regexp: 'invoked oom_killer'
104
+ -
105
+ name: segfault
106
+ regexp: segfault
96
107
  ```
97
108
 
98
109
  Include configuration
@@ -141,6 +152,15 @@ Alias /apc-status /usr/local/bin/apc-status.php
141
152
 
142
153
  Then set the `url`-configuration for the plugin to where the script is being served, e.g. `http//localhost:80/apc-status`.
143
154
 
155
+ #### log-parser
156
+ The log file is being read backwards from the end.
157
+ Each line should contain a timestamp which matches `regexp_timestamp` and can be parsed by `DateTime.parse`.
158
+ Multiple `matchers` can be specified, each creates a metrics with the number of matched lines as a value.
159
+
160
+ Example values for `regexp_timestamp`:
161
+ * *default*: `^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}`
162
+ * syslog traditional: `^\w+ \d{1,2} \d{2}\:\d{2}\:\d{2}` (not recommended because year is missing)
163
+
144
164
  Custom external plugins
145
165
  -----------------------
146
166
  Additional plugins can be created as independent gems.
@@ -0,0 +1,83 @@
1
+ require 'date'
2
+
3
+ module Bipbip
4
+
5
+ TIMESTAMP_REGEXP = '^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}'
6
+
7
+ class Plugin::LogParser < Plugin
8
+
9
+ def metrics_schema
10
+ config['matchers'].map do |matcher|
11
+ {:name => matcher['name'], :type => 'gauge', :unit => 'Boolean'}
12
+ end
13
+ end
14
+
15
+ def monitor
16
+ time_first = nil
17
+
18
+ lines = lines_backwards.take_while do |line|
19
+ timestamp_match = line.match(regexp_timestamp)
20
+ raise "Line doesn't match `#{regexp_timestamp}`: `#{line}`" if timestamp_match.nil?
21
+ time = DateTime.parse(timestamp_match[0]).to_time
22
+ time_first ||= time
23
+ (time > log_time_min)
24
+ end
25
+
26
+ self.log_time_min = time_first unless time_first.nil?
27
+
28
+ Hash[config['matchers'].map do |matcher|
29
+ name = matcher['name']
30
+ regexp = Regexp.new(matcher['regexp'])
31
+ value = lines.reject { |line| line.match(regexp).nil? }.length
32
+ [name, value]
33
+ end]
34
+ end
35
+
36
+ private
37
+
38
+ def log_time_min
39
+ @log_time_min ||= Time.now - @frequency.to_i
40
+ end
41
+
42
+ def log_time_min=(time)
43
+ @log_time_min = time
44
+ end
45
+
46
+ def regexp_timestamp
47
+ @regexp_timestamp ||= Regexp.new(config.fetch('regexp_timestamp', TIMESTAMP_REGEXP))
48
+ end
49
+
50
+ def lines_backwards
51
+ buffer_size = 65536
52
+
53
+ Enumerator.new do |yielder|
54
+ File.open(config['path']) do |file|
55
+ file.seek(0, File::SEEK_END)
56
+
57
+ while file.pos > 0
58
+ buffer_size = file.pos if file.pos < buffer_size
59
+
60
+ file.seek(-buffer_size, File::SEEK_CUR)
61
+ buffer = file.read(buffer_size)
62
+ file.seek(-buffer_size, File::SEEK_CUR)
63
+
64
+ line_list = buffer.each_line.entries
65
+
66
+ if file.pos != 0
67
+ # Remove first line as can be incomplete
68
+ # due to seeking backward with buffer_size steps
69
+ first_line = line_list.shift
70
+ raise "Line length exceeds buffer size `#{buffer_size}`" if first_line.length == buffer_size
71
+ file.seek(first_line.length, File::SEEK_CUR)
72
+ end
73
+
74
+ line_list.reverse.each do |line|
75
+ yielder.yield(line)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ end
83
+ end
@@ -1,3 +1,3 @@
1
1
  module Bipbip
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bipbip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-08-07 00:00:00.000000000 Z
13
+ date: 2014-10-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: copperegg
@@ -187,6 +187,7 @@ files:
187
187
  - lib/bipbip/plugin/fastcgi_php_fpm.rb
188
188
  - lib/bipbip/plugin/fastcgi_php_opcache.rb
189
189
  - lib/bipbip/plugin/gearman.rb
190
+ - lib/bipbip/plugin/log_parser.rb
190
191
  - lib/bipbip/plugin/memcached.rb
191
192
  - lib/bipbip/plugin/mongodb.rb
192
193
  - lib/bipbip/plugin/monit.rb
@@ -220,7 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
221
  version: '0'
221
222
  requirements: []
222
223
  rubyforge_project:
223
- rubygems_version: 2.3.0
224
+ rubygems_version: 2.4.1
224
225
  signing_key:
225
226
  specification_version: 4
226
227
  summary: Gather services data and store in CopperEgg