ezmetrics 1.0.5 → 1.0.6

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: 1bd4e2f35cc2cf1b50efbac72d107041dc68129e
4
- data.tar.gz: 179ed567aac638d1ab0d3a4ed86eaad458c55fd1
3
+ metadata.gz: dc9e49c32e99f5d45f45ca6d3d467e53c09b8502
4
+ data.tar.gz: ce9f340d9f70ddfd7aebbac487e2d1b4b094527f
5
5
  SHA512:
6
- metadata.gz: e805073975368174e1ce2fd62ce3ddeece44a50bb0141f4a2d7fb9a1b8392c1083667656f29217a1beef6f9add360af0bbba3fe4016263dfa20421af247e1bbf
7
- data.tar.gz: 7364788497b995a02cb3385220a7f9e861cc4d7db6377f29850c6d22e25d99b25b6fdbaaa00a6ffb224573739262219136d9739e3676f65af6b4ba03a72c6606
6
+ metadata.gz: 295ae4b987d80ec5feb6cbb21e0f5dee0ea6523d140e50840b5637b57c3263f712b5c798eed3c69794fb8618a5236e7f6005a1fee34f4e2f6e8812f97ab636e7
7
+ data.tar.gz: 8c9523d1385036e83a1eaea18e275c91f2865c391ad60f50a2af76b865843338e1d4408e8f08f037c2af14ba552181f7a82e85be7ea5b7242755f2c4070fb418
data/README.md CHANGED
@@ -15,14 +15,14 @@ gem 'ezmetrics'
15
15
 
16
16
  ### Getting started
17
17
 
18
- This tool captures and aggregates metrics such as
18
+ This tool captures and aggregates Rails application metrics such as
19
19
  - `duration`
20
20
  - `views`
21
21
  - `db`
22
22
  - `queries`
23
23
  - `status`
24
24
 
25
- for a 60 seconds timeframe by default.
25
+ and stores them for the timeframe you specified, 60 seconds by default.
26
26
 
27
27
  You can change the timeframe according to your needs and save the metrics by calling `log` method:
28
28
 
@@ -54,7 +54,9 @@ or
54
54
  > Please note that you can combine these timeframes, for example - store for 10 minutes, display for 5 minutes.
55
55
 
56
56
 
57
- ### Add an initializer to your Rails application
57
+ ### Capture metrics
58
+
59
+ Just add an initializer to your application:
58
60
 
59
61
  ```ruby
60
62
  # config/initializers/ezmetrics.rb
@@ -81,6 +83,8 @@ end
81
83
 
82
84
  ### Display metrics
83
85
 
86
+ As simple as:
87
+
84
88
  ```ruby
85
89
  EZmetrics.new.show
86
90
  ```
@@ -117,3 +121,27 @@ This will return a hash with the following structure:
117
121
  }
118
122
  ```
119
123
 
124
+ ### Performance
125
+
126
+ The implementation is based on **Redis** commands such as:
127
+
128
+ - [`get`](https://redis.io/commands/get)
129
+ - [`mget`](https://redis.io/commands/mget)
130
+ - [`setex`](https://redis.io/commands/setex)
131
+
132
+ which are extremely fast.
133
+
134
+ You can check the **aggregation** time by running:
135
+
136
+ ```ruby
137
+ EZmetrics::Benchmark.new.measure_aggregation
138
+ ```
139
+
140
+ The result of running this benchmark on a *2017 Macbook Pro 2.9 GHz Intel Core i7 with 16 GB of RAM*:
141
+
142
+ | Interval | Duration (seconds) |
143
+ |:--------:|:------------------:|
144
+ | 1 minute | 0.0 |
145
+ | 1 hour | 0.11 |
146
+ | 12 hours | 1.6 |
147
+ | 24 hours | 3.5 |
@@ -153,4 +153,6 @@ class EZmetrics
153
153
  requests: {}
154
154
  }
155
155
  end
156
- end
156
+ end
157
+
158
+ require "ezmetrics/benchmark"
@@ -0,0 +1,87 @@
1
+ require "benchmark"
2
+
3
+ class EZmetrics::Benchmark
4
+
5
+ def initialize
6
+ @start = Time.now.to_i
7
+ @redis = Redis.new
8
+ @durations = []
9
+ @iterations = 3
10
+ @intervals = {
11
+ "1.minute" => 60,
12
+ "1.hour " => 3600,
13
+ "12.hours" => 43200,
14
+ "24.hours" => 86400
15
+ }
16
+ end
17
+
18
+ def measure_aggregation
19
+ write_metrics
20
+ print_header
21
+ intervals.each do |interval, seconds|
22
+ result = measure_aggregation_time(interval, seconds)
23
+ print_row(result)
24
+ end
25
+ cleanup_metrics
26
+ print_footer
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :start, :redis, :durations, :intervals, :iterations
32
+
33
+ def write_metrics
34
+ seconds = intervals.values.max
35
+ seconds.times do |i|
36
+ second = start - i
37
+ payload = {
38
+ "duration_sum" => rand(10000),
39
+ "duration_max" => rand(10000),
40
+ "views_sum" => rand(1000),
41
+ "views_max" => rand(1000),
42
+ "db_sum" => rand(8000),
43
+ "db_max" => rand(8000),
44
+ "queries_sum" => rand(100),
45
+ "queries_max" => rand(100),
46
+ "statuses" => {
47
+ "2xx" => rand(10),
48
+ "3xx" => rand(10),
49
+ "4xx" => rand(10),
50
+ "5xx" => rand(10),
51
+ "all" => rand(40)
52
+ }
53
+ }
54
+ redis.setex("ez-metrics:#{second}", seconds, JSON.generate(payload))
55
+ end
56
+ nil
57
+ end
58
+
59
+ def cleanup_metrics
60
+ interval_start = Time.now.to_i - intervals.values.max - 100
61
+ interval_keys = (interval_start..Time.now.to_i).to_a.map { |second| "ez-metrics:#{second}" }
62
+ redis.del(interval_keys)
63
+ end
64
+
65
+ def measure_aggregation_time(interval, seconds)
66
+ iterations.times do
67
+ durations << ::Benchmark.measure { EZmetrics.new(seconds).show }.real
68
+ end
69
+
70
+ return {
71
+ interval: interval.gsub(".", " "),
72
+ duration: (durations.sum.to_f / iterations).round(2)
73
+ }
74
+ end
75
+
76
+ def print_header
77
+ print "\n#{'─'*31}\n| Interval | Duration (seconds)\n#{'─'*31}\n"
78
+ end
79
+
80
+ def print_row(result)
81
+ print "| #{result[:interval]} | #{result[:duration]}\n"
82
+ end
83
+
84
+ def print_footer
85
+ print "#{'─'*31}\n"
86
+ end
87
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ezmetrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicolae Rotaru
@@ -47,6 +47,7 @@ files:
47
47
  - LICENSE
48
48
  - README.md
49
49
  - lib/ezmetrics.rb
50
+ - lib/ezmetrics/benchmark.rb
50
51
  homepage: https://github.com/nyku/ezmetrics
51
52
  licenses:
52
53
  - GPL-3.0