Class: GitLab::Monitor::GitProber
- Inherits:
-
Object
- Object
- GitLab::Monitor::GitProber
- Defined in:
- lib/gitlab_monitor/git.rb
Overview
Handles creating a Git object, probing for both pull and push, and finally writing to metrics
Optionally takes a metrics object which by default is a PrometheusMetrics, useful to change the metrics writer to something else.
Instance Method Summary collapse
-
#initialize(opts, metrics: PrometheusMetrics.new) ⇒ GitProber
constructor
A new instance of GitProber.
- #probe_pull ⇒ Object
- #probe_push ⇒ Object
- #write_to(target) ⇒ Object
Constructor Details
#initialize(opts, metrics: PrometheusMetrics.new) ⇒ GitProber
Returns a new instance of GitProber.
65 66 67 68 69 |
# File 'lib/gitlab_monitor/git.rb', line 65 def initialize(opts, metrics: PrometheusMetrics.new) @metrics = metrics @labels = opts[:labels] || {} @git = Git.new(opts[:source]) end |
Instance Method Details
#probe_pull ⇒ Object
71 72 73 74 |
# File 'lib/gitlab_monitor/git.rb', line 71 def probe_pull @metrics.add "git_pull_time_milliseconds", (@git.pull.time * 1000).to_i, **@labels self end |
#probe_push ⇒ Object
76 77 78 79 |
# File 'lib/gitlab_monitor/git.rb', line 76 def probe_push @metrics.add "git_push_time_milliseconds", (@git.push.time * 1000).to_i, **@labels self end |
#write_to(target) ⇒ Object
81 82 83 |
# File 'lib/gitlab_monitor/git.rb', line 81 def write_to(target) target.write(@metrics.to_s) end |