Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
4c04444e
Commit
4c04444e
authored
Aug 16, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished Ruby Sampler
+ Cleanup sampler, use latest Prometheus gem
parent
0bfe7901
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
19 deletions
+21
-19
config/initializers/7_prometheus_metrics.rb
config/initializers/7_prometheus_metrics.rb
+1
-1
lib/gitlab/metrics/samplers/ruby_sampler.rb
lib/gitlab/metrics/samplers/ruby_sampler.rb
+20
-18
No files found.
config/initializers/7_prometheus_metrics.rb
View file @
4c04444e
...
@@ -21,5 +21,5 @@ Sidekiq.configure_server do |config|
...
@@ -21,5 +21,5 @@ Sidekiq.configure_server do |config|
end
end
# if Gitlab::Metrics.prometheus_metrics_enabled?
# if Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab
::
Metrics
::
Samplers
::
RubySampler
.
initialize_instance
(
1
.
second
).
start
Gitlab
::
Metrics
::
Samplers
::
RubySampler
.
initialize_instance
(
60
.
second
).
start
# end
# end
lib/gitlab/metrics/samplers/ruby_sampler.rb
View file @
4c04444e
require
'prometheus/client/support/unicorn'
module
Gitlab
module
Gitlab
module
Metrics
module
Metrics
module
Samplers
module
Samplers
class
RubySampler
<
BaseSampler
class
RubySampler
<
BaseSampler
COUNTS
=
[
:count
,
:minor_gc_count
,
:major_gc_count
]
def
metrics
def
metrics
@metrics
||=
init_metrics
@metrics
||=
init_metrics
end
end
...
@@ -32,25 +32,30 @@ module Gitlab
...
@@ -32,25 +32,30 @@ module Gitlab
def
init_metrics
def
init_metrics
metrics
=
{}
metrics
=
{}
metrics
[
:sample
s_total
]
=
Gitlab
::
Metrics
.
counter
(
with_prefix
(
:sampler
,
:total
),
'Total count of samples'
)
metrics
[
:sample
r_duration
]
=
Gitlab
::
Metrics
.
histogram
(
with_prefix
(
:sampler_duration
,
:seconds
),
'Sampler time'
,
source_label
)
metrics
[
:total_time
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:gc
,
:time_total
),
'Total GC time'
,
labels
,
:livesum
)
metrics
[
:total_time
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:gc
,
:time_total
),
'Total GC time'
,
labels
,
:livesum
)
GC
.
stat
.
keys
.
each
do
|
key
|
GC
.
stat
.
keys
.
each
do
|
key
|
metrics
[
key
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:gc
,
key
),
to_doc_string
(
key
),
labels
,
:livesum
)
metrics
[
key
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:gc
,
key
),
to_doc_string
(
key
),
labels
,
:livesum
)
end
end
metrics
[
:objects_total
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:objects
,
:total
),
'Objects total'
,
labels
.
merge
(
class:
nil
),
:livesum
)
metrics
[
:objects_total
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:objects
,
:total
),
'Objects total'
,
labels
.
merge
(
class:
nil
),
:livesum
)
metrics
[
:memory_usage
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:memory
,
:usage_total
),
'Memory used total'
,
labels
,
:livesum
)
metrics
[
:file_descriptors
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:file
,
:descriptors_total
),
'File descriptors total'
,
labels
,
:livesum
)
metrics
metrics
end
end
def
sample
def
sample
start_time
=
System
.
monotonic_time
metrics
[
:samples_total
].
increment
(
labels
)
sample_gc
sample_gc
sample_objects
sample_objects
rescue
=>
ex
puts
ex
metrics
[
:memory_usage
].
set
(
labels
,
System
.
memory_usage
)
metrics
[
:file_descriptors
].
set
(
labels
,
System
.
file_descriptor_count
)
metrics
[
:sampler_duration
].
observe
(
source_label
,
(
System
.
monotonic_time
-
start_time
)
/
1000.0
)
ensure
GC
::
Profiler
.
clear
end
end
private
private
...
@@ -64,13 +69,13 @@ module Gitlab
...
@@ -64,13 +69,13 @@ module Gitlab
end
end
def
sample_objects
def
sample_objects
ss
_objects
.
each
do
|
name
,
count
|
list
_objects
.
each
do
|
name
,
count
|
metrics
[
:objects_total
].
set
(
labels
.
merge
(
class:
name
),
count
)
metrics
[
:objects_total
].
set
(
labels
.
merge
(
class:
name
),
count
)
end
end
end
end
if
Metrics
.
mri?
if
Metrics
.
mri?
def
ss
_objects
def
list
_objects
sample
=
Allocations
.
to_hash
sample
=
Allocations
.
to_hash
counts
=
sample
.
each_with_object
({})
do
|
(
klass
,
count
),
hash
|
counts
=
sample
.
each_with_object
({})
do
|
(
klass
,
count
),
hash
|
name
=
klass
.
name
name
=
klass
.
name
...
@@ -85,12 +90,10 @@ module Gitlab
...
@@ -85,12 +90,10 @@ module Gitlab
counts
counts
end
end
else
else
def
ss_objects
def
list_objects
end
end
end
end
def
source_label
def
source_label
if
Sidekiq
.
server?
if
Sidekiq
.
server?
{
source:
'sidekiq'
}
{
source:
'sidekiq'
}
...
@@ -101,11 +104,10 @@ module Gitlab
...
@@ -101,11 +104,10 @@ module Gitlab
def
worker_label
def
worker_label
return
{}
unless
defined?
(
Unicorn
::
Worker
)
return
{}
unless
defined?
(
Unicorn
::
Worker
)
worker
=
if
defined?
(
Unicorn
::
Worker
)
worker_no
=
::
Prometheus
::
Client
::
Support
::
Unicorn
.
worker_id
ObjectSpace
.
each_object
(
Unicorn
::
Worker
)
&
.
first
end
if
worker_no
if
worker
{
unicorn:
worker_no
}
{
unicorn:
worker
.
nr
}
else
else
{
unicorn:
'master'
}
{
unicorn:
'master'
}
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