Class: Bigcommerce::Prometheus::Servers::Thin::ServerMetrics

Inherits:
Object
  • Object
show all
Defined in:
lib/bigcommerce/prometheus/servers/thin/server_metrics.rb

Overview

Server metrics for the collector

Instance Method Summary collapse

Constructor Details

#initialize(logger: nil) ⇒ ServerMetrics

Returns a new instance of ServerMetrics.

Parameters:

  • logger (::Logger) (defaults to: nil)


33
34
35
36
37
38
39
40
# File 'lib/bigcommerce/prometheus/servers/thin/server_metrics.rb', line 33

def initialize(logger: nil)
  @logger = logger || ::Bigcommerce::Prometheus.logger
  @metrics_total = ::PrometheusExporter::Metric::Counter.new('collector_metrics_total', 'Total metrics processed by exporter.')
  @sessions_total = ::PrometheusExporter::Metric::Counter.new('collector_sessions_total', 'Total send_metric sessions processed by exporter.')
  @bad_metrics_total = ::PrometheusExporter::Metric::Counter.new('collector_bad_metrics_total', 'Total mis-handled metrics by collector.')
  @collector_working_gauge = ::PrometheusExporter::Metric::Gauge.new('collector_working', 'Is the main process collector able to collect metrics')
  @collector_rss_gauge = ::PrometheusExporter::Metric::Gauge.new('collector_rss', 'total memory used by collector process')
end

Instance Method Details

#add_bad_metricObject



50
51
52
# File 'lib/bigcommerce/prometheus/servers/thin/server_metrics.rb', line 50

def add_bad_metric
  @bad_metrics_total.observe
end

#add_metricObject



46
47
48
# File 'lib/bigcommerce/prometheus/servers/thin/server_metrics.rb', line 46

def add_metric
  @metrics_total.observe
end

#add_sessionObject



42
43
44
# File 'lib/bigcommerce/prometheus/servers/thin/server_metrics.rb', line 42

def add_session
  @sessions_total.observe
end

#to_prometheus_text(working: true) ⇒ String

Parameters:

  • working (Boolean) (defaults to: true)

Returns:

  • (String)


58
59
60
# File 'lib/bigcommerce/prometheus/servers/thin/server_metrics.rb', line 58

def to_prometheus_text(working: true)
  collect(working: working).map(&:to_prometheus_text).join("\n\n")
end