frankenstein 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -2
- data/lib/frankenstein/collected_metric.rb +1 -1
- data/lib/frankenstein/process_metrics.rb +70 -0
- data/lib/frankenstein/ruby_gc_metrics.rb +24 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f39ba456b50f9441b4d32af514e3715fbf09cfb3b5d356edf6aa4efebaa5ae8d
|
4
|
+
data.tar.gz: 85fba7233f645d11051162b76e46da7e867f15e0644ed916415074f0b6e76b63
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 498ee7d399b04cecccf7ca01653de4fdc8cd6d375467fd1cbc574bd859196cc351236c659a79be5358fdeba59c7c21e7378a587933d17a24b01410ba90312fdf
|
7
|
+
data.tar.gz: dd17eb87a8ae2a09e7d5679cea4476faf3294c9329094eeb8b48fe57d24bb0740de1722828477155195cdc7a00f34dc753fad340bee288c058c80a5f6498f1ed
|
data/.travis.yml
CHANGED
@@ -67,7 +67,7 @@ module Frankenstein
|
|
67
67
|
#
|
68
68
|
# @param type [Symbol] what type of metric you're returning. It's uncommon
|
69
69
|
# to want anything other than `:gauge` here (the default), because
|
70
|
-
# when you're collecting external data it's
|
70
|
+
# when you're collecting external data it's unlikely you'll be able to
|
71
71
|
# trust that your external data source will behave like a proper
|
72
72
|
# counter (or histogram or summary), but if you want the flexibility,
|
73
73
|
# it's there for you. If you do decide to try your hand at collecting
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'frankenstein/collected_metric'
|
2
|
+
require 'etc'
|
3
|
+
|
4
|
+
module Frankenstein
|
5
|
+
# Allow registration of metrics for Ruby GC statistics.
|
6
|
+
#
|
7
|
+
module ProcessMetrics
|
8
|
+
# Register generic process metrics.
|
9
|
+
#
|
10
|
+
# Generates collected metric objects for all of the [recommended process
|
11
|
+
# metrics](https://prometheus.io/docs/instrumenting/writing_clientlibs/#process-metrics)
|
12
|
+
# that can be reasonably obtained using Ruby on the platform that the process
|
13
|
+
# is running on.
|
14
|
+
#
|
15
|
+
# @param registry [Prometheus::Client::Registry] specify the metrics
|
16
|
+
# registry in which to register the GC-related metrics.
|
17
|
+
#
|
18
|
+
# @param logger [Logger] where to log any problems which some sort of
|
19
|
+
#
|
20
|
+
def self.register(registry = Prometheus::Client.registry, logger: Logger.new("/dev/null"))
|
21
|
+
registry.gauge(:process_start_time_seconds, "Start time of the process since unix epoch in seconds").set({}, Time.now.to_f)
|
22
|
+
|
23
|
+
page_size = Etc.sysconf(Etc::SC_PAGESIZE)
|
24
|
+
hz = Etc.sysconf(Etc::SC_CLK_TCK)
|
25
|
+
|
26
|
+
stat_file = "/proc/#{Process.pid}/stat".freeze
|
27
|
+
|
28
|
+
if File.exist?(stat_file)
|
29
|
+
Frankenstein::CollectedMetric.new(:process_cpu_seconds_total, "Total user and system CPU time spent in seconds", registry: registry, logger: logger) do
|
30
|
+
stats = File.open(stat_file).read.split(" ")
|
31
|
+
{ { mode: "user" } => stats[13].to_f / hz, { mode: "system" } => stats[14].to_f / hz }
|
32
|
+
end
|
33
|
+
|
34
|
+
Frankenstein::CollectedMetric.new(:process_virtual_memory_bytes, "Virtual memory size in bytes", registry: registry, logger: logger) do
|
35
|
+
stats = File.open(stat_file).read.split(" ")
|
36
|
+
{ {} => stats[22].to_i }
|
37
|
+
end
|
38
|
+
|
39
|
+
Frankenstein::CollectedMetric.new(:process_resident_memory_bytes, "Resident memory size in bytes", registry: registry, logger: logger) do
|
40
|
+
stats = File.open(stat_file).read.split(" ")
|
41
|
+
{ {} => stats[23].to_i * page_size }
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
fd_dir = "/proc/#{Process.pid}/fd".freeze
|
46
|
+
|
47
|
+
if File.exist?(fd_dir)
|
48
|
+
Frankenstein::CollectedMetric.new(:process_open_fds, "Number of open file descriptors", registry: registry, logger: logger) do
|
49
|
+
{ {} => Dir["#{fd_dir}/*"].length }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
if Process.respond_to?(:getrlimit)
|
54
|
+
Frankenstein::CollectedMetric.new(:process_max_fds, "Maximum number of open file descriptors", registry: registry, logger: logger) do
|
55
|
+
{ {} => Process.getrlimit(:NOFILE).first }
|
56
|
+
end
|
57
|
+
|
58
|
+
Frankenstein::CollectedMetric.new(:process_virtual_memory_max_bytes, "Maximum amount of virtual memory available in bytes", registry: registry, logger: logger) do
|
59
|
+
{ {} => Process.getrlimit(:AS).first }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if GC.respond_to?(:stat) && GC.stat[:heap_allocated_pages]
|
64
|
+
Frankenstein::CollectedMetric.new(:process_heap_bytes, "Process heap size in bytes", registry: registry, logger: logger) do
|
65
|
+
{ {} => GC.stat[:heap_allocated_pages] * page_size }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'frankenstein/collected_metric'
|
2
|
+
|
3
|
+
module Frankenstein
|
4
|
+
# Allow registration of metrics for Ruby GC statistics.
|
5
|
+
#
|
6
|
+
module RubyGCMetrics
|
7
|
+
# Register Ruby GC metrics.
|
8
|
+
#
|
9
|
+
# For every statistic provided by the Ruby VM under the module method
|
10
|
+
# `GC.stat`, a metric is registered named `ruby_gc_<stat>`, which
|
11
|
+
# provides a dimensionless metric with the value of the statistic.
|
12
|
+
#
|
13
|
+
# @param registry [Prometheus::Client::Registry] specify the metrics
|
14
|
+
# registry in which to register the GC-related metrics.
|
15
|
+
#
|
16
|
+
def self.register(registry = Prometheus::Client.registry)
|
17
|
+
GC.stat.each do |k, v|
|
18
|
+
Frankenstein::CollectedMetric.new(:"ruby_gc_#{k}", "Ruby GC parameter #{k}", registry: registry) do
|
19
|
+
{ {} => GC.stat[k] }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frankenstein
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-09-
|
11
|
+
date: 2018-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prometheus-client
|
@@ -228,7 +228,9 @@ files:
|
|
228
228
|
- lib/frankenstein.rb
|
229
229
|
- lib/frankenstein/collected_metric.rb
|
230
230
|
- lib/frankenstein/error.rb
|
231
|
+
- lib/frankenstein/process_metrics.rb
|
231
232
|
- lib/frankenstein/request.rb
|
233
|
+
- lib/frankenstein/ruby_gc_metrics.rb
|
232
234
|
- lib/frankenstein/server.rb
|
233
235
|
- lib/frankenstein/server/webrick_logger.rb
|
234
236
|
homepage: https://github.com/discourse/frankenstein
|