Skip to content

Commit

Permalink
Use my prometheus-client fork with the :most_recent aggregation.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefansundin committed May 10, 2020
1 parent 81803fd commit 68f8e23
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .ebextensions/12-git.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
packages:
yum:
git: []
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ gem "secure_headers"
gem "heroku-env"
gem "tzinfo"
gem "nokogiri"
gem "prometheus-client", require: "prometheus/middleware/exporter"
gem "prometheus-client", require: "prometheus/middleware/exporter", git: "https://github.com/stefansundin/prometheus-client.git", branch: "master"

# dilbert feed
gem "feedjira"
Expand Down
10 changes: 8 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/stefansundin/prometheus-client.git
revision: fc179858e6e00a13a649dbdaa5b7de67fa68b1a5
branch: master
specs:
prometheus-client (2.0.0)

GEM
remote: https://rubygems.org/
specs:
Expand Down Expand Up @@ -38,7 +45,6 @@ GEM
nokogiri
powder (0.4.0)
thor (>= 0.11.5)
prometheus-client (2.0.0)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
Expand Down Expand Up @@ -96,7 +102,7 @@ DEPENDENCIES
nokogiri
opengraph_parser
powder
prometheus-client
prometheus-client!
pry-remote
puma
rack
Expand Down
4 changes: 3 additions & 1 deletion config/initializers/40-prometheus.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

# Use DirectFileStore if we run multiple processes
store_settings = {}
if ENV["WEB_CONCURRENCY"]
require "prometheus/client/data_stores/direct_file_store"
app_path = File.expand_path("../../..", __FILE__)
Prometheus::Client.config.data_store = Prometheus::Client::DataStores::DirectFileStore.new(dir: "#{app_path}/tmp/prometheus/")
store_settings[:aggregation] = :most_recent

# Clean up old metric files
Dir["#{app_path}/tmp/prometheus/*.bin"].each do |file_path|
Expand All @@ -15,7 +17,7 @@
prometheus = Prometheus::Client.registry

$metrics = {
ratelimit: prometheus.gauge(:ratelimit, labels: %i[service], docstring: "Remaining ratelimit for external services."),
ratelimit: prometheus.gauge(:ratelimit, store_settings: store_settings, labels: %i[service], docstring: "Remaining ratelimit for external services."),
requests: prometheus.counter(:requests, labels: %i[service response_code], docstring: "Number of requests made to external services."),
urls: prometheus.counter(:urls, docstring: "Number of URLs resolved."),
}

0 comments on commit 68f8e23

Please sign in to comment.