Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
gitlab-org
gitlab-exporter
Commits
e1e8c7a4
Commit
e1e8c7a4
authored
Aug 11, 2016
by
Pablo Carranza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rubocop auto correct pass
parent
af76f6af
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
20 additions
and
23 deletions
+20
-23
bin/gitlab-mon
bin/gitlab-mon
+0
-1
lib/gitlab_monitor/cli.rb
lib/gitlab_monitor/cli.rb
+8
-8
lib/gitlab_monitor/git.rb
lib/gitlab_monitor/git.rb
+1
-1
lib/gitlab_monitor/prometheus.rb
lib/gitlab_monitor/prometheus.rb
+3
-3
lib/gitlab_monitor/util.rb
lib/gitlab_monitor/util.rb
+0
-1
lib/gitlab_monitor/version.rb
lib/gitlab_monitor/version.rb
+1
-1
spec/git_spec.rb
spec/git_spec.rb
+4
-6
spec/prometheus_metrics_spec.rb
spec/prometheus_metrics_spec.rb
+2
-1
spec/util_spec.rb
spec/util_spec.rb
+1
-1
No files found.
bin/gitlab-mon
View file @
e1e8c7a4
#!/usr/bin/env ruby
require
"optparse"
require
"gitlab_monitor"
...
...
lib/gitlab_monitor/cli.rb
View file @
e1e8c7a4
...
...
@@ -35,18 +35,18 @@ module GitLab
def
run
validate!
::
GitLab
::
Monitor
::
GitProber
.
new
(
self
)
.
probe_pull
.
probe_push
.
write_to
(
@target
)
::
GitLab
::
Monitor
::
GitProber
.
new
(
self
)
.
probe_pull
.
probe_push
.
write_to
(
@target
)
end
def
options
(
args
)
args
.
options
do
|
opts
|
opts
.
banner
=
"Usage:
#{
EXECUTABLE_NAME
}
#{
COMMAND_NAME
}
[options] repository_path [target_file]"
opts
.
on
(
"-l"
,
"--labels=key=value,key2=value2"
,
"Labels to append to the metrics"
)
{
|
val
|
@labels
=
val
.
split
(
","
).
map
{
|
value
|
value
.
split
(
"="
).
tap
{
|
aa
|
aa
[
0
]
=
aa
[
0
].
to_sym
}
}.
to_h
}
opts
.
on
(
"-l"
,
"--labels=key=value,key2=value2"
,
"Labels to append to the metrics"
)
do
|
val
|
@labels
=
val
.
split
(
","
).
map
{
|
value
|
value
.
split
(
"="
).
tap
{
|
aa
|
aa
[
0
]
=
aa
[
0
].
to_sym
}
}.
to_h
end
opts
end
end
...
...
@@ -62,7 +62,7 @@ module GitLab
end
def
self
.
commands
[
GIT
].
in
ject
({})
do
|
commands
,
command
_clas
s
|
[
GIT
].
each_with_ob
ject
({})
do
|
command
_clas
s
,
commands
|
commands
[
command_class
::
COMMAND_NAME
]
=
command_class
commands
end
...
...
lib/gitlab_monitor/git.rb
View file @
e1e8c7a4
...
...
@@ -18,7 +18,7 @@ module GitLab
@tracker
.
track
{
execute
"git push -q"
}
end
def
empty_commit
(
message
=
"Beep"
)
def
empty_commit
(
message
=
"Beep"
)
@tracker
.
track
{
execute
(
"git commit --allow-empty -m '
#{
message
}
'"
)
}
end
...
...
lib/gitlab_monitor/prometheus.rb
View file @
e1e8c7a4
...
...
@@ -6,18 +6,18 @@ module GitLab
end
def
add
(
name
,
value
,
**
labels
)
@metrics
[
name
]
=
{
value:
value
,
labels:
labels
,
timestamp:
(
Time
.
now
.
to_f
*
1000
).
to_i
}
@metrics
[
name
]
=
{
value:
value
,
labels:
labels
,
timestamp:
(
Time
.
now
.
to_f
*
1000
).
to_i
}
self
end
def
to_s
buffer
=
StringIO
.
new
@metrics
.
each
{
|
name
,
metrics
|
@metrics
.
each
do
|
name
,
metrics
|
buffer
.
write
(
name
.
to_s
)
labels
=
(
metrics
[
:labels
]
||
{}).
map
{
|
label
,
value
|
"
#{
label
}
=
\"
#{
value
}
\"
"
}.
join
(
","
)
buffer
.
write
(
"{
#{
labels
}
}"
)
unless
labels
.
empty?
buffer
.
write
(
"
#{
metrics
[
:value
]
}
#{
metrics
[
:timestamp
]
}
\n
"
)
}
end
buffer
.
rewind
buffer
.
read
end
...
...
lib/gitlab_monitor/util.rb
View file @
e1e8c7a4
...
...
@@ -15,4 +15,3 @@ module GitLab
end
end
end
lib/gitlab_monitor/version.rb
View file @
e1e8c7a4
module
GitLab
module
Monitor
VERSION
=
"0.0.1"
VERSION
=
"0.0.1"
.
freeze
end
end
spec/git_spec.rb
View file @
e1e8c7a4
...
...
@@ -7,18 +7,17 @@ context "An invalid repository" do
it
"fails with an invalid repository"
do
repo
=
Dir
.
mktmpdir
Dir
.
rmdir
(
repo
)
expect
{
GitLab
::
Monitor
::
Git
.
new
(
repo
)}.
to
raise_error
(
/Repository
#{
repo
}
does not exists/
)
expect
{
GitLab
::
Monitor
::
Git
.
new
(
repo
)
}.
to
raise_error
(
/Repository
#{
repo
}
does not exists/
)
end
end
end
GitProberOptions
=
Struct
.
new
(
:source
,
:labels
)
context
"With valid pair of repositories"
do
let
(
:repos
)
{
GitRepoBuilder
.
new
}
after
{
repos
.
cleanup
}
after
do
repos
.
cleanup
end
describe
GitLab
::
Monitor
::
Git
do
it
"builds with a repo folder"
do
...
...
@@ -26,11 +25,11 @@ context "With valid pair of repositories" do
end
it
"pulls correctly"
do
expect
(
GitLab
::
Monitor
::
Git
.
new
(
repos
.
cloned_repo
).
pull
.
time
).
to
satisfy
{
|
v
|
v
>=
0
}
expect
(
GitLab
::
Monitor
::
Git
.
new
(
repos
.
cloned_repo
).
pull
.
time
).
to
satisfy
{
|
v
|
v
>=
0
}
end
it
"pushes correctly"
do
expect
(
GitLab
::
Monitor
::
Git
.
new
(
repos
.
cloned_repo
).
push
.
time
).
to
satisfy
{
|
v
|
v
>=
0
}
expect
(
GitLab
::
Monitor
::
Git
.
new
(
repos
.
cloned_repo
).
push
.
time
).
to
satisfy
{
|
v
|
v
>=
0
}
end
end
...
...
@@ -74,4 +73,3 @@ context "With valid pair of repositories" do
end
end
end
spec/prometheus_metrics_spec.rb
View file @
e1e8c7a4
...
...
@@ -11,6 +11,7 @@ describe GitLab::Monitor::PrometheusMetrics do
it
"supports metrics with many labels"
do
expect
(
subject
.
add
(
"mymetric"
,
1.3
,
mylabel:
"x"
,
myotherlabel:
"y"
).
to_s
).
to
match
(
/mymetric{mylabel="x",myotherlabel="y"} 1.3 \d*$/
)
/mymetric{mylabel="x",myotherlabel="y"} 1.3 \d*$/
)
end
end
spec/util_spec.rb
View file @
e1e8c7a4
...
...
@@ -2,6 +2,6 @@ require "spec_helper"
describe
GitLab
::
Monitor
::
TimeTracker
do
it
"tracks execution time"
do
expect
(
subject
.
track
{
sleep
0.1
}.
time
).
to
satisfy
{
|
v
|
v
>=
0.1
}
expect
(
subject
.
track
{
sleep
0.1
}.
time
).
to
satisfy
{
|
v
|
v
>=
0.1
}
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment