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
c4d265c4
Commit
c4d265c4
authored
Aug 11, 2016
by
Pablo Carranza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add documentation
parent
e1e8c7a4
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
0 deletions
+41
-0
lib/gitlab_monitor.rb
lib/gitlab_monitor.rb
+1
-0
lib/gitlab_monitor/cli.rb
lib/gitlab_monitor/cli.rb
+13
-0
lib/gitlab_monitor/git.rb
lib/gitlab_monitor/git.rb
+16
-0
lib/gitlab_monitor/prometheus.rb
lib/gitlab_monitor/prometheus.rb
+6
-0
lib/gitlab_monitor/util.rb
lib/gitlab_monitor/util.rb
+5
-0
No files found.
lib/gitlab_monitor.rb
View file @
c4d265c4
module
GitLab
# GitLab Monitoring
module
Monitor
autoload
:CLI
,
"gitlab_monitor/cli"
autoload
:TimeTracker
,
"gitlab_monitor/util"
...
...
lib/gitlab_monitor/cli.rb
View file @
c4d265c4
module
GitLab
module
Monitor
# Stores runner classes in a single place
#
# The entry point is the module method "for" which takes the name of a runner.
# In case the runner is invalid it will return a NullRunner which fails with an
# InvalidCLICommand error, which contains the general application usage instructions.
module
CLI
EXECUTABLE_NAME
=
"gitlab-mon"
.
freeze
...
...
@@ -9,6 +14,8 @@ module GitLab
class
InvalidCLICommand
<
RuntimeError
;
end
# Empty runner that will raise an InvalidCLICommand when executed to provide the usage
# in the exception message
class
NullRunner
def
initialize
(
args
)
end
...
...
@@ -19,6 +26,12 @@ module GitLab
end
end
# Git runner.
#
# Takes something that behaves like ARGV with optparse included as an argument.
#
# It will take 2 positional arguments once parsed, the first one for the repository location,
# the optional second one is an IO like object to write to
class
GIT
COMMAND_NAME
=
"git"
.
freeze
...
...
lib/gitlab_monitor/git.rb
View file @
c4d265c4
...
...
@@ -2,6 +2,14 @@ require "open3"
module
GitLab
module
Monitor
# Git monitoring helping class
#
# Takes a repository path for construction and provides 2 main methods:
# - pull
# - push
#
# Both methods return a CommandResult which includes the output of the execution
# plus the tracked execution time.
class
Git
def
initialize
(
repo
)
fail
"Repository
#{
repo
}
does not exists"
unless
Dir
.
exist?
repo
...
...
@@ -31,6 +39,10 @@ module GitLab
end
end
# Result of a command
#
# Provides some handy methods for checking if the execution failed and a simple to_s that will
# return the command output
CommandResult
=
Struct
.
new
(
:stdout
,
:status
)
do
def
failed?
status
.
nonzero?
...
...
@@ -45,6 +57,10 @@ module GitLab
end
end
# 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.
class
GitProber
def
initialize
(
options
,
metrics:
PrometheusMetrics
.
new
)
@metrics
=
metrics
...
...
lib/gitlab_monitor/prometheus.rb
View file @
c4d265c4
module
GitLab
module
Monitor
# Prometheus metrics container
#
# Provides a simple API to `add` metrics and then turn them `to_s` which will just
# dump all the metrics in prometheus format
#
# The add method also can take any arbitrary amount of labels in a `key: value` format.
class
PrometheusMetrics
def
initialize
@metrics
=
{}
...
...
lib/gitlab_monitor/util.rb
View file @
c4d265c4
module
GitLab
module
Monitor
# Simple time wrapper that provides a to_i and wraps the execution result
TrackedResult
=
Struct
.
new
(
:result
,
:time
)
do
def
to_i
time
end
end
# Time tracking object
#
# Provides a simple time tracking, and returns back the result plus the tracked time
# wraped in a TrackedResult struct
class
TimeTracker
def
track
@start
=
Time
.
now
.
to_f
...
...
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