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
0bfe7901
Commit
0bfe7901
authored
Aug 11, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add samples total and cleanup
parent
03b38a4a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
26 deletions
+55
-26
doc/user/project/integrations/prometheus.md
doc/user/project/integrations/prometheus.md
+2
-0
lib/gitlab/metrics/samplers/ruby_sampler.rb
lib/gitlab/metrics/samplers/ruby_sampler.rb
+53
-26
No files found.
doc/user/project/integrations/prometheus.md
View file @
0bfe7901
...
@@ -14,6 +14,8 @@ the settings page with a default template. To configure the template, see the
...
@@ -14,6 +14,8 @@ the settings page with a default template. To configure the template, see the
## Requirements
## Requirements
[
supported performance metrics
](
https://docs.gitlab.com/ee/user/project/integrations/prometheus_library/metrics.html
)
Integration with Prometheus requires the following:
Integration with Prometheus requires the following:
1.
GitLab 9.0 or higher
1.
GitLab 9.0 or higher
...
...
lib/gitlab/metrics/samplers/ruby_sampler.rb
View file @
0bfe7901
...
@@ -2,15 +2,14 @@ module Gitlab
...
@@ -2,15 +2,14 @@ module Gitlab
module
Metrics
module
Metrics
module
Samplers
module
Samplers
class
RubySampler
<
BaseSampler
class
RubySampler
<
BaseSampler
COUNTS
=
[
:count
,
:minor_gc_count
,
:major_gc_count
]
COUNTS
=
[
:count
,
:minor_gc_count
,
:major_gc_count
]
def
metrics
def
metrics
@metrics
||=
init_metrics
@metrics
||=
init_metrics
end
end
def
with_prefix
(
name
)
def
with_prefix
(
prefix
,
name
)
"ruby_
gc
_
#{
name
}
"
.
to_sym
"ruby_
#{
prefix
}
_
#{
name
}
"
.
to_sym
end
end
def
to_doc_string
(
name
)
def
to_doc_string
(
name
)
...
@@ -23,22 +22,40 @@ module Gitlab
...
@@ -23,22 +22,40 @@ module Gitlab
def
initialize
(
interval
)
def
initialize
(
interval
)
super
(
interval
)
super
(
interval
)
GC
::
Profiler
.
enable
Rails
.
logger
.
info
(
"123"
)
init_metrics
if
Gitlab
::
Metrics
.
mri?
require
'allocations'
Allocations
.
start
end
end
end
def
init_metrics
def
init_metrics
metrics
=
{}
metrics
=
{}
metrics
[
:total_time
]
=
Gitlab
::
Metrics
.
gauge
(
with_prefix
(
:total_time
),
to_doc_string
(
:total_time
),
labels
,
:livesum
)
metrics
[
:samples_total
]
=
Gitlab
::
Metrics
.
counter
(
with_prefix
(
:sampler
,
:total
),
'Total count of samples'
)
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
(
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
metrics
end
end
def
sample
def
sample
metrics
[
:samples_total
].
increment
(
labels
)
sample_gc
sample_objects
rescue
=>
ex
puts
ex
end
private
def
sample_gc
metrics
[
:total_time
].
set
(
labels
,
GC
::
Profiler
.
total_time
*
1000
)
metrics
[
:total_time
].
set
(
labels
,
GC
::
Profiler
.
total_time
*
1000
)
GC
.
stat
.
each
do
|
key
,
value
|
GC
.
stat
.
each
do
|
key
,
value
|
...
@@ -46,6 +63,34 @@ module Gitlab
...
@@ -46,6 +63,34 @@ module Gitlab
end
end
end
end
def
sample_objects
ss_objects
.
each
do
|
name
,
count
|
metrics
[
:objects_total
].
set
(
labels
.
merge
(
class:
name
),
count
)
end
end
if
Metrics
.
mri?
def
ss_objects
sample
=
Allocations
.
to_hash
counts
=
sample
.
each_with_object
({})
do
|
(
klass
,
count
),
hash
|
name
=
klass
.
name
next
unless
name
hash
[
name
]
=
count
end
# Symbols aren't allocated so we'll need to add those manually.
counts
[
'Symbol'
]
=
Symbol
.
all_symbols
.
length
counts
end
else
def
ss_objects
end
end
def
source_label
def
source_label
if
Sidekiq
.
server?
if
Sidekiq
.
server?
{
source:
'sidekiq'
}
{
source:
'sidekiq'
}
...
@@ -65,24 +110,6 @@ module Gitlab
...
@@ -65,24 +110,6 @@ module Gitlab
{
unicorn:
'master'
}
{
unicorn:
'master'
}
end
end
end
end
def
sample_gc
time
=
GC
::
Profiler
.
total_time
*
1000.0
stats
=
GC
.
stat
.
merge
(
total_time:
time
)
# We want the difference of GC runs compared to the last sample, not the
# total amount since the process started.
stats
[
:minor_gc_count
]
=
@last_minor_gc
.
compared_with
(
stats
[
:minor_gc_count
])
stats
[
:major_gc_count
]
=
@last_major_gc
.
compared_with
(
stats
[
:major_gc_count
])
stats
[
:count
]
=
stats
[
:minor_gc_count
]
+
stats
[
:major_gc_count
]
add_metric
(
'gc_statistics'
,
stats
)
end
end
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