redis_prometheus 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +26 -5
- data/lib/redis_prometheus/middleware.rb +8 -8
- data/lib/redis_prometheus/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8c59cb7c47a04172276fc269cdf8cd17e63d5fef
|
4
|
+
data.tar.gz: 5bd10eab113ec3cbbd302c9dea510441c4232b0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f04986c69d9d712b68f7e8c00751db1950ee95bedfebcfc76b96e6586cb16e18d8a08256b0da6fb05601d8422d942a8046a7fb39d0653a3c8a029816cf83fb32
|
7
|
+
data.tar.gz: c11775bca497be85a7271945fb5b3e83cf6a4d5c0aa030130ac7af7e14f0c5850054abc13cad9ae5d2364e6d17e08efc713aaf8a26e0e4a339c902339643942b
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# RedisPrometheus
|
2
2
|
|
3
|
-
|
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
|
-
|
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
|
-
|
17
|
+
```
|
18
|
+
$ bundle
|
19
|
+
```
|
18
20
|
|
19
21
|
Or install it yourself as:
|
20
22
|
|
21
|
-
|
23
|
+
```
|
24
|
+
$ gem install redis_prometheus
|
25
|
+
```
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
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
|
|
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.
|
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-
|
11
|
+
date: 2018-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|