class GitLab::Monitor::ProcessProber
Probes a process for info then writes metrics to a target
Public Class Methods
new(options, metrics: PrometheusMetrics.new)
click to toggle source
# File lib/gitlab_monitor/process.rb, line 62 def initialize(options, metrics: PrometheusMetrics.new) @metrics = metrics @name = options[:name] @pids = if options[:pid_or_pattern] =~ /^\d+$/ [options[:pid_or_pattern]] else Utils.pgrep(options[:pid_or_pattern]) end @use_quantiles = options.fetch(:quantiles, false) end
Public Instance Methods
probe_count()
click to toggle source
# File lib/gitlab_monitor/process.rb, line 90 def probe_count @metrics.add("process_count", @pids.count, name: @name.downcase) self end
probe_smaps()
click to toggle source
# 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()
click to toggle source
# 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)
click to toggle source
# File lib/gitlab_monitor/process.rb, line 117 def write_to(target) target.write(@metrics.to_s) end