promenade 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6038eb3692025b959c4fac797615ad3f213cef7bf44aa2acc0c0fc8abf7abc9d
4
- data.tar.gz: 68c502e34e147f24ed378ff236ae85f6abadd74eb24400393f980643e2aff25f
3
+ metadata.gz: 21e1b0da279e0be2d796defd5ba139262e5fcae5d9eb7bcc96a0e237ed2627e0
4
+ data.tar.gz: 265399012b1a27ef4b4f821a7fd4b860a8d714e3c210cf10da2311c0f5cba12e
5
5
  SHA512:
6
- metadata.gz: 40cf77b605a494115bd4b43002ddeba06db5b6f37d8ea7dfd110230f1642d25af77f6e7673453d645711558d20693539c44a44c947156d6edda2315ada91fe6d
7
- data.tar.gz: 924beb3ee617a96e5b3e356e689817e119852e6bcfd798a38bf27109b4a278d7df77cd9ad732b5cee24bc0808546fc2f400752376378e841cfcb09ac553be8ce
6
+ metadata.gz: 9d53dd6240a9b318550f2c94774e46e55a943a4d8bfda8f42b1339f2f7673d802b3fe7acd22d1efd0efcef0ab9ee513dfbc943a17fcb9b270c719ca7dac3be2b
7
+ data.tar.gz: c3d7acde8d85895a32a384c3428771b5ed792e6fbe9810d42a60cf1639e6f7fb60333d32209f30ca430ecbe73ec3dfb06be407ffbe35bd8c9ca005d20a476685
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in promenade.gemspec
4
4
  gemspec
5
+
6
+ gem "codecov"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- promenade (0.1.5)
4
+ promenade (0.1.6)
5
5
  activesupport
6
6
  prometheus-client-mmap (~> 0.9.3)
7
7
  rack
@@ -15,6 +15,10 @@ GEM
15
15
  minitest (~> 5.1)
16
16
  tzinfo (~> 1.1)
17
17
  ast (2.4.0)
18
+ codecov (0.1.10)
19
+ json
20
+ simplecov
21
+ url
18
22
  concurrent-ruby (1.0.5)
19
23
  diff-lcs (1.3)
20
24
  docile (1.3.1)
@@ -62,12 +66,14 @@ GEM
62
66
  tzinfo (1.2.5)
63
67
  thread_safe (~> 0.1)
64
68
  unicode-display_width (1.4.0)
69
+ url (0.3.2)
65
70
 
66
71
  PLATFORMS
67
72
  ruby
68
73
 
69
74
  DEPENDENCIES
70
75
  bundler (~> 1.16)
76
+ codecov
71
77
  promenade!
72
78
  rake (~> 10.0)
73
79
  rspec (~> 3.0)
data/README.md CHANGED
@@ -2,11 +2,158 @@
2
2
 
3
3
  [![Build Status](https://travis-ci.org/errm/promenade.svg?branch=master)](https://travis-ci.org/errm/promenade)
4
4
  [![Gem Version](https://badge.fury.io/rb/promenade.svg)](https://badge.fury.io/rb/promenade)
5
+ [![codecov](https://codecov.io/gh/errm/promenade/branch/master/graph/badge.svg)](https://codecov.io/gh/errm/promenade)
5
6
 
6
7
  Promenade is a libary to simplify instrumenting Ruby applications with prometheus.
7
8
 
8
9
  It is currently under development.
9
10
 
11
+ ## Usage
12
+
13
+ Add promenade to your Gemfile:
14
+
15
+ ```
16
+ gem "promenade"
17
+ ```
18
+
19
+ ### Built in instrumentation
20
+
21
+ Promenade includes some built in instrumentation that can be used by requiring it (for example in an initializer).
22
+
23
+ Currently there is just support for [ruby-kafka](https://github.com/zendesk/ruby-kafka), but I plan to support other things soon.
24
+
25
+ ```
26
+ # Instrument the ruby-kafka libary
27
+ require "promenade/kafka"
28
+ ```
29
+
30
+ ### Instrumentation DSL
31
+
32
+ Promenade makes recording prometheus metrics from your own code a little simpler with a DSL of sorts.
33
+
34
+ `Promenade::Helper` includes some class macros for defining your own metrics, and a metric method you can use to record metrics.
35
+
36
+ #### Counter
37
+
38
+ A counter is a metric that exposes a sum or tally of things.
39
+
40
+ ```ruby
41
+ require "promenade/helper"
42
+
43
+ class WidgetService
44
+ include ::Promenade::Helper
45
+
46
+ counter :widgets_created do
47
+ doc "Records how many widgets are created"
48
+ end
49
+
50
+ def create
51
+ # Widget creation code :)
52
+ metric(:widgets_created).increment
53
+
54
+ # You can also add extra labels as you set increment counters
55
+ metric(:widgets_created).increment({ type: "guinness" })
56
+ end
57
+
58
+ def batch_create
59
+ You can increment by more than 1 at a time if you need
60
+ metric(:widgets_created).increment({ type: "guinness" }, 100)
61
+ end
62
+ end
63
+ ```
64
+
65
+ #### Gauge
66
+
67
+ A gauge is a metric that exposes an instantaneous value or some snapshot of a changing value.
68
+
69
+ ```ruby
70
+ require "promenade/helper"
71
+
72
+ class Thermometer
73
+ include ::Promenade::Helper
74
+
75
+ gauge :room_temperature_celsius do
76
+ doc "Records room temprature"
77
+ end
78
+
79
+ def take_mesurements
80
+ metric(:room_temperature_celsius).set({ room: "lounge" }, 22.3)
81
+ metric(:room_temperature_celsius).set({ room: "kitchen" }, 25.45)
82
+ metric(:room_temperature_celsius).set({ room: "broom_cupboard" }, 15.37)
83
+ end
84
+ end
85
+ ```
86
+
87
+ #### Histogram
88
+
89
+ A histogram samples observations (usually things like request durations or
90
+ response sizes) and counts them in configurable buckets. It also provides a sum
91
+ of all observed values.
92
+
93
+ ```ruby
94
+ require "promenade/helper"
95
+
96
+ class Calculator
97
+ include ::Promenade::Helper
98
+
99
+ histogram :calculator_time_taken do
100
+ doc "Records how long it takes to do the adding"
101
+ # promenade also has some bucket presets like :network and :memory for common usecases
102
+ buckets [0.25, 0.5, 1, 2, 4]
103
+ end
104
+
105
+ def add_up
106
+ timing = Benchmark.realtime do
107
+ # Some time consuming addition
108
+ end
109
+
110
+ metric(:calculator_time_taken).observe({ operation: "addition"}, timing)
111
+ end
112
+ end
113
+ ```
114
+
115
+ #### Summary
116
+
117
+ Summary is similar to a histogram, but for when you just care about percentile values. Often useful for timings.
118
+
119
+ ```ruby
120
+ require "promenade/helper"
121
+
122
+ class ApiClient
123
+ include ::Promenade::Helper
124
+
125
+ summary :api_client_http_timing do
126
+ doc "record how long requests to the api are taking"
127
+ end
128
+
129
+ def get_users
130
+ timing = Benchmark.realtime do
131
+ # Makes a network call
132
+ end
133
+
134
+ metric(:api_client_http_timing).observe({ method: "get", path: "/api/v1/users" }, timing)
135
+ end
136
+ end
137
+ ```
138
+
139
+ ### Exporter
140
+
141
+ Because promenade is based on prometheus-client you can add the `Prometheus::Client::Rack::Exporter` middleware to your rack middleware stack to expose metrics.
142
+
143
+ There is also a stand alone exporter that can be run with the `promenade` command.
144
+
145
+ This is ideal if you are worried about acidently exposing your metrics, are concerned about the performance impact prometheus scrapes might have on your application, or for applications without a webserver (like background processing jobs). It does mean that you have another process to manage on your server though 🤷.
146
+
147
+ The exporter runs by default on port `9394` and the metrics are avaible at the standard path of `/metrics`, the standalone exporter is congfigured to use gzip.
148
+
149
+ ### Configuration
150
+
151
+ In a typical development environment there should be nothing for you to do. Promenade stores its state files in `tmp/promenade` and will create that directory if it does not exist.
152
+
153
+ In a production environment you should try to store the state files on tmpfs for performance, you can configure the path that promenade will write to by setting the `PROMETHEUS_MULTIPROC_DIR` environment variable.
154
+
155
+ If you are running the standalone exporter, you may also set the `PORT` environment variable to bind to a port other than the default (`9394`).
156
+
10
157
  ## Development
11
158
 
12
159
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -7,10 +7,14 @@ module Promenade
7
7
  end
8
8
 
9
9
  def self.multiprocess_files_dir
10
- ENV.fetch("PROMETHEUS_MULTIPROC_DIR", root_dir.join("tmp", "prometheus"))
10
+ ENV.fetch("PROMETHEUS_MULTIPROC_DIR", root_dir.join("tmp", "promenade"))
11
11
  end
12
12
 
13
13
  def self.setup
14
+ unless File.directory? multiprocess_files_dir
15
+ FileUtils.mkdir_p multiprocess_files_dir
16
+ end
17
+
14
18
  Prometheus::Client.configure do |config|
15
19
  config.multiprocess_files_dir = multiprocess_files_dir
16
20
  config.pid_provider = Prometheus::Client::Support::Unicorn.method(:worker_pid_provider)
@@ -1,3 +1,3 @@
1
1
  module Promenade
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promenade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-07-05 00:00:00.000000000 Z
11
+ date: 2018-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport