File tree Expand file tree Collapse file tree 3 files changed +79
-3
lines changed Expand file tree Collapse file tree 3 files changed +79
-3
lines changed Original file line number Diff line number Diff line change
1
+ begin
2
+ require "pitchfork/mem_info"
3
+ rescue LoadError
4
+ # No pitchfork available, dont do anything
5
+ end
6
+
7
+ module Promenade
8
+ module Pitchfork
9
+ class MemStats
10
+ Promenade . gauge :pitchfork_mem_rss do
11
+ doc "Resident Set Size of the pitchfork process, Total memory used by the process."
12
+ end
13
+
14
+ Promenade . gauge :pitchfork_shared_mem do
15
+ doc "Shared memory of the pitchfork process, memory that is shared between multiple processes."
16
+ end
17
+
18
+ def initialize
19
+ return unless defined? ( ::Pitchfork ) && defined? ( ::Pitchfork ::MemInfo )
20
+
21
+ @mem_info = ::Pitchfork ::MemInfo . new ( Process . pid )
22
+ @parent_mem_info = ::Pitchfork ::MemInfo . new ( Process . ppid )
23
+ end
24
+
25
+ def instrument
26
+ Promenade . metric ( :pitchfork_mem_rss ) . set ( { } , @mem_info . rss )
27
+ Promenade . metric ( :pitchfork_shared_mem ) . set ( { } , @mem_info . shared_memory )
28
+ end
29
+
30
+ def self . instrument
31
+ new . instrument
32
+ rescue StandardError
33
+ end
34
+ end
35
+ end
36
+ end
Original file line number Diff line number Diff line change 1
1
require "promenade/pitchfork/stats"
2
+ require "promenade/pitchfork/mem_stats"
2
3
3
4
module Promenade
4
5
module Pitchfork
@@ -11,12 +12,17 @@ def initialize(app)
11
12
12
13
def call ( env )
13
14
if env . key? ( RACK_AFTER_REPLY )
14
- env [ RACK_AFTER_REPLY ] << -> {
15
- ::Promenade ::Pitchfork ::Stats . instrument
16
- }
15
+ env [ RACK_AFTER_REPLY ] << -> { instrument }
17
16
end
18
17
@app . call ( env )
19
18
end
19
+
20
+ private
21
+
22
+ def instrument
23
+ Promenade ::Pitchfork ::Stats . instrument
24
+ Promenade ::Pitchfork ::MemStats . instrument
25
+ end
20
26
end
21
27
end
22
28
end
Original file line number Diff line number Diff line change
1
+ require "spec_helper"
2
+ require "promenade/pitchfork/mem_stats"
3
+
4
+ RSpec . describe Promenade ::Pitchfork ::MemStats do
5
+ let ( :pitfork_mem_info ) { class_double ( "Pitchfork::MemInfo" ) }
6
+
7
+ before do
8
+ stub_const ( "Pitchfork::MemInfo" , pitfork_mem_info )
9
+ allow ( pitfork_mem_info ) . to receive ( :new ) . and_return ( pitfork_mem_info )
10
+ allow ( pitfork_mem_info ) . to receive ( :rss ) . and_return ( 100 )
11
+ allow ( pitfork_mem_info ) . to receive ( :shared_memory ) . and_return ( 50 )
12
+ end
13
+
14
+ describe "#instrument" do
15
+ let ( :metric ) { instance_double ( "Promenade::Metric" ) }
16
+
17
+ before do
18
+ allow ( Promenade ) . to receive ( :metric ) . and_return ( metric )
19
+ allow ( metric ) . to receive ( :set )
20
+ end
21
+
22
+ it "sets the metrics correctly" do
23
+ stats = Promenade ::Pitchfork ::MemStats . new
24
+
25
+ expect ( Promenade ) . to receive ( :metric ) . with ( :pitchfork_mem_rss ) . and_return ( metric )
26
+ expect ( Promenade ) . to receive ( :metric ) . with ( :pitchfork_shared_mem ) . and_return ( metric )
27
+
28
+ expect ( metric ) . to receive ( :set ) . with ( { } , 100 )
29
+ expect ( metric ) . to receive ( :set ) . with ( { } , 50 )
30
+
31
+ stats . instrument
32
+ end
33
+ end
34
+ end
You can’t perform that action at this time.
0 commit comments