Class: GitLab::Monitor::ProcessProber
- Inherits:
-
Object
- Object
- GitLab::Monitor::ProcessProber
- Defined in:
- lib/gitlab_monitor/process.rb
Overview
Probes a process for info then writes metrics to a target
Instance Method Summary collapse
-
#initialize(options, metrics: PrometheusMetrics.new) ⇒ ProcessProber
constructor
A new instance of ProcessProber.
- #probe_count ⇒ Object
- #probe_smaps ⇒ Object
- #probe_stat ⇒ Object
- #write_to(target) ⇒ Object
Constructor Details
#initialize(options, metrics: PrometheusMetrics.new) ⇒ ProcessProber
Returns a new instance of ProcessProber.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gitlab_monitor/process.rb', line 62 def initialize(, metrics: PrometheusMetrics.new) @metrics = metrics @name = [:name] @pids = if [:pid_or_pattern] =~ /^\d+$/ [[:pid_or_pattern]] else Utils.pgrep([:pid_or_pattern]) end @use_quantiles = .fetch(:quantiles, false) end |
Instance Method Details
#probe_count ⇒ Object
90 91 92 93 94 |
# File 'lib/gitlab_monitor/process.rb', line 90 def probe_count @metrics.add("process_count", @pids.count, name: @name.downcase) self end |
#probe_smaps ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/gitlab_monitor/process.rb', line 96 def probe_smaps @pids.each do |pid| stats = ::GitLab::Monitor::MemStats::Aggregator.new(pid) next unless stats.valid? labels = { name: @name.downcase } labels[:pid] = pid unless @use_quantiles ::GitLab::Monitor::MemStats::Mapping::FIELDS.each do |field| value = stats.totals[field] if value >= 0 @metrics.add("process_smaps_#{field}_bytes", value * 1024, @use_quantiles, **labels) end end end self end |
#probe_stat ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/gitlab_monitor/process.rb', line 73 def probe_stat @pids.each do |pid| stats = ProcessStats.new(pid) next unless stats.valid? labels = { name: @name.downcase } labels[:pid] = pid unless @use_quantiles @metrics.add("process_cpu_seconds_total", stats.cpu_time, @use_quantiles, **labels) @metrics.add("process_resident_memory_bytes", stats.rss, @use_quantiles, **labels) @metrics.add("process_virtual_memory_bytes", stats.vsize, @use_quantiles, **labels) @metrics.add("process_start_time_seconds", stats.start_time, @use_quantiles, **labels) end self end |
#write_to(target) ⇒ Object
117 118 119 |
# File 'lib/gitlab_monitor/process.rb', line 117 def write_to(target) target.write(@metrics.to_s) end |