redis_prometheus 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 795f9ada93c54358d409d12e704065f0ae71d37b
4
- data.tar.gz: 4e0154742b837495bcab118e66fe21252cd1a570
3
+ metadata.gz: 8c59cb7c47a04172276fc269cdf8cd17e63d5fef
4
+ data.tar.gz: 5bd10eab113ec3cbbd302c9dea510441c4232b0c
5
5
  SHA512:
6
- metadata.gz: b3123cdcec1254735a8122aa9859daccb43711f3e775f996ad4deb5c5e80cf8e1c4d6ba525801fe0d8a1b2bacfab26c65caedd884e596770b1d1a8a1454e3d0c
7
- data.tar.gz: 6117e961ddcebd2d6440075951e6883816d99be6a71b40cccfa139326bc7015ce0bd5de4fa0f76d861332354577e1c4543ef044975b1f65238915fcad253c5b6
6
+ metadata.gz: f04986c69d9d712b68f7e8c00751db1950ee95bedfebcfc76b96e6586cb16e18d8a08256b0da6fb05601d8422d942a8046a7fb39d0653a3c8a029816cf83fb32
7
+ data.tar.gz: c11775bca497be85a7271945fb5b3e83cf6a4d5c0aa030130ac7af7e14f0c5850054abc13cad9ae5d2364e6d17e08efc713aaf8a26e0e4a339c902339643942b
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # RedisPrometheus
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/redis_prometheus`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ After realising all the current gem solutions for Rails + Prometheus only report stats for the current process (meaning your stats will differ on every scrape), we wrote this gem that uses Redis as a shared data store.
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ **IMPORTANT:** This gem has no tests yet and is brand new, it was written for our internal needs and has been open-sourced under the MIT licence, but it DEFINITELY comes with zero warranty at all, including that it will either work and won't open your site up to hackers!
6
6
 
7
7
  ## Installation
8
8
 
@@ -14,15 +14,36 @@ gem 'redis_prometheus'
14
14
 
15
15
  And then execute:
16
16
 
17
- $ bundle
17
+ ```
18
+ $ bundle
19
+ ```
18
20
 
19
21
  Or install it yourself as:
20
22
 
21
- $ gem install redis_prometheus
23
+ ```
24
+ $ gem install redis_prometheus
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
25
- TODO: Write usage instructions here
29
+ You then need to configure two ENVironment variables (because we play nicely with 12 Factor Apps) outside of your app or in a `.env` file if you use Foreman/etc:
30
+
31
+ ```
32
+ REDIS_PROMETHEUS_SERVICE=...
33
+ REDIS_PROMETHEUS_TOKEN=...
34
+ ```
35
+
36
+ The `REDIS_PROMETHEUS_TOKEN` is just appended to the `/metrics` URL that this gem responds on, so if you set it as 123, you should configure Prometheus to scrape /metrics/123. This is in lieu of authentication, just to make the URL a little harder to guess.
37
+
38
+ The `REDIS_PROMETHEUS_SERVICE` is just a label for this application, so if you have multiple applications reporting in to the same Prometheus you can separate them.
39
+
40
+ If you have any paths that you want to ignore stats for, you can set them in `config/application.rb` like this:
41
+
42
+ ```
43
+ config.redis_prometheus.ignored_urls += %w{/status /ping}
44
+ ```
45
+
46
+ After that, configure Prometheus to scrape your URL and it will automatically report a Histogram of response times with URLs, any UUIDs in the URL will be replaced with a token so they share a URL.
26
47
 
27
48
  ## Development
28
49
 
@@ -29,7 +29,7 @@ module RedisPrometheus
29
29
  headers = {}
30
30
  response = ""
31
31
 
32
- keys = Redis.current.keys("http_request_duration_seconds_bucket:*")
32
+ keys = Redis.current.keys("http_request_duration_seconds_bucket/#{ENV["REDIS_PROMETHEUS_SERVICE"]}:*")
33
33
  values = Redis.current.mget(keys)
34
34
  response << "# TYPE http_request_duration_seconds_bucket histogram\n"
35
35
  response << "# HELP http_request_duration_seconds_bucket The HTTP response duration of the Rack application.\n"
@@ -53,17 +53,17 @@ module RedisPrometheus
53
53
 
54
54
  response << "# TYPE http_request_requests_counter counter\n"
55
55
  response << "# HELP http_request_requests_counter The total number of HTTP requests handled by the Rack application.\n"
56
- requests = Redis.current.get("http_request_requests_counter") || 0
56
+ requests = Redis.current.get("http_request_requests_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}") || 0
57
57
  response << "http_request_requests_counter{service=\"#{ENV["REDIS_PROMETHEUS_SERVICE"]}\"} #{requests.to_f}\n"
58
58
 
59
59
  response << "# TYPE http_request_client_errors_counter counter\n"
60
60
  response << "# HELP http_request_client_errors_counter The total number of HTTP errors return by the Rack application.\n"
61
- requests = Redis.current.get("http_request_client_errors_counter") || 0
61
+ requests = Redis.current.get("http_request_client_errors_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}") || 0
62
62
  response << "http_request_client_errors_counter{service=\"#{ENV["REDIS_PROMETHEUS_SERVICE"]}\"} #{requests.to_f}\n"
63
63
 
64
64
  response << "# TYPE http_request_server_errors_counter counter\n"
65
65
  response << "# HELP http_request_server_errors_counter The total number of HTTP errors return by the Rack application.\n"
66
- requests = Redis.current.get("http_request_server_errors_counter") || 0
66
+ requests = Redis.current.get("http_request_server_errors_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}") || 0
67
67
  response << "http_request_server_errors_counter{service=\"#{ENV["REDIS_PROMETHEUS_SERVICE"]}\"} #{requests.to_f}\n"
68
68
 
69
69
  headers['Content-Encoding'] = "gzip"
@@ -82,13 +82,13 @@ module RedisPrometheus
82
82
  url.gsub!(%r{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}i, "{uuid}")
83
83
 
84
84
  bucket = duration_to_bucket(duration)
85
- Redis.current.incr("http_request_duration_seconds_bucket:url=#{url}:le=#{bucket}")
86
- Redis.current.incr("http_request_requests_counter")
85
+ Redis.current.incr("http_request_duration_seconds_bucket/#{ENV["REDIS_PROMETHEUS_SERVICE"]}:url=#{url}:le=#{bucket}")
86
+ Redis.current.incr("http_request_requests_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}")
87
87
  if code.to_i >= 400 && code.to_i <= 499
88
- Redis.current.incr("http_request_client_errors_counter")
88
+ Redis.current.incr("http_request_client_errors_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}")
89
89
  end
90
90
  if code.to_i >= 500 && code.to_i <= 599
91
- Redis.current.incr("http_request_server_errors_counter")
91
+ Redis.current.incr("http_request_server_errors_counter/#{ENV["REDIS_PROMETHEUS_SERVICE"]}")
92
92
  end
93
93
  end
94
94
 
@@ -1,3 +1,3 @@
1
1
  module RedisPrometheus
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis_prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Jeffries
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-25 00:00:00.000000000 Z
11
+ date: 2018-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler