diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..7663a928 --- /dev/null +++ b/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +gem build prometheus_exporter.gemspec diff --git a/lib/prometheus_exporter/server/web_collector.rb b/lib/prometheus_exporter/server/web_collector.rb index 95033614..9bda8941 100644 --- a/lib/prometheus_exporter/server/web_collector.rb +++ b/lib/prometheus_exporter/server/web_collector.rb @@ -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 @@ -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( @@ -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) diff --git a/lib/prometheus_exporter/version.rb b/lib/prometheus_exporter/version.rb index ba312c14..cfde6275 100644 --- a/lib/prometheus_exporter/version.rb +++ b/lib/prometheus_exporter/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module PrometheusExporter - VERSION = '0.5.1' + VERSION = '0.5.1.db' end