Class: Syslogstash::PrometheusExporter

Inherits:
Object
  • Object
show all
Defined in:
lib/syslogstash/prometheus_exporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg) ⇒ PrometheusExporter

Returns a new instance of PrometheusExporter.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/syslogstash/prometheus_exporter.rb', line 7

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

Instance Attribute Details

#threadObject (readonly)

Returns the value of attribute thread.



5
6
7
# File 'lib/syslogstash/prometheus_exporter.rb', line 5

def thread
  @thread
end

Instance Method Details

#droppedObject



33
34
35
36
# File 'lib/syslogstash/prometheus_exporter.rb', line 33

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

#received(socket) ⇒ Object



22
23
24
25
# File 'lib/syslogstash/prometheus_exporter.rb', line 22

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

#runObject



38
39
40
# File 'lib/syslogstash/prometheus_exporter.rb', line 38

def run
	@stats_server.run
end

#sent(server, stamp) ⇒ Object



27
28
29
30
31
# File 'lib/syslogstash/prometheus_exporter.rb', line 27

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