Skip to content
This repository has been archived by the owner on Feb 7, 2019. It is now read-only.

Create Prometheus Exporter #53

Merged
merged 8 commits into from
Jan 11, 2019
Merged
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem 'lograge'
gem 'logstash-event'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'prometheus_exporter'
gem 'rails', '~> 5.2.2'
gem 'sentry-raven'

Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ GEM
ast (~> 2.4.0)
pg (1.1.4)
powerpack (0.1.2)
prometheus_exporter (0.4.2)
puma (3.12.0)
rack (2.0.6)
rack-test (1.1.0)
Expand Down Expand Up @@ -203,6 +204,7 @@ DEPENDENCIES
lograge
logstash-event
pg (>= 0.18, < 2.0)
prometheus_exporter
puma (~> 3.11)
rails (~> 5.2.2)
rspec-rails
Expand Down
7 changes: 7 additions & 0 deletions config/initializers/metrics.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
unless Rails.env.test?
require 'prometheus_exporter/instrumentation'
require 'prometheus_exporter/middleware'

PrometheusExporter::Instrumentation::Process.start(type: 'master')
Rails.application.middleware.unshift PrometheusExporter::Middleware
end
10 changes: 10 additions & 0 deletions config/puma_prod.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
# See: https://devcenter.heroku.com/articles/deploying-rails-applications-with-the-puma-web-server#on-worker-boot
ActiveRecord::Base.establish_connection
end

after_worker_boot do
require 'prometheus_exporter/instrumentation'
PrometheusExporter::Instrumentation::Puma.start
end

after_fork do
require 'prometheus_exporter/instrumentation'
PrometheusExporter::Instrumentation::Process.start(type: 'web')
end
18 changes: 18 additions & 0 deletions deploy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ spec:
secretKeyRef:
name: allocation-api-secrets
key: nomis_oauth_pub_key
- name: allocation-api-metrics
image: 926803513772.dkr.ecr.eu-west-1.amazonaws.com/offender-management/offender-management-allocation-api:latest
imagePullPolicy: Always
command: ['sh', '-c', "bundle exec puma prometheus_exporter --pidfile /tmp/server.pid"]
ports:
- containerPort: 9394
livenessProbe:
httpGet:
path: /metrics
port: 9394
initialDelaySeconds: 10
periodSeconds: 60
readinessProbe:
httpGet:
path: /metrics
port: 9394
initialDelaySeconds: 10
periodSeconds: 60
15 changes: 15 additions & 0 deletions deploy/service-monitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: allocation-api
namespace: offender-management-staging
spec:
selector:
matchLabels:
app: allocation-api
namespaceSelector:
matchNames:
- offender-management-staging
endpoints:
- port: "9394"
interval: 15s