gitlab-monitor 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +2 -0
- data/.gitlab-ci.yml +18 -0
- data/.rubocop.yml +34 -0
- data/CONTRIBUTING.md +651 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +75 -0
- data/LICENSE +25 -0
- data/README.md +110 -0
- data/bin/gitlab-mon +17 -0
- data/config/gitlab-monitor.yml.example +112 -0
- data/gitlab-monitor.gemspec +33 -0
- data/lib/gitlab_monitor.rb +18 -0
- data/lib/gitlab_monitor/cli.rb +341 -0
- data/lib/gitlab_monitor/database.rb +13 -0
- data/lib/gitlab_monitor/database/base.rb +44 -0
- data/lib/gitlab_monitor/database/bloat.rb +74 -0
- data/lib/gitlab_monitor/database/bloat_btree.sql +84 -0
- data/lib/gitlab_monitor/database/bloat_table.sql +63 -0
- data/lib/gitlab_monitor/database/ci_builds.rb +527 -0
- data/lib/gitlab_monitor/database/remote_mirrors.rb +74 -0
- data/lib/gitlab_monitor/database/row_count.rb +164 -0
- data/lib/gitlab_monitor/database/tuple_stats.rb +53 -0
- data/lib/gitlab_monitor/git.rb +144 -0
- data/lib/gitlab_monitor/memstats.rb +98 -0
- data/lib/gitlab_monitor/memstats/mapping.rb +91 -0
- data/lib/gitlab_monitor/prober.rb +40 -0
- data/lib/gitlab_monitor/process.rb +122 -0
- data/lib/gitlab_monitor/prometheus.rb +64 -0
- data/lib/gitlab_monitor/sidekiq.rb +149 -0
- data/lib/gitlab_monitor/sidekiq_queue_job_stats.lua +42 -0
- data/lib/gitlab_monitor/util.rb +83 -0
- data/lib/gitlab_monitor/version.rb +5 -0
- data/lib/gitlab_monitor/web_exporter.rb +77 -0
- data/spec/cli_spec.rb +31 -0
- data/spec/database/bloat_spec.rb +99 -0
- data/spec/database/ci_builds_spec.rb +421 -0
- data/spec/database/row_count_spec.rb +37 -0
- data/spec/fixtures/smaps/sample.txt +10108 -0
- data/spec/git_process_proper_spec.rb +27 -0
- data/spec/git_spec.rb +52 -0
- data/spec/memstats_spec.rb +28 -0
- data/spec/prometheus_metrics_spec.rb +17 -0
- data/spec/spec_helper.rb +63 -0
- data/spec/util_spec.rb +15 -0
- metadata +225 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "gitlab_monitor"
|
3
|
+
|
4
|
+
# rubocop:disable Metrics/LineLength
|
5
|
+
describe GitLab::Monitor::GitProcessProber do
|
6
|
+
describe ".extract_subcommand" do
|
7
|
+
it "extract git subcommand" do
|
8
|
+
command_subcommands = {
|
9
|
+
"git upload-pack --stateless-rpc --advertise-refs /repositories/Hey/project.git" => "upload-pack",
|
10
|
+
"git --git-dir=/repositories/null/gitlab-ce.git fetch upstream --tags" => "fetch",
|
11
|
+
"git --shallow-file pack-objects --revs --thin --stdout --shallow --delta-base-offset" => "pack-objects",
|
12
|
+
"git /repositories/some/thing.git pack-objects" => "pack-objects",
|
13
|
+
"git --git-dir=/repositories/Fact/arti.git cat-file blob 13b39ff4503badb8182b901c471039d6ab6ab96b" => "cat-file",
|
14
|
+
"git --git-dir /repositories/Fact/arti.git cat-file blob 13b39ff4503badb8182b901c471039d6ab6ab96b" => "cat-file",
|
15
|
+
"git --git-dir=/repositories/an/web.git gc" => "gc",
|
16
|
+
"git --git-dir=/repositories/an/web.git gc" => "gc",
|
17
|
+
"git --git-dir /repositories/an/web.git gc" => "gc",
|
18
|
+
"git --git-dir /repositories/an/web.git" => nil
|
19
|
+
}
|
20
|
+
|
21
|
+
command_subcommands.each do |command, subcommand|
|
22
|
+
cmdline = command.tr(" ", "\u0000")
|
23
|
+
expect(described_class.extract_subcommand(cmdline)).to eq(subcommand)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/git_spec.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "stringio"
|
3
|
+
require "gitlab_monitor/cli"
|
4
|
+
|
5
|
+
context "An invalid repository" do
|
6
|
+
describe GitLab::Monitor::Git do
|
7
|
+
it "fails with an invalid repository" do
|
8
|
+
repo = Dir.mktmpdir
|
9
|
+
Dir.rmdir(repo)
|
10
|
+
expect { GitLab::Monitor::Git.new(repo) }.to raise_error(/Repository #{repo} does not exists/)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "With valid pair of repositories" do
|
16
|
+
let(:repos) { GitRepoBuilder.new }
|
17
|
+
|
18
|
+
after do
|
19
|
+
repos.cleanup
|
20
|
+
end
|
21
|
+
|
22
|
+
describe GitLab::Monitor::Git do
|
23
|
+
it "builds with a repo folder" do
|
24
|
+
expect(GitLab::Monitor::Git.new(repos.cloned_repo)).to be
|
25
|
+
end
|
26
|
+
|
27
|
+
it "pulls correctly" do
|
28
|
+
expect(GitLab::Monitor::Git.new(repos.cloned_repo).pull.time).to satisfy { |v| v >= 0 }
|
29
|
+
end
|
30
|
+
|
31
|
+
it "pushes correctly" do
|
32
|
+
expect(GitLab::Monitor::Git.new(repos.cloned_repo).push.time).to satisfy { |v| v >= 0 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe GitLab::Monitor::GitProber do
|
37
|
+
let(:options) { GitProberOptions.new(repos.cloned_repo, {}) }
|
38
|
+
let(:output) { StringIO.new }
|
39
|
+
|
40
|
+
it "probes and monitors a pull" do
|
41
|
+
prober = GitLab::Monitor::GitProber.new(options)
|
42
|
+
prober.probe_pull.write_to(output)
|
43
|
+
expect(output.string).to match(/git_pull_time_milliseconds \d+ \d+/)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "probes and monitors a push" do
|
47
|
+
prober = GitLab::Monitor::GitProber.new(options)
|
48
|
+
prober.probe_push.write_to(output)
|
49
|
+
expect(output.string).to match(/git_push_time_milliseconds \d+ \d+/)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "gitlab_monitor/memstats"
|
3
|
+
|
4
|
+
describe GitLab::Monitor::MemStats do
|
5
|
+
let(:pid) { 100 }
|
6
|
+
let(:smaps_data) { File.open("spec/fixtures/smaps/sample.txt") }
|
7
|
+
|
8
|
+
subject { described_class::Aggregator.new(pid) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
expect(File).to receive(:open).with("/proc/#{pid}/smaps").and_yield(smaps_data)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses the data properly" do
|
15
|
+
expect(subject.valid?).to be_truthy
|
16
|
+
|
17
|
+
nonzero_fields = %w(size rss shared_clean shared_dirty private_dirty pss)
|
18
|
+
zero_fields = %w(private_clean swap)
|
19
|
+
|
20
|
+
nonzero_fields.each do |field|
|
21
|
+
expect(subject.totals[field]).to be > 0 # rubocop:disable Style/NumericPredicate
|
22
|
+
end
|
23
|
+
|
24
|
+
zero_fields.each do |field|
|
25
|
+
expect(subject.totals[field]).to eq(0)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GitLab::Monitor::PrometheusMetrics do
|
4
|
+
it "supports simple metrics" do
|
5
|
+
expect(subject.add("mymetric", 1.1).to_s).to match(/mymetric 1.1 \d*$/)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "supports metrics with one label" do
|
9
|
+
expect(subject.add("mymetric", 1.2, mylabel: "x").to_s).to match(/mymetric{mylabel="x"} 1.2 \d*$/)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "supports metrics with many labels" do
|
13
|
+
expect(subject.add("mymetric", 1.3, mylabel: "x", myotherlabel: "y").to_s).to match(
|
14
|
+
/mymetric{mylabel="x",myotherlabel="y"} 1.3 \d*$/
|
15
|
+
)
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "gitlab_monitor"
|
3
|
+
|
4
|
+
require "open3"
|
5
|
+
require "tmpdir"
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift File.expand_path(".")
|
8
|
+
Dir["spec/support/**/*.rb"].each do |f| require f end
|
9
|
+
|
10
|
+
class GitRepoBuilder
|
11
|
+
def origin
|
12
|
+
@origin ||= create_origin
|
13
|
+
end
|
14
|
+
|
15
|
+
def cloned_repo
|
16
|
+
@cloned_repo ||= clone_origin
|
17
|
+
end
|
18
|
+
|
19
|
+
def cleanup
|
20
|
+
FileUtils.rm_r(@origin) if @origin
|
21
|
+
FileUtils.rm_r(@cloned_repo) if @cloned_repo
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def create_origin
|
27
|
+
path = Dir.mktmpdir
|
28
|
+
Open3.capture3("git init", chdir: path)
|
29
|
+
Open3.capture3("git commit --allow-empty -m 'Beep'", chdir: path)
|
30
|
+
Open3.capture3("git checkout -b other", chdir: path)
|
31
|
+
path
|
32
|
+
end
|
33
|
+
|
34
|
+
def clone_origin
|
35
|
+
path = Dir.mktmpdir
|
36
|
+
Dir.rmdir(path)
|
37
|
+
Open3.capture3("git clone #{origin} #{path}")
|
38
|
+
Open3.capture3("git checkout master", chdir: path)
|
39
|
+
path
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
GitProberOptions = Struct.new(:source, :labels)
|
44
|
+
|
45
|
+
class CLIArgs
|
46
|
+
def initialize(args)
|
47
|
+
@arguments = args
|
48
|
+
end
|
49
|
+
|
50
|
+
def options
|
51
|
+
yield self
|
52
|
+
end
|
53
|
+
|
54
|
+
def on(*args)
|
55
|
+
end
|
56
|
+
|
57
|
+
def banner=(banner)
|
58
|
+
end
|
59
|
+
|
60
|
+
def parse!
|
61
|
+
@arguments
|
62
|
+
end
|
63
|
+
end
|
data/spec/util_spec.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe GitLab::Monitor::TimeTracker do
|
4
|
+
it "tracks execution time" do
|
5
|
+
expect(subject.track { sleep 0.1 }.time).to satisfy { |v| v >= 0.1 }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe GitLab::Monitor::Utils do
|
10
|
+
it "excludes extraneous PIDs" do
|
11
|
+
allow(described_class).to receive(:exec_pgrep).and_return("12345 my-process\n98765 sh\n")
|
12
|
+
|
13
|
+
expect(described_class.pgrep("some-process")).to eq(["12345"])
|
14
|
+
end
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitlab-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 4.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pablo Carranza
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pg
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sinatra
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.0.4
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.0.4
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: quantile
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sidekiq
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 5.2.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 5.2.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: redis-namespace
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.6.0
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.6.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: connection_pool
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 2.2.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 2.2.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 3.7.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 3.7.0
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec-expectations
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 3.7.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 3.7.0
|
139
|
+
description: GitLab monitoring tools to use with prometheus
|
140
|
+
email: pablo@gitlab.com
|
141
|
+
executables:
|
142
|
+
- gitlab-mon
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".gitignore"
|
147
|
+
- ".gitlab-ci.yml"
|
148
|
+
- ".rubocop.yml"
|
149
|
+
- CONTRIBUTING.md
|
150
|
+
- Gemfile
|
151
|
+
- Gemfile.lock
|
152
|
+
- LICENSE
|
153
|
+
- README.md
|
154
|
+
- bin/gitlab-mon
|
155
|
+
- config/gitlab-monitor.yml.example
|
156
|
+
- gitlab-monitor.gemspec
|
157
|
+
- lib/gitlab_monitor.rb
|
158
|
+
- lib/gitlab_monitor/cli.rb
|
159
|
+
- lib/gitlab_monitor/database.rb
|
160
|
+
- lib/gitlab_monitor/database/base.rb
|
161
|
+
- lib/gitlab_monitor/database/bloat.rb
|
162
|
+
- lib/gitlab_monitor/database/bloat_btree.sql
|
163
|
+
- lib/gitlab_monitor/database/bloat_table.sql
|
164
|
+
- lib/gitlab_monitor/database/ci_builds.rb
|
165
|
+
- lib/gitlab_monitor/database/remote_mirrors.rb
|
166
|
+
- lib/gitlab_monitor/database/row_count.rb
|
167
|
+
- lib/gitlab_monitor/database/tuple_stats.rb
|
168
|
+
- lib/gitlab_monitor/git.rb
|
169
|
+
- lib/gitlab_monitor/memstats.rb
|
170
|
+
- lib/gitlab_monitor/memstats/mapping.rb
|
171
|
+
- lib/gitlab_monitor/prober.rb
|
172
|
+
- lib/gitlab_monitor/process.rb
|
173
|
+
- lib/gitlab_monitor/prometheus.rb
|
174
|
+
- lib/gitlab_monitor/sidekiq.rb
|
175
|
+
- lib/gitlab_monitor/sidekiq_queue_job_stats.lua
|
176
|
+
- lib/gitlab_monitor/util.rb
|
177
|
+
- lib/gitlab_monitor/version.rb
|
178
|
+
- lib/gitlab_monitor/web_exporter.rb
|
179
|
+
- spec/cli_spec.rb
|
180
|
+
- spec/database/bloat_spec.rb
|
181
|
+
- spec/database/ci_builds_spec.rb
|
182
|
+
- spec/database/row_count_spec.rb
|
183
|
+
- spec/fixtures/smaps/sample.txt
|
184
|
+
- spec/git_process_proper_spec.rb
|
185
|
+
- spec/git_spec.rb
|
186
|
+
- spec/memstats_spec.rb
|
187
|
+
- spec/prometheus_metrics_spec.rb
|
188
|
+
- spec/spec_helper.rb
|
189
|
+
- spec/util_spec.rb
|
190
|
+
homepage: http://gitlab.com
|
191
|
+
licenses:
|
192
|
+
- MIT
|
193
|
+
metadata: {}
|
194
|
+
post_install_message:
|
195
|
+
rdoc_options: []
|
196
|
+
require_paths:
|
197
|
+
- lib
|
198
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
199
|
+
requirements:
|
200
|
+
- - ">="
|
201
|
+
- !ruby/object:Gem::Version
|
202
|
+
version: '0'
|
203
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
requirements:
|
205
|
+
- - ">="
|
206
|
+
- !ruby/object:Gem::Version
|
207
|
+
version: '0'
|
208
|
+
requirements: []
|
209
|
+
rubyforge_project:
|
210
|
+
rubygems_version: 2.7.6
|
211
|
+
signing_key:
|
212
|
+
specification_version: 4
|
213
|
+
summary: GitLab monitoring tools
|
214
|
+
test_files:
|
215
|
+
- spec/cli_spec.rb
|
216
|
+
- spec/database/bloat_spec.rb
|
217
|
+
- spec/database/ci_builds_spec.rb
|
218
|
+
- spec/database/row_count_spec.rb
|
219
|
+
- spec/fixtures/smaps/sample.txt
|
220
|
+
- spec/git_process_proper_spec.rb
|
221
|
+
- spec/git_spec.rb
|
222
|
+
- spec/memstats_spec.rb
|
223
|
+
- spec/prometheus_metrics_spec.rb
|
224
|
+
- spec/spec_helper.rb
|
225
|
+
- spec/util_spec.rb
|