Class: GitLab::Exporter::ProcessProber

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_exporter/process.rb

Overview

Probes a process for info then writes metrics to a target

Instance Method Summary collapse

Constructor Details

#initialize(name:, metrics: PrometheusMetrics.new, quantiles: false, **options) ⇒ ProcessProber

Returns a new instance of ProcessProber.



62
63
64
65
66
67
68
69
70
71
# File 'lib/gitlab_exporter/process.rb', line 62

def initialize(name:, metrics: PrometheusMetrics.new, quantiles: false, **options)
  @metrics = metrics
  @name    = name
  @pids    = if options[:pid_or_pattern] =~ /^\d+$/
               [options[:pid_or_pattern]]
             else
               Utils.pgrep(options[:pid_or_pattern])
             end
  @use_quantiles = quantiles
end

Instance Method Details

#probe_countObject



94
95
96
97
98
99
100
101
102
# File 'lib/gitlab_exporter/process.rb', line 94

def probe_count
  puts "[DEPRECATED] probe_count and ProcessProber are now considered obsolete"\
    " and will be removed in future major versions,"\
    " please use metrics produced by application processes instead"

  @metrics.add("process_count", @pids.count, name: @name.downcase)

  self
end

#probe_smapsObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/gitlab_exporter/process.rb', line 104

def probe_smaps
  puts "[DEPRECATED] probe_smaps and ProcessProber are now considered obsolete"\
    " and will be removed in future major versions,"\
    " please use metrics produced by application processes instead"

  @pids.each do |pid|
    stats = ::GitLab::Exporter::MemStats::Aggregator.new(pid)

    next unless stats.valid?

    labels = { name: @name.downcase }
    labels[:pid] = pid unless @use_quantiles

    ::GitLab::Exporter::MemStats::Mapping::FIELDS.each do |field|
      value = stats.totals[field]

      @metrics.add("process_smaps_#{field}_bytes", value * 1024, @use_quantiles, **labels) if value >= 0
    end
  end

  self
end

#probe_statObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gitlab_exporter/process.rb', line 73

def probe_stat
  puts "[DEPRECATED] probe_stat and ProcessProber are now considered obsolete"\
    " and will be removed in future major versions,"\
    " please use metrics produced by application processes instead"

  @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



127
128
129
# File 'lib/gitlab_exporter/process.rb', line 127

def write_to(target)
  target.write(@metrics.to_s)
end