query_counter 0.1.2 → 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/lib/query_counter/middleware.rb +14 -0
- data/lib/query_counter/request_helper.rb +37 -0
- data/lib/query_counter.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d69555984b1eaadf69789d406d1c2866abe2cb0c
|
4
|
+
data.tar.gz: 7131e5990e060322feafa5ec7823a720f2ffd510
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ea44f6c728227a52c44b30fc0c10755a0e7ec99fc1d214506559f5539ba65af12f48c9a69d76f925e18b44e88dcda0fd321b277107dbba861e6af45f8df1f06a
|
7
|
+
data.tar.gz: 90ca373df91ccedb757d0dc9e115819ebdf40e20926309e519ba61c8b68ad0f03faea5431dbd0355f1eb6aa1021d32bc85eff267efebe38ba717f64da91f5bdf
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module QueryCounter
|
2
|
+
class Middleware
|
3
|
+
def initialize(app)
|
4
|
+
@app = app
|
5
|
+
end
|
6
|
+
|
7
|
+
def call(env)
|
8
|
+
Thread.current[:starting_gc_count] = GC.count
|
9
|
+
Thread.current[:starting_count_objects] = ObjectSpace.count_objects
|
10
|
+
QueryCounter.reset
|
11
|
+
@app.call(env)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module QueryCounter
|
2
|
+
module RequestHelper
|
3
|
+
def qc_log_resource_usage_around
|
4
|
+
yield
|
5
|
+
ensure
|
6
|
+
qc_log_resource_usage
|
7
|
+
end
|
8
|
+
|
9
|
+
def qc_log_count_objects_around
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
qc_log_count_objects
|
13
|
+
end
|
14
|
+
|
15
|
+
def qc_log_resource_usage
|
16
|
+
gc = GC.count - Thread.current[:starting_gc_count]
|
17
|
+
stats = []
|
18
|
+
stats << "gc: #{gc}" if gc > 0
|
19
|
+
QueryCounter.current_collector.stats.each do |resource, stat|
|
20
|
+
stats << "#{resource}: #{stat.count} [#{stat.time.to_i}ms]"
|
21
|
+
end
|
22
|
+
|
23
|
+
logger.info 'Resource Stats ' + stats.join(', ')
|
24
|
+
end
|
25
|
+
|
26
|
+
def qc_log_count_objects
|
27
|
+
diff_count_objects = {}
|
28
|
+
ObjectSpace.count_objects.each do |name, count|
|
29
|
+
if (diff = (count - Thread.current[:starting_count_objects][name].to_i)) > 0
|
30
|
+
diff_count_objects[name] = diff
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
logger.info "Objects: #{diff_count_objects}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/query_counter.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module QueryCounter
|
2
2
|
autoload :Collector, 'query_counter/collector'
|
3
3
|
autoload :Global, 'query_counter/global'
|
4
|
+
autoload :Middleware, 'query_counter/middleware'
|
5
|
+
autoload :RequestHelper, 'query_counter/request_helper'
|
4
6
|
autoload :Stat, 'query_counter/stat'
|
5
7
|
|
6
8
|
def self.global_collector
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_counter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Doug Youch
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Used for monitoring number of external calls
|
14
14
|
email: dougyouch@gmail.com
|
@@ -19,6 +19,8 @@ files:
|
|
19
19
|
- lib/query_counter.rb
|
20
20
|
- lib/query_counter/collector.rb
|
21
21
|
- lib/query_counter/global.rb
|
22
|
+
- lib/query_counter/middleware.rb
|
23
|
+
- lib/query_counter/request_helper.rb
|
22
24
|
- lib/query_counter/stat.rb
|
23
25
|
homepage: https://github.com/evertrue/query_counter
|
24
26
|
licenses: []
|