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
373c76a9
Commit
373c76a9
authored
Oct 10, 2016
by
Ahmad Sherif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Combine multiple probers into one
parent
02533e48
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
62 additions
and
24 deletions
+62
-24
Gemfile.lock
Gemfile.lock
+1
-1
config/gitlab-monitor.yml.example
config/gitlab-monitor.yml.example
+8
-6
lib/gitlab_monitor.rb
lib/gitlab_monitor.rb
+1
-0
lib/gitlab_monitor/prober.rb
lib/gitlab_monitor/prober.rb
+40
-0
lib/gitlab_monitor/version.rb
lib/gitlab_monitor/version.rb
+1
-1
lib/gitlab_monitor/web_exporter.rb
lib/gitlab_monitor/web_exporter.rb
+11
-16
No files found.
Gemfile.lock
View file @
373c76a9
PATH
remote: .
specs:
gitlab-monitor (0.0.
5
)
gitlab-monitor (0.0.
6
)
pg (~> 0.18.4)
sinatra (~> 1.4.7)
...
...
config/gitlab-monitor.yml.example
View file @
373c76a9
...
...
@@ -3,12 +3,14 @@ server:
listen_port: 4567
probes:
dead_tuples_count:
class_name: Database::DeadTuplesProber
methods:
- probe_db
opts:
connection_string: dbname=gitlabhq_development user=postgres
database:
multiple: true
dead_tuples_count:
class_name: Database::DeadTuplesProber
methods:
- probe_db
opts:
connection_string: dbname=gitlabhq_development user=postgres
git:
methods:
- probe_pull
...
...
lib/gitlab_monitor.rb
View file @
373c76a9
...
...
@@ -11,5 +11,6 @@ module GitLab
autoload
:Database
,
"gitlab_monitor/database"
autoload
:ProcessProber
,
"gitlab_monitor/process"
autoload
:WebExporter
,
"gitlab_monitor/web_exporter"
autoload
:Prober
,
"gitlab_monitor/prober"
end
end
lib/gitlab_monitor/prober.rb
0 → 100644
View file @
373c76a9
module
GitLab
module
Monitor
# A class to combine multiple probers into one
class
Prober
def
initialize
(
prober_opts
,
metrics:
PrometheusMetrics
.
new
)
@prober_opts
=
prober_opts
@metrics
=
metrics
resolve_prober_classes
end
def
probe_all
@prober_opts
.
each
do
|
_probe_name
,
params
|
Utils
.
wrap_in_array
(
params
[
:opts
]).
each
do
|
opts
|
prober
=
params
[
:class
].
new
(
opts
,
metrics:
@metrics
)
params
[
:methods
].
each
do
|
meth
|
prober
.
send
(
meth
)
end
end
end
end
def
write_to
(
target
)
target
.
write
(
@metrics
.
to_s
)
end
private
def
resolve_prober_classes
@prober_opts
.
each
do
|
probe_name
,
params
|
prober_class_name
=
params
[
:class_name
]
||
Utils
.
camel_case_string
(
"
#{
probe_name
}
_prober"
)
klass
=
prober_class_name
.
split
(
"::"
).
reduce
(
GitLab
::
Monitor
)
{
|
a
,
e
|
a
.
const_get
(
e
)
}
params
[
:class
]
=
klass
end
end
end
end
end
lib/gitlab_monitor/version.rb
View file @
373c76a9
module
GitLab
module
Monitor
VERSION
=
"0.0.
5
"
.
freeze
VERSION
=
"0.0.
6
"
.
freeze
end
end
lib/gitlab_monitor/web_exporter.rb
View file @
373c76a9
...
...
@@ -17,30 +17,25 @@ module GitLab
set
(
:port
,
config
.
fetch
(
:listen_port
,
4567
))
end
def
setup_probes
(
config
)
# rubocop:disable Metrics/AbcSize
def
setup_probes
(
config
)
(
config
||
{}).
each
do
|
probe_name
,
params
|
prober_class_name
=
params
.
delete
(
:class_name
)
||
Utils
.
camel_case_string
(
"
#{
probe_name
}
_prober"
)
prober_class
=
resolve_prober_class
(
prober_class_name
)
opts
=
if
params
.
delete
(
:multiple
)
params
else
{
probe_name
=>
params
}
end
get
"/
#{
probe_name
}
"
do
Utils
.
wrap_in_array
(
params
[
:opts
]).
each
do
|
opts
|
prober
=
prober_class
.
new
(
opts
,
metrics:
PrometheusMetrics
.
new
(
include_timestamp:
false
))
params
[
:methods
].
each
do
|
meth
|
prober
.
send
(
meth
)
end
prober
.
write_to
(
response
)
end
prober
=
Prober
.
new
(
opts
,
metrics:
PrometheusMetrics
.
new
(
include_timestamp:
false
))
prober
.
probe_all
prober
.
write_to
(
response
)
response
end
end
end
def
resolve_prober_class
(
prober_class_name
)
prober_class_name
.
split
(
"::"
).
reduce
(
GitLab
::
Monitor
)
do
|
ancestor
,
const_name
|
ancestor
.
const_get
(
const_name
)
end
end
end
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