Sha256: dce2e0e78e1c580673b4ddd4734ecb82412d8af9ecd0e4eb6c0145cafb780918
Contents?: true
Size: 1.49 KB
Versions: 2
Compression:
Stored size: 1.49 KB
Contents
require 'prometheus/client/rack/exporter' require 'rack' require 'rack/handler/puma' class Syslogstash::PrometheusExporter attr_reader :thread def initialize @msg_in = prom.counter(:syslogstash_messages_received, "The number of syslog messages received from each log socket") @msg_out = prom.counter(:syslogstash_messages_sent, "The number of logstash messages sent to each logstash server") @lag = prom.gauge(:syslogstash_lag_ms, "How far behind we are in relaying messages") @queue = prom.gauge(:syslogstash_queue_size, "How many messages are queued to be sent") end def received(socket, stamp) @msg_in.increment(socket_path: socket) @queue.set({}, (@queue.get({}) || 0) + 1) if @most_recent_received.nil? || @most_recent_received < stamp @most_recent_received = stamp refresh_lag end end def sent(server, stamp) @msg_out.increment(logstash_server: server) @queue.set({}, @queue.get({}) - 1) if @most_recent_sent.nil? || @most_recent_sent < stamp @most_recent_sent = stamp refresh_lag end end def run @thread = Thread.new do app = Rack::Builder.new app.use Prometheus::Client::Rack::Exporter app.run ->(env) { [404, {'Content-Type' => 'text/plain'}, ['Nope']] } Rack::Handler::Puma.run app, Host: '[::]', Port: 9159 end end private def prom Prometheus::Client.registry end def refresh_lag if @most_recent_received && @most_recent_sent @lag.set({}, ((@most_recent_received.to_f - @most_recent_sent.to_f) * 1000).to_i) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
syslogstash-0.4.1 | lib/syslogstash/prometheus_exporter.rb |
syslogstash-0.4.0 | lib/syslogstash/prometheus_exporter.rb |