Class: Riemann::Tools::ApacheStatus
- Inherits:
-
Object
- Object
- Riemann::Tools::ApacheStatus
show all
- Includes:
- Riemann::Tools
- Defined in:
- lib/riemann/tools/apache_status.rb
Constant Summary
VERSION
Instance Attribute Summary
#argv
Instance Method Summary
collapse
#attributes, #endpoint_name, included, #options, #report, #riemann, #run
Constructor Details
Returns a new instance of ApacheStatus.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/riemann/tools/apache_status.rb', line 20
def initialize
super
@uri = URI.parse("#{opts[:uri]}?auto")
@scoreboard_map = {
'_' => 'waiting',
'S' => 'starting',
'R' => 'reading',
'W' => 'sending',
'K' => 'keepalive',
'D' => 'dns',
'C' => 'closing',
'L' => 'logging',
'G' => 'graceful',
'I' => 'idle',
'.' => 'open',
}
end
|
Instance Method Details
#connection ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/riemann/tools/apache_status.rb', line 72
def connection
response = nil
begin
response = ::Net::HTTP.new(@uri.host, @uri.port).get(@uri, { 'user-agent' => opts[:user_agent] }).body
rescue StandardError => e
report(
service: 'httpd health',
state: 'critical',
description: "Httpd connection error: #{e.class} - #{e.message}",
tags: ['httpd'],
)
else
report(
service: 'httpd health',
state: 'ok',
description: 'Httpd connection status ok',
tags: ['httpd'],
)
end
response
end
|
#get_scoreboard_metrics(response) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/riemann/tools/apache_status.rb', line 51
def get_scoreboard_metrics(response)
results = Hash.new(0)
response.slice! 'Scoreboard: '
response.each_char do |char|
results[char] += 1
end
results.transform_keys { |k| @scoreboard_map[k] }
end
|
#report_metrics(metrics) ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/riemann/tools/apache_status.rb', line 61
def report_metrics(metrics)
metrics.each do |k, v|
report(
service: "httpd #{k}",
metric: v.to_f,
state: 'ok',
tags: ['httpd'],
)
end
end
|
#tick ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/riemann/tools/apache_status.rb', line 94
def tick
return if (response = connection).nil?
response.each_line do |line|
metrics = {}
if line =~ /Scoreboard/
metrics = get_scoreboard_metrics(line.strip)
else
key, value = line.strip.split(':')
metrics[key.gsub(/\s/, '')] = value
end
report_metrics(metrics)
end
end
|