This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpowermta_traffic_
186 lines (152 loc) · 3.55 KB
/
powermta_traffic_
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/env ruby
pod=<<-POD
=head1 NAME
powermta_traffic_
Munin plugin that monitors the amount (message or transfer volume) both in
and out of PowerMTA.
This is a wildcard plugin, there are two types of data that can be graphed:
- msg Message throughput
- volume Traffic throughput
=head1 CONFIGURATION
The PowerMTA HTTP status interface must be enabled.
Options:
env.url http://localhost:8080 # URL to PowerMTA monitor page
env.auth_user [empty] # HTTP auth username for stats, if any
env.auth_pass [empty] # HTTP auth password for stats, if any
ln -s /usr/share/munin/plugins/powermta_traffic_ \
/etc/munin/plugins/powermta_traffic_msg
ln -s /usr/share/munin/plugins/powermta_traffic_ \
/etc/munin/plugins/powermta_traffic_volume
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 VERSION
1.0
=head1 AUTHOR
Chris Boulton <[email protected]>
http://chrisboulton.net/
http://github.com/chrisboulton/munin-powermta
=head1 LICENSE
BSD
POD
require 'pathname'
require 'net/http'
require 'rexml/document'
PMTA_URL = ENV['url'] || 'http://localhost:8080'
PMTA_USER = ENV['auth_user'] || ''
PMTA_PASS = ENV['auth_pass'] || ''
SCRIPT_NAME = File.basename(Pathname.new(__FILE__).realpath)
STAT_TYPE = File.basename($0).gsub(SCRIPT_NAME, '');
def autoconf
begin
get_powermta_stats
rescue Exception => e
puts "no (#{e})"
end
puts "yes"
exit 0
end
def config_volume
puts <<-EOF
graph_category PowerMTA
graph_title PowerMTA traffic by volume
graph_order in out
graph_vlabel bits in (-) / out (+) per ${graph_period}
graph_args --base 1000
in.label received
in.type DERIVE
in.graph no
in.min 0
in.cdef in,8,*
out.label bits
out.type DERIVE
out.negative in
out.min 0
out.cdef out,8,*
EOF
end
def config_msg
puts <<-EOF
graph_category PowerMTA
graph_title PowerMTA traffic by message count
graph_order in out
graph_vlabel messages in (-) / out (+) per ${graph_period}
graph_args --base 1000
in.label received
in.type DERIVE
in.graph no
in.min 0
in.max 1000000
out.label messages
out.type DERIVE
out.negative in
out.min 0
out.max 1000000
EOF
end
def suggest
puts "msg\nvolume"
exit 0
end
def fetch_volume
begin
rsp = get_powermta_stats
stat = (get_powermta_stat(rsp, "//traffic/total/out/kb").to_f * 1000).round
puts "out.value #{stat}\n"
stat = (get_powermta_stat(rsp, "//traffic/total/in/kb").to_f * 1000).round
puts "in.value #{stat}"
rescue Exception => e
$stderr.puts e
exit 1
end
end
def fetch_msg
begin
rsp = get_powermta_stats
stat = get_powermta_stat(rsp, "//traffic/total/out/msg")
puts "out.value #{stat}\n"
stat = get_powermta_stat(rsp, "//traffic/total/in/msg")
puts "in.value #{stat}"
rescue Exception => e
$stderr.puts e
exit 1
end
end
def get_powermta_stats
url = "#{PMTA_URL}/status?format=xml"
begin
response = Net::HTTP.get_response(URI.parse(url)).body
xml = REXML::Document.new(response)
rescue Exception => e
raise "Unable to fetch PowerMTA status from #{url}"
end
rsp = REXML::XPath.first(xml, "//rsp")
if rsp.nil?
raise "Not a valid PowerMTA status page"
end
return rsp
end
def get_powermta_stat(rsp, stat)
result = REXML::XPath.first(rsp, stat)
if stat.nil?
raise "Unable to locate statistic for #{stat}"
end
return result.text
end
if ARGV[0] == "config"
if STAT_TYPE == "msg"
config_msg
else
config_volume
end
elsif ARGV[0] == "suggest"
suggest
elsif ARGV[0] == "autoconf"
autoconf
else
if STAT_TYPE == "msg"
fetch_msg
else
fetch_volume
end
end