Sha256: c8a73eb5ef325ce4ba6d6c1451f4397fe44cea772dbaa9d94d6bb60d23153178

Contents?: true

Size: 1.38 KB

Versions: 2

Compression:

Stored size: 1.38 KB

Contents

require 'frankenstein/server'
require 'logger'

class Syslogstash::PrometheusExporter
	attr_reader :thread

	def initialize(cfg)
		@stats_server = Frankenstein::Server.new(port: 9159, logger: cfg.logger, metrics_prefix: "syslogstash_server")

		@msg_in  = prom.counter(:syslogstash_messages_received_total, "The number of syslog messages received from the log socket")
		@msg_out = prom.counter(:syslogstash_messages_sent_total, "The number of logstash messages sent to each logstash server")
		@lag     = prom.gauge(:syslogstash_last_relayed_message_timestamp, "When the last message that was successfully relayed to logstash was originally received")
		@queue   = prom.gauge(:syslogstash_queue_size, "How many messages are currently in the queue to be sent")
		@dropped = prom.counter(:syslogstash_messages_dropped, "How many messages have been dropped from the backlog queue")

		@q_mutex = Mutex.new

		@lag.set({}, 0)
		@queue.set({}, 0)
	end

	def received(socket)
		@msg_in.increment(socket_path: socket)
		@q_mutex.synchronize { @queue.set({}, @queue.get({}) + 1) }
	end

	def sent(server, stamp)
		@msg_out.increment(logstash_server: server)
		@q_mutex.synchronize { @queue.set({}, @queue.get({}) - 1) }
		@lag.set({}, stamp.to_f)
	end

	def dropped
		@queue.set({}, @queue.get({}) - 1)
		@dropped.increment({})
	end

	def run
		@stats_server.run
	end

	private

	def prom
		@stats_server.registry
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
syslogstash-2.2.0 lib/syslogstash/prometheus_exporter.rb
syslogstash-2.1.0 lib/syslogstash/prometheus_exporter.rb