diff options
author | Douwe Maan <douwe@gitlab.com> | 2019-07-04 10:24:20 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2019-07-04 10:24:20 +0000 |
commit | 7ffacaae6037a3c483263f6b680632f4ef322a01 (patch) | |
tree | 4ac1a5705856fa0fa0108fb1c794d28a8d1ae428 | |
parent | 5608c8617cddf5b86e6caebd759beb69540e671c (diff) | |
parent | 04962880ad5325e4386528cfebb1d8a599de6494 (diff) | |
download | gitlab-ce-7ffacaae6037a3c483263f6b680632f4ef322a01.tar.gz |
Merge branch '63873-process-start-time' into 'master'
Resolve "The process start time is invalid"
Closes #63873
See merge request gitlab-org/gitlab-ce!30195
-rw-r--r-- | changelogs/unreleased/63873-process-start-time.yml | 6 | ||||
-rw-r--r-- | doc/administration/monitoring/prometheus/gitlab_metrics.md | 2 | ||||
-rw-r--r-- | lib/gitlab/metrics/samplers/ruby_sampler.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/metrics/system.rb | 12 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb | 16 | ||||
-rw-r--r-- | spec/lib/gitlab/metrics/system_spec.rb | 12 |
6 files changed, 21 insertions, 34 deletions
diff --git a/changelogs/unreleased/63873-process-start-time.yml b/changelogs/unreleased/63873-process-start-time.yml new file mode 100644 index 00000000000..b11a66ca106 --- /dev/null +++ b/changelogs/unreleased/63873-process-start-time.yml @@ -0,0 +1,6 @@ +--- +title: Change ruby_process_start_time_seconds metric to unix timestamp instead of + seconds from boot. +merge_request: 30195 +author: +type: fixed diff --git a/doc/administration/monitoring/prometheus/gitlab_metrics.md b/doc/administration/monitoring/prometheus/gitlab_metrics.md index 2d9e3f7f18b..f09548aa024 100644 --- a/doc/administration/monitoring/prometheus/gitlab_metrics.md +++ b/doc/administration/monitoring/prometheus/gitlab_metrics.md @@ -104,7 +104,7 @@ Some basic Ruby runtime metrics are available: | ruby_process_cpu_seconds_total | Gauge | 12.0 | Total amount of CPU time per process | | ruby_process_max_fds | Gauge | 12.0 | Maximum number of open file descriptors per process | | ruby_process_resident_memory_bytes | Gauge | 12.0 | Memory usage by process, measured in bytes | -| ruby_process_start_time_seconds | Gauge | 12.0 | The elapsed time between system boot and the process started, measured in seconds | +| ruby_process_start_time_seconds | Gauge | 12.0 | UNIX timestamp of process start time | [GC.stat]: https://ruby-doc.org/core-2.3.0/GC.html#method-c-stat diff --git a/lib/gitlab/metrics/samplers/ruby_sampler.rb b/lib/gitlab/metrics/samplers/ruby_sampler.rb index 17eacbd21d8..eef802caabb 100644 --- a/lib/gitlab/metrics/samplers/ruby_sampler.rb +++ b/lib/gitlab/metrics/samplers/ruby_sampler.rb @@ -6,6 +6,12 @@ module Gitlab module Metrics module Samplers class RubySampler < BaseSampler + def initialize(interval) + metrics[:process_start_time_seconds].set(labels.merge(worker_label), Time.now.to_i) + + super + end + def metrics @metrics ||= init_metrics end @@ -47,7 +53,6 @@ module Gitlab metrics[:file_descriptors].set(labels.merge(worker_label), System.file_descriptor_count) metrics[:process_cpu_seconds_total].set(labels.merge(worker_label), ::Gitlab::Metrics::System.cpu_time) metrics[:process_max_fds].set(labels.merge(worker_label), ::Gitlab::Metrics::System.max_open_file_descriptors) - metrics[:process_start_time_seconds].set(labels.merge(worker_label), ::Gitlab::Metrics::System.process_start_time) set_memory_usage_metrics sample_gc diff --git a/lib/gitlab/metrics/system.rb b/lib/gitlab/metrics/system.rb index 34de40ca72f..5c2f07b95e2 100644 --- a/lib/gitlab/metrics/system.rb +++ b/lib/gitlab/metrics/system.rb @@ -31,14 +31,6 @@ module Gitlab match[1].to_i end - - def self.process_start_time - fields = File.read('/proc/self/stat').split - - # fields[21] is linux proc stat field "(22) starttime". - # The value is expressed in clock ticks, divide by clock ticks for seconds. - ( fields[21].to_i || 0 ) / clk_tck - end else def self.memory_usage 0.0 @@ -51,10 +43,6 @@ module Gitlab def self.max_open_file_descriptors 0 end - - def self.process_start_time - 0 - end end def self.cpu_time diff --git a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb index aaf8c9fa2a0..4d93b70e6e3 100644 --- a/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb +++ b/spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb @@ -8,12 +8,19 @@ describe Gitlab::Metrics::Samplers::RubySampler do allow(Gitlab::Metrics::NullMetric).to receive(:instance).and_return(null_metric) end + describe '#initialize' do + it 'sets process_start_time_seconds' do + Timecop.freeze do + expect(sampler.metrics[:process_start_time_seconds].get).to eq(Time.now.to_i) + end + end + end + describe '#sample' do it 'samples various statistics' do expect(Gitlab::Metrics::System).to receive(:cpu_time) expect(Gitlab::Metrics::System).to receive(:file_descriptor_count) expect(Gitlab::Metrics::System).to receive(:memory_usage) - expect(Gitlab::Metrics::System).to receive(:process_start_time) expect(Gitlab::Metrics::System).to receive(:max_open_file_descriptors) expect(sampler).to receive(:sample_gc) @@ -44,13 +51,6 @@ describe Gitlab::Metrics::Samplers::RubySampler do sampler.sample end - it 'adds a metric containing the process start time' do - expect(Gitlab::Metrics::System).to receive(:process_start_time).and_return(12345) - expect(sampler.metrics[:process_start_time_seconds]).to receive(:set).with({}, 12345) - - sampler.sample - end - it 'adds a metric containing the process max file descriptors' do expect(Gitlab::Metrics::System).to receive(:max_open_file_descriptors).and_return(1024) expect(sampler.metrics[:process_max_fds]).to receive(:set).with({}, 1024) diff --git a/spec/lib/gitlab/metrics/system_spec.rb b/spec/lib/gitlab/metrics/system_spec.rb index da87df15746..3b434a02f63 100644 --- a/spec/lib/gitlab/metrics/system_spec.rb +++ b/spec/lib/gitlab/metrics/system_spec.rb @@ -19,12 +19,6 @@ describe Gitlab::Metrics::System do expect(described_class.max_open_file_descriptors).to be > 0 end end - - describe '.process_start_time' do - it 'returns the process start time' do - expect(described_class.process_start_time).to be > 0 - end - end else describe '.memory_usage' do it 'returns 0.0' do @@ -43,12 +37,6 @@ describe Gitlab::Metrics::System do expect(described_class.max_open_file_descriptors).to eq(0) end end - - describe 'process_start_time' do - it 'returns 0' do - expect(described_class.process_start_time).to eq(0) - end - end end describe '.cpu_time' do |