class PrometheusExporter::Server::WebCollector
Public Class Methods
new()
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 5 def initialize @metrics = {} @http_requests_total = nil @http_duration_seconds = nil @http_redis_duration_seconds = nil @http_sql_duration_seconds = nil @http_queue_duration_seconds = nil end
Public Instance Methods
collect(obj)
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 18 def collect(obj) ensure_metrics observe(obj) end
metrics()
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 23 def metrics @metrics.values end
type()
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 14 def type "web" end
Protected Instance Methods
ensure_metrics()
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 29 def ensure_metrics unless @http_requests_total @metrics["http_requests_total"] = @http_requests_total = PrometheusExporter::Metric::Counter.new( "http_requests_total", "Total HTTP requests from web app." ) @metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Summary.new( "http_duration_seconds", "Time spent in HTTP reqs in seconds." ) @metrics["http_redis_duration_seconds"] = @http_redis_duration_seconds = PrometheusExporter::Metric::Summary.new( "http_redis_duration_seconds", "Time spent in HTTP reqs in Redis, in seconds." ) @metrics["http_sql_duration_seconds"] = @http_sql_duration_seconds = PrometheusExporter::Metric::Summary.new( "http_sql_duration_seconds", "Time spent in HTTP reqs in SQL in seconds." ) @metrics["http_queue_duration_seconds"] = @http_queue_duration_seconds = PrometheusExporter::Metric::Summary.new( "http_queue_duration_seconds", "Time spent queueing the request in load balancer in seconds." ) end end
observe(obj)
click to toggle source
# File lib/prometheus_exporter/server/web_collector.rb, line 58 def observe(obj) default_labels = obj['default_labels'] custom_labels = obj['custom_labels'] labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels) @http_requests_total.observe(1, labels) if timings = obj["timings"] @http_duration_seconds.observe(timings["total_duration"], labels) if redis = timings["redis"] @http_redis_duration_seconds.observe(redis["duration"], labels) end if sql = timings["sql"] @http_sql_duration_seconds.observe(sql["duration"], labels) end end if queue_time = obj["queue_time"] @http_queue_duration_seconds.observe(queue_time, labels) end end