Class: GitLab::Exporter::GitProcessProber
- Inherits:
-
Object
- Object
- GitLab::Exporter::GitProcessProber
- Defined in:
- lib/gitlab_exporter/git.rb
Overview
A special prober for git processes
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(metrics: PrometheusMetrics.new, quantiles: nil, **opts) ⇒ GitProcessProber
constructor
rubocop:disable Lint/UnusedMethodArgument.
-
#probe_git ⇒ Object
rubocop:disable Metrics/MethodLength.
- #write_to(target) ⇒ Object
Constructor Details
#initialize(metrics: PrometheusMetrics.new, quantiles: nil, **opts) ⇒ GitProcessProber
rubocop:disable Lint/UnusedMethodArgument
90 91 92 93 |
# File 'lib/gitlab_exporter/git.rb', line 90 def initialize(metrics: PrometheusMetrics.new, quantiles: nil, **opts) # rubocop:disable Lint/UnusedMethodArgument @metrics = metrics @quantiles = quantiles end |
Class Method Details
.extract_subcommand(cmd) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/gitlab_exporter/git.rb', line 138 def self.extract_subcommand(cmd) return if cmd.empty? cmd_splitted = cmd.split("\u0000") # cmdline does not return it space-separated cmd_splitted.shift # Because it's "git" cmd_splitted.shift while cmd_splitted.first && (cmd_splitted.first.empty? || cmd_splitted.first !~ /^[^-][a-z\-]*$/) cmd_splitted[0] end |
Instance Method Details
#probe_git ⇒ Object
rubocop:disable Metrics/MethodLength
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/gitlab_exporter/git.rb', line 95 def probe_git # rubocop:disable Metrics/MethodLength puts "[DEPRECATED] probe_git and GitProcessProber are now considered obsolete"\ " and will be removed in future major versions,"\ " please use git metrics produced by Gitaly instead" counts = Hash.new(0) Utils.pgrep("^git ").each do |pid| process_cmd = begin File.read("/proc/#{pid}/cmdline") rescue StandardError "" # Process file is gone (race condition) end subcommand = self.class.extract_subcommand(process_cmd) next unless subcommand # Unlikely, but just to be safe name = "git #{subcommand}" counts[name] += 1 prober = ProcessProber.new( { name: name, pid_or_pattern: pid, quantiles: @quantiles }, metrics: @metrics ) prober .probe_stat end counts.each do |name, count| @metrics.add("process_count", count, name: name) end self end |
#write_to(target) ⇒ Object
134 135 136 |
# File 'lib/gitlab_exporter/git.rb', line 134 def write_to(target) target.write(@metrics.to_s) end |