Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ gem "redis"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
gem "raindrops", "~> 0.19" if !RUBY_ENGINE == "jruby"
gem "simplecov"

# Dev tools / linter
gem "guard", require: false
Expand Down
1 change: 1 addition & 0 deletions gemfiles/ar_71.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem "rake"
gem "redis"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
gem "simplecov"
gem "guard", require: false
gem "guard-minitest", require: false
gem "rubocop", require: false
Expand Down
1 change: 1 addition & 0 deletions gemfiles/ar_72.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem "rake"
gem "redis"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
gem "simplecov"
gem "guard", require: false
gem "guard-minitest", require: false
gem "rubocop", require: false
Expand Down
1 change: 1 addition & 0 deletions gemfiles/ar_80.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem "rake"
gem "redis"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
gem "simplecov"
gem "guard", require: false
gem "guard-minitest", require: false
gem "rubocop", require: false
Expand Down
1 change: 1 addition & 0 deletions gemfiles/ar_81.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gem "rake"
gem "redis"
gem "syntax_tree"
gem "syntax_tree-disable_ternary"
gem "simplecov"
gem "guard", require: false
gem "guard-minitest", require: false
gem "rubocop", require: false
Expand Down
18 changes: 10 additions & 8 deletions lib/prometheus_exporter/server/web_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,22 @@ module PrometheusExporter::Server
class WebServer
attr_reader :collector

PAGESIZE =
begin
`getconf PAGESIZE`.to_i
rescue StandardError
4096
end
private_constant :PAGESIZE

def initialize(opts)
@port = opts[:port] || PrometheusExporter::DEFAULT_PORT
@bind = opts[:bind] || PrometheusExporter::DEFAULT_BIND_ADDRESS
@timeout = opts[:timeout] || PrometheusExporter::DEFAULT_TIMEOUT
@verbose = opts[:verbose] || false
@auth = opts[:auth]
@realm = opts[:realm] || PrometheusExporter::DEFAULT_REALM
@pid = Process.pid

@metrics_total =
PrometheusExporter::Metric::Counter.new(
Expand Down Expand Up @@ -173,15 +182,8 @@ def metrics
end

def get_rss
@pagesize ||=
begin
`getconf PAGESIZE`.to_i
rescue StandardError
4096
end
@pid ||= Process.pid
begin
File.read("/proc/#{@pid}/statm").split(" ")[1].to_i * @pagesize
File.read("/proc/#{@pid}/statm").split(" ")[1].to_i * PAGESIZE
rescue StandardError
0
end
Expand Down
9 changes: 7 additions & 2 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "prometheus_exporter"
require "simplecov"

# Start SimpleCov
SimpleCov.start { add_filter "test/" }

require "minitest/mock"
require "minitest/autorun"
Expand Down Expand Up @@ -126,3 +128,6 @@ def get_max_metric_age

# Allow stubbing process monotonic clock from any class in the suite
Minitest::Test.send(:include, ClockHelper)

# Load our gem
require "prometheus_exporter"