bipbip 0.4.5 → 0.5.0
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 +4 -4
- data/README.md +0 -10
- data/lib/bipbip/plugin.rb +11 -5
- data/lib/bipbip/plugin/log_parser.rb +43 -51
- data/lib/bipbip/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a8c565ef72aa8710b7d485185227db02f8f1f916
|
4
|
+
data.tar.gz: c3dc8e55ee5adfe49ca1214ee1f4f0d26e9eb102
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9be1a3363765235384983bebb7f36959698ad3cbad7e315aa19f33281c1c8c851dcaadeaca4c5714780e301e820126d4a11240158f0cd8e2db2f5f354350e0fb
|
7
|
+
data.tar.gz: c5ac6e22536847ca6ab813bae641ff143cbaf28812c96e8a843ce22823ac0a53a928bd753a026b6d36c2c7bffe8840db4cb3d2fe42bce4c20390ba525c096275
|
data/README.md
CHANGED
@@ -96,7 +96,6 @@ services:
|
|
96
96
|
-
|
97
97
|
plugin: log-parser
|
98
98
|
path: /var/log/syslog
|
99
|
-
regexp_timestamp: '^\w+ \d{1,2} \d{2}\:\d{2}\:\d{2}'
|
100
99
|
matchers:
|
101
100
|
-
|
102
101
|
name: oom_killer
|
@@ -154,15 +153,6 @@ Alias /apc-status /usr/local/bin/apc-status.php
|
|
154
153
|
|
155
154
|
Then set the `url`-configuration for the plugin to where the script is being served, e.g. `http//localhost:80/apc-status`.
|
156
155
|
|
157
|
-
#### log-parser
|
158
|
-
The log file is being read backwards from the end.
|
159
|
-
Each line should contain a timestamp which matches `regexp_timestamp` and can be parsed by `DateTime.parse`.
|
160
|
-
Multiple `matchers` can be specified, each creates a metrics with the number of matched lines as a value.
|
161
|
-
|
162
|
-
Example values for `regexp_timestamp`:
|
163
|
-
* *default*: `^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}`
|
164
|
-
* syslog traditional: `^\w+ \d{1,2} \d{2}\:\d{2}\:\d{2}` (not recommended because year is missing)
|
165
|
-
|
166
156
|
Custom external plugins
|
167
157
|
-----------------------
|
168
158
|
Additional plugins can be created as independent gems.
|
data/lib/bipbip/plugin.rb
CHANGED
@@ -34,7 +34,7 @@ module Bipbip
|
|
34
34
|
if data.empty?
|
35
35
|
raise "#{name} #{source_identifier}: Empty data"
|
36
36
|
end
|
37
|
-
|
37
|
+
log(Logger::DEBUG, "Data: #{data}")
|
38
38
|
storages.each do |storage|
|
39
39
|
storage.store_sample(self, time, data)
|
40
40
|
end
|
@@ -42,19 +42,19 @@ module Bipbip
|
|
42
42
|
interruptible_sleep (frequency - (Time.now - time))
|
43
43
|
end
|
44
44
|
rescue => e
|
45
|
-
|
45
|
+
log(Logger::ERROR, e.message)
|
46
46
|
interruptible_sleep retry_delay
|
47
47
|
retry_delay += frequency if retry_delay < frequency * 10
|
48
48
|
retry
|
49
49
|
rescue Exception => e
|
50
|
-
|
50
|
+
log(Logger::FATAL, e.message)
|
51
51
|
raise e
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
56
|
def interrupt
|
57
|
-
|
57
|
+
log(Logger::INFO, "Interrupting plugin process #{Process.pid}")
|
58
58
|
@interrupted = true
|
59
59
|
interrupt_sleep
|
60
60
|
end
|
@@ -76,7 +76,7 @@ module Bipbip
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def metrics_names
|
79
|
-
metrics_schema.map {|metric| metric[:name] }
|
79
|
+
metrics_schema.map { |metric| metric[:name] }
|
80
80
|
end
|
81
81
|
|
82
82
|
def metrics_schema
|
@@ -86,5 +86,11 @@ module Bipbip
|
|
86
86
|
def monitor
|
87
87
|
raise 'Missing method monitor'
|
88
88
|
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def log(severity, message)
|
93
|
+
Bipbip.logger.add(severity, message, "#{name} #{source_identifier}")
|
94
|
+
end
|
89
95
|
end
|
90
96
|
end
|
@@ -1,10 +1,7 @@
|
|
1
|
-
require '
|
1
|
+
require 'rb-inotify'
|
2
2
|
|
3
3
|
module Bipbip
|
4
4
|
|
5
|
-
TIMESTAMP_REGEXP = '^\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}'
|
6
|
-
REGEXP_IGNORE_LINE = '^\s*$'
|
7
|
-
|
8
5
|
class Plugin::LogParser < Plugin
|
9
6
|
|
10
7
|
def metrics_schema
|
@@ -14,21 +11,18 @@ module Bipbip
|
|
14
11
|
end
|
15
12
|
|
16
13
|
def monitor
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
time_first ||= time
|
25
|
-
(time > log_time_min)
|
26
|
-
else
|
27
|
-
Bipbip::logger.warn("Log parser: Unparseable line `#{line.chomp}` in `#{config['path']}`")
|
14
|
+
unless IO.select([notifier.to_io], [], [], 0).nil?
|
15
|
+
n = notifier
|
16
|
+
begin
|
17
|
+
n.process
|
18
|
+
rescue NoMethodError => e
|
19
|
+
# Ignore errors from closed notifier - see https://github.com/nex3/rb-inotify/issues/41
|
20
|
+
raise e unless n.watchers.empty?
|
28
21
|
end
|
29
22
|
end
|
30
23
|
|
31
|
-
|
24
|
+
lines = @lines.entries
|
25
|
+
@lines.clear
|
32
26
|
|
33
27
|
Hash[config['matchers'].map do |matcher|
|
34
28
|
name = matcher['name']
|
@@ -40,48 +34,46 @@ module Bipbip
|
|
40
34
|
|
41
35
|
private
|
42
36
|
|
43
|
-
def
|
44
|
-
|
37
|
+
def notifier
|
38
|
+
if @notifier.nil?
|
39
|
+
@notifier = create_notifier
|
40
|
+
@lines = []
|
41
|
+
@size = File.stat(config['path']).size
|
42
|
+
end
|
43
|
+
@notifier
|
45
44
|
end
|
46
45
|
|
47
|
-
def
|
48
|
-
|
46
|
+
def create_notifier
|
47
|
+
# Including the "attrib" event, because on some systems "unlink" triggers "attrib", but then the inode's deletion doesn't trigger "delete_self"
|
48
|
+
events = [:modify, :delete_self, :move_self, :unmount, :attrib]
|
49
|
+
notifier = INotify::Notifier.new
|
50
|
+
notifier.watch(config['path'], *events) do |event|
|
51
|
+
if event.flags.include?(:modify)
|
52
|
+
roll_file
|
53
|
+
else
|
54
|
+
log(Logger::WARN, "File event `#{event.flags.join(',')}` detected, resetting notifier")
|
55
|
+
reset_notifier
|
56
|
+
end
|
57
|
+
end
|
58
|
+
notifier
|
49
59
|
end
|
50
60
|
|
51
|
-
def
|
52
|
-
@
|
61
|
+
def reset_notifier
|
62
|
+
unless @notifier.nil?
|
63
|
+
@notifier.stop
|
64
|
+
@notifier.close
|
65
|
+
@notifier = nil
|
66
|
+
end
|
53
67
|
end
|
54
68
|
|
55
|
-
def
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
while file.pos > 0
|
63
|
-
buffer_size = file.pos if file.pos < buffer_size
|
64
|
-
|
65
|
-
file.seek(-buffer_size, File::SEEK_CUR)
|
66
|
-
buffer = file.read(buffer_size)
|
67
|
-
file.seek(-buffer_size, File::SEEK_CUR)
|
68
|
-
|
69
|
-
line_list = buffer.each_line.entries
|
70
|
-
|
71
|
-
if file.pos != 0
|
72
|
-
# Remove first line as can be incomplete
|
73
|
-
# due to seeking backward with buffer_size steps
|
74
|
-
first_line = line_list.shift
|
75
|
-
raise "Line length exceeds buffer size `#{buffer_size}`" if first_line.length == buffer_size
|
76
|
-
file.seek(first_line.length, File::SEEK_CUR)
|
77
|
-
end
|
78
|
-
|
79
|
-
line_list.reverse.each do |line|
|
80
|
-
yielder.yield(line)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
69
|
+
def roll_file
|
70
|
+
file = File.new(config['path'], 'r')
|
71
|
+
if file.size != @size
|
72
|
+
file.seek(@size)
|
73
|
+
@lines.push(*file.readlines)
|
74
|
+
@size = file.size
|
84
75
|
end
|
76
|
+
file.close
|
85
77
|
end
|
86
78
|
|
87
79
|
end
|
data/lib/bipbip/version.rb
CHANGED
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
|
+
version: 0.5.0
|
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-
|
13
|
+
date: 2014-11-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: copperegg
|
@@ -152,6 +152,20 @@ dependencies:
|
|
152
152
|
- - "~>"
|
153
153
|
- !ruby/object:Gem::Version
|
154
154
|
version: 0.1.3
|
155
|
+
- !ruby/object:Gem::Dependency
|
156
|
+
name: rb-inotify
|
157
|
+
requirement: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - "~>"
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: 0.9.5
|
162
|
+
type: :runtime
|
163
|
+
prerelease: false
|
164
|
+
version_requirements: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - "~>"
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: 0.9.5
|
155
169
|
- !ruby/object:Gem::Dependency
|
156
170
|
name: rake
|
157
171
|
requirement: !ruby/object:Gem::Requirement
|