bin/postfix-exporter in postfix-exporter-1.0.2 vs bin/postfix-exporter in postfix-exporter-2.0.1
- old
+ new
@@ -1,10 +1,10 @@
#!/usr/bin/env ruby
-require 'prometheus/client/rack/exporter'
-require 'socket'
require 'rack'
+require 'prometheus/middleware/exporter'
+require 'socket'
require 'rack/handler/webrick'
require 'logger'
prometheus = Prometheus::Client.registry
@@ -32,11 +32,10 @@
end
end
if ENV["SYSLOG_SOCKET"]
delays = prometheus.summary(:postfix_delivery_delays, "Distribution of time taken to deliver (or bounce) messages")
- statuses = prometheus.counter(:postfix_deliveries, "How many messages have been delivered (or bounced)")
Thread.new do
begin
s = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
s.bind(Socket.pack_sockaddr_un(ENV["SYSLOG_SOCKET"]))
@@ -46,18 +45,17 @@
end
loop do
begin
msg = s.recvmsg.first
- if msg =~ %r{postfix/smtp.* delay=(\d+(\.\d+)?), .* dsn=(\d+\.\d+\.\d+), status=(\w+)}
+ if msg =~ %r{postfix/.* delay=(\d+(\.\d+)?), .* dsn=(\d+\.\d+\.\d+), status=(\w+)}
delay = $1.to_f
dsn = $3
status = $4
if status == "bounced" or status == "sent"
- statuses.increment(dsn: dsn, status: status)
- delays.add({dsn: dsn, status: status}, delay)
+ delays.observe({dsn: dsn, status: status}, delay)
end
end
rescue StandardError => ex
$stderr.puts "Error while receiving postfix logs: #{ex.message} (#{ex.class})"
$stderr.puts ex.backtrace.map { |l| " #{l}" }.join("\n")
@@ -66,9 +64,10 @@
end
end
end
app = Rack::Builder.new
+app.use Rack::Deflater, if: ->(_, _, _, body) { body.any? && body[0].length > 512 }
app.use Prometheus::Client::Rack::Exporter
app.run ->(env) { [404, {'Content-Type' => 'text/plain'}, ['NOPE NOPE NOPE NOPE']] }
logger = Logger.new($stderr)
logger.level = Logger::INFO