ducksboard_reporter 0.1.2 → 0.1.3
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4fbafb079a9f649c86561507e1b17825d5634dc
|
4
|
+
data.tar.gz: c63cf5b41bf246be7f18388d8d659e4178b21441
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 822a3d67bf1bac56c65ea0f0e73f75c412d3722038c27f9eccba3eb2bb2c3d7f7d0e1e8dab6c4a0d17fa8f3721b0bb380d60586b3cad57b0bf91761f28fc10fa
|
7
|
+
data.tar.gz: 4a7707a5cbea6ccdac83e25b826d09aea74fd93daee64f2036c08a74cc7401db5813f2f7a0fd1f1719dee77b2e0dedda090f722b6877f60299cde8e4c8b0d128
|
data/example_config.yml
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
module DucksboardReporter
|
2
|
+
class FileTail
|
3
|
+
|
4
|
+
attr_accessor :value, :timestamp, :name, :options
|
5
|
+
|
6
|
+
def initialize(path)
|
7
|
+
@path = path
|
8
|
+
@timestamp = Time.now.to_i
|
9
|
+
end
|
10
|
+
|
11
|
+
def run
|
12
|
+
open_file
|
13
|
+
|
14
|
+
while true do
|
15
|
+
if (current_time = Time.now.to_i) > @timestamp # flush every second
|
16
|
+
@every_second_block.call(current_time)
|
17
|
+
@timestamp = current_time
|
18
|
+
end
|
19
|
+
|
20
|
+
IO.select([@file])
|
21
|
+
line = @file.gets
|
22
|
+
|
23
|
+
if line
|
24
|
+
@line_block.call(line)
|
25
|
+
else
|
26
|
+
raise Errno::ENOENT unless File.exists?(@path)
|
27
|
+
sleep 0.001
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
sleep 0.1
|
32
|
+
retry
|
33
|
+
end
|
34
|
+
|
35
|
+
def every_second(&block)
|
36
|
+
@every_second_block = block
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_line(&block)
|
40
|
+
@line_block = block
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def open_file
|
46
|
+
if @file && !@file.closed?
|
47
|
+
if File.stat(@path).ino == @file.stat.ino
|
48
|
+
return
|
49
|
+
else
|
50
|
+
@file.close
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
@file = File.open(@path, "r")
|
55
|
+
@file.seek(0, IO::SEEK_END)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -9,37 +9,29 @@ module DucksboardReporter
|
|
9
9
|
nosrvs = 0
|
10
10
|
|
11
11
|
begin
|
12
|
-
|
12
|
+
tail = FileTail.new(options[:log_file])
|
13
13
|
rescue Errno::ENOENT
|
14
|
-
error("HaproxyLogRequests:
|
14
|
+
error("HaproxyLogRequests: Log file does not exist #{options[:log_file]}")
|
15
15
|
return
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if (current_time = Time.now.to_i) > @timestamp # flush every second
|
23
|
-
@requests, requests = requests, 0
|
24
|
-
@nosrvs, nosrvs = nosrvs, 0
|
25
|
-
@timestamp = current_time
|
26
|
-
end
|
27
|
-
|
28
|
-
IO.select([file])
|
29
|
-
line = file.gets
|
18
|
+
tail.every_second do
|
19
|
+
@requests, requests = requests, 0
|
20
|
+
@nosrvs, nosrvs = nosrvs, 0
|
21
|
+
end
|
30
22
|
|
23
|
+
tail.on_line do |line|
|
31
24
|
case line
|
32
25
|
when /NOSRV/
|
33
26
|
nosrvs += 1
|
34
27
|
when /./
|
35
28
|
requests += 1
|
36
|
-
else
|
37
|
-
sleep 0.1
|
38
29
|
end
|
39
30
|
end
|
31
|
+
|
32
|
+
tail.run
|
40
33
|
end
|
41
34
|
end
|
42
35
|
end
|
43
36
|
end
|
44
37
|
|
45
|
-
|
data/lib/ducksboard_reporter.rb
CHANGED
@@ -10,6 +10,7 @@ Hash.include Hashie::Extensions::SymbolizeKeys
|
|
10
10
|
require "ducksboard_reporter/version"
|
11
11
|
require "ducksboard_reporter/reporter"
|
12
12
|
require "ducksboard_reporter/widget"
|
13
|
+
require "ducksboard_reporter/file_tail"
|
13
14
|
|
14
15
|
require "ducksboard_reporter/reporters/random"
|
15
16
|
require "ducksboard_reporter/reporters/haproxy_log_requests"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ducksboard_reporter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- unnu
|
@@ -167,6 +167,7 @@ files:
|
|
167
167
|
- ducksboard_reporter.gemspec
|
168
168
|
- example_config.yml
|
169
169
|
- lib/ducksboard_reporter.rb
|
170
|
+
- lib/ducksboard_reporter/file_tail.rb
|
170
171
|
- lib/ducksboard_reporter/reporter.rb
|
171
172
|
- lib/ducksboard_reporter/reporters/bandwidth.rb
|
172
173
|
- lib/ducksboard_reporter/reporters/cpu_usage.rb
|