prometheus#proxy_prefix for simplification of PrefixProxy.new. missing @verify for Postfix added.

master
Denis Knauf 2022-10-04 18:21:26 +02:00
parent 24858883b4
commit 01677886a2
2 changed files with 20 additions and 12 deletions

View File

@ -4,7 +4,7 @@ class Collector
class PrefixProxy
attr_reader :prometheus, :prefix
def initialize prometheus, prefix
@prometheus, @prefix = prometheus, prefix
@prometheus, @prefix = prometheus, prefix.dup.freeze
end
def counter name, **options
@ -22,6 +22,10 @@ class Collector
def summary name, **options
@prometheus.summary :"#{prefix}_#{name}", **options
end
def prefix_proxy prefix
PrefixProxy.new @prometheus, "#{@prefix}_#{prefix}"
end
end
def self.start prometheus: nil, journal: nil
@ -32,6 +36,9 @@ class Collector
@settings = settings
@journal = journal || Systemd::Journal.new( flags: Systemd::Journal::Flags::SYSTEM_ONLY)
@prometheus = prometheus || Prometheus::Client.registry
def @prometheus.prefix_proxy prefix
PrefixProxy.new self, prefix
end
@store = {}
@errors = @prometheus.counter :postfix_exporter_errors_total, docstring: 'Count internal errors/exceptions'

View File

@ -54,8 +54,8 @@ class Collector::Postfix
class Postscreen
def initialize store, prometheus
@store = store
@noqueue = Noqueue.new store, Collector::PrefixProxy.new( prometheus, :noqueue)
@cache = Cache.new store, Collector::PrefixProxy.new( prometheus, :cache)
@noqueue = Noqueue.new store, prometheus.prefix_proxy( :noqueue)
@cache = Cache.new store, prometheus.prefix_proxy( :cache)
@connect_from = prometheus.counter :connect_from_total, docstring: 'A counter of connections to postscreen'
@whitelisted = prometheus.counter :whitelisted_total, docstring: 'A counter of WHITELISTED connections to postscreen'
@pass_old = prometheus.counter :pass_old_total, docstring: 'A counter of PASS OLD connections to postscreen'
@ -181,7 +181,7 @@ class Collector::Postfix
class Smtpd
def initialize store, prometheus
@store = store
@noqueue = Noqueue.new store, Collector::PrefixProxy.new( prometheus, :noqueue)
@noqueue = Noqueue.new store, prometheus.prefix_proxy( :noqueue)
@connect_from = prometheus.counter :connect_from_total, docstring: 'A counter of connections to smtpd', labels: %i[from_unknown]
%w[0 1].each {|x| @connect_from.increment by: 0, labels: {from_unknown: x} }
@tls = prometheus.counter :tls_total, docstring: 'A counter of TLS connections to smtpd with TLS-version and cipher', labels: %i[trust tls cipher]
@ -330,7 +330,7 @@ class Collector::Postfix
class Verify
def initialize store, prometheus
@store = store
@cache = Cache.new store, Collector::PrefixProxy.new( prometheus, :cache)
@cache = Cache.new store, prometheus.prefix_proxy( :cache)
end
def collect entry
@ -344,13 +344,14 @@ class Collector::Postfix
def initialize store, prometheus
@store = store
@postscreen = Postscreen.new store, Collector::PrefixProxy.new( prometheus, :postscreen)
@smtp = Smtp.new store, Collector::PrefixProxy.new( prometheus, :smtp)
@smtpd = Smtpd.new store, Collector::PrefixProxy.new( prometheus, :smtpd)
@submission = Smtpd.new store, Collector::PrefixProxy.new( prometheus, :submission)
@tlsproxy = Tlsproxy.new store, Collector::PrefixProxy.new( prometheus, :tlsproxy)
@scache = SCache.new store, Collector::PrefixProxy.new( prometheus, :scache)
@bounce = Bounce.new store, Collector::PrefixProxy.new( prometheus, :bounce)
@postscreen = Postscreen.new store, prometheus.prefix_proxy( :postscreen)
@smtp = Smtp.new store, prometheus.prefix_proxy( :smtp)
@smtpd = Smtpd.new store, prometheus.prefix_proxy( :smtpd)
@submission = Smtpd.new store, prometheus.prefix_proxy( :submission)
@tlsproxy = Tlsproxy.new store, prometheus.prefix_proxy( :tlsproxy)
@scache = SCache.new store, prometheus.prefix_proxy( :scache)
@bounce = Bounce.new store, prometheus.prefix_proxy( :bounce)
@verify = Verify.new store, prometheus.prefix_proxy( :verify)
@qmgr = prometheus.counter :qmgr_total, docstring: 'A counter of qmgr actions'
@cleanup = prometheus.counter :cleanup_total, docstring: 'A counter of cleanup actions'
@lmtp = prometheus.counter :lmtp_total, docstring: 'A counter of ltmp actions'