Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

gem build prometheus_exporter.gemspec
33 changes: 29 additions & 4 deletions lib/prometheus_exporter/server/web_collector.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# frozen_string_literal: true

require 'yaml'

module PrometheusExporter::Server
class WebCollector < TypeCollector
def initialize
if ENV["RAIL_PROMETHEUS_EXPORTER_CONFIG"] then
@config = YAML.load(File.read(ENV["RAIL_PROMETHEUS_EXPORTER_CONFIG"]))
else
puts("Could not find env RAIL_PROMETHEUS_EXPORTER_CONFIG. Loading defualt configuration.")
@config = {"histogram_buckets"=>[ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5.0, 7.5, 10, 20, 30 ]}
end
@metrics = {}
end

Expand All @@ -28,9 +36,16 @@ def ensure_metrics
"Total HTTP requests from web app."
)

@metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Summary.new(
# Commenting out request duration summary metrics
# @metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Summary.new(
# "http_duration_seconds",
# "Time spent in HTTP reqs in seconds."
# )

@metrics["http_duration_seconds"] = @http_duration_seconds = PrometheusExporter::Metric::Histogram.new(
"http_duration_seconds",
"Time spent in HTTP reqs in seconds."
"Time spent in HTTP reqs in seconds.",
opts={:buckets=>@config["histogram_buckets"]}
)

@metrics["http_redis_duration_seconds"] = @http_redis_duration_seconds = PrometheusExporter::Metric::Summary.new(
Expand All @@ -50,10 +65,20 @@ def ensure_metrics
end
end

def replace_digits_in_controller(controller)
if controller
controller = controller.gsub(/\d+/, "digit")
end
controller
end

def observe(obj)
obj['controller'] = replace_digits_in_controller(obj['controller'])

default_labels = {
controller: obj['controller'] || 'other',
action: obj['action'] || 'other'
request_url: obj['controller'] || 'other',
action: obj['action'] || 'other',
status_code: obj["status"]
}
custom_labels = obj['custom_labels']
labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
Expand Down
2 changes: 1 addition & 1 deletion lib/prometheus_exporter/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module PrometheusExporter
VERSION = '0.5.1'
VERSION = '0.5.1.db'
end