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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
c97dc61a
Commit
c97dc61a
authored
Sep 06, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup transaction metrics
parent
3cc28601
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
49 additions
and
28 deletions
+49
-28
config/initializers/1_settings.rb
config/initializers/1_settings.rb
+1
-0
config/initializers/7_prometheus_metrics.rb
config/initializers/7_prometheus_metrics.rb
+13
-4
config/initializers/8_metrics.rb
config/initializers/8_metrics.rb
+0
-4
lib/gitlab/metrics/influx_db.rb
lib/gitlab/metrics/influx_db.rb
+6
-3
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+12
-2
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+17
-15
spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
+0
-0
No files found.
config/initializers/1_settings.rb
View file @
c97dc61a
...
...
@@ -535,6 +535,7 @@ Settings.webpack.dev_server['port'] ||= 3808
Settings
[
'monitoring'
]
||=
Settingslogic
.
new
({})
Settings
.
monitoring
[
'ip_whitelist'
]
||=
[
'127.0.0.1/8'
]
Settings
.
monitoring
[
'unicorn_sampler_interval'
]
||=
10
Settings
.
monitoring
[
'ruby_sampler_interval'
]
||=
60
Settings
.
monitoring
[
'sidekiq_exporter'
]
||=
Settingslogic
.
new
({})
Settings
.
monitoring
.
sidekiq_exporter
[
'enabled'
]
||=
false
Settings
.
monitoring
.
sidekiq_exporter
[
'address'
]
||=
'localhost'
...
...
config/initializers/7_prometheus_metrics.rb
View file @
c97dc61a
...
...
@@ -11,7 +11,15 @@ Prometheus::Client.configure do |config|
config
.
multiprocess_files_dir
||=
Rails
.
root
.
join
(
'tmp/prometheus_multiproc_dir'
)
end
config
.
pid_provider
=
Prometheus
::
Client
::
Support
::
Unicorn
.
method
(
:worker_pid_provider
)
config
.
pid_provider
=
->
do
wid
=
Prometheus
::
Client
::
Support
::
Unicorn
.
worker_id
wid
=
Process
.
pid
if
wid
.
nil?
if
wid
.
nil?
"process_pid_
#{
Process
.
pid
}
"
else
"worker_id_
#{
wid
}
"
end
end
end
Sidekiq
.
configure_server
do
|
config
|
...
...
@@ -20,6 +28,7 @@ Sidekiq.configure_server do |config|
end
end
# if Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab
::
Metrics
::
Samplers
::
RubySampler
.
initialize_instance
(
60
.
second
).
start
# end
if
Gitlab
::
Metrics
.
prometheus_metrics_enabled?
Gitlab
::
Metrics
::
Samplers
::
UnicornSampler
.
initialize_instance
(
Settings
.
monitoring
.
unicorn_sampler_interval
).
start
Gitlab
::
Metrics
::
Samplers
::
RubySampler
.
initialize_instance
(
Settings
.
monitoring
.
ruby_sampler_interval
).
start
end
config/initializers/8_metrics.rb
View file @
c97dc61a
...
...
@@ -123,10 +123,6 @@ def instrument_classes(instrumentation)
end
# rubocop:enable Metrics/AbcSize
unless
Sidekiq
.
server?
Gitlab
::
Metrics
::
Samplers
::
UnicornSampler
.
initialize_instance
(
Settings
.
monitoring
.
unicorn_sampler_interval
).
start
end
Gitlab
::
Application
.
configure
do
|
config
|
# 0 should be Sentry to catch errors in this middleware
config
.
middleware
.
insert
(
1
,
Gitlab
::
Metrics
::
RequestsRackMiddleware
)
...
...
lib/gitlab/metrics/influx_db.rb
View file @
c97dc61a
...
...
@@ -102,9 +102,12 @@ module Gitlab
real_time
=
(
real_stop
-
real_start
)
*
1000.0
cpu_time
=
cpu_stop
-
cpu_start
trans
.
increment
(
"
#{
name
}
_real_time"
,
real_time
)
trans
.
increment
(
"
#{
name
}
_cpu_time"
,
cpu_time
)
trans
.
increment
(
"
#{
name
}
_call_count"
,
1
)
Gitlab
::
Metrics
.
histogram
(
"gitlab_
#{
name
}
_real_duration"
.
to_sym
,
"Measure
#{
name
}
"
,
{},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
]).
observe
({},
real_time
)
Gitlab
::
Metrics
.
histogram
(
"gitlab_
#{
name
}
_cpu_duration"
.
to_sym
,
"Measure
#{
name
}
"
,
{},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
]).
observe
({},
cpu_time
)
trans
.
increment
(
"
#{
name
}
_real_time"
,
real_time
,
false
)
trans
.
increment
(
"
#{
name
}
_cpu_time"
,
cpu_time
,
false
)
trans
.
increment
(
"
#{
name
}
_call_count"
,
1
,
false
)
retval
end
...
...
lib/gitlab/metrics/subscribers/active_record.rb
View file @
c97dc61a
...
...
@@ -5,11 +5,21 @@ module Gitlab
class
ActiveRecord
<
ActiveSupport
::
Subscriber
attach_to
:active_record
def
self
.
metric_sql_duration_seconds
@metric_sql_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_sql_duration_seconds
,
'SQL duration seconds'
,
{},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
end
def
sql
(
event
)
self
.
class
.
metric_sql_duration_secodnds
.
observe
({},
event
.
duration
/
1000.0
)
return
unless
current_transaction
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
)
current_transaction
.
increment
(
:sql_count
,
1
)
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
current_transaction
.
increment
(
:sql_count
,
1
,
false
)
end
private
...
...
lib/gitlab/metrics/transaction.rb
View file @
c97dc61a
...
...
@@ -40,21 +40,21 @@ module Gitlab
@memory_after
-
@memory_before
end
def
self
.
metric_transaction_duration_
milli
seconds
@metric
s_transaction_duration_milli
seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_duration_
milli
seconds
,
'Transaction duration
milli
seconds'
,
def
self
.
metric_transaction_duration_seconds
@metric
_transaction_duration_
seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_duration_seconds
,
'Transaction duration seconds'
,
{},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
500
,
1000
0
]
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.
0
]
)
end
def
self
.
metric_transaction_allocated_memory_
mega
bytes
@metric_transaction_allocated_memory_
mega
bytes
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_allocated_memory_
mega
bytes
,
def
self
.
metric_transaction_allocated_memory_bytes
@metric_transaction_allocated_memory_bytes
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_allocated_memory_bytes
,
'Transaction allocated memory bytes'
,
{},
[
1
,
2
,
5
,
10
,
20
,
1
00
]
[
500000
,
1000000
,
2000000
,
5000000
,
10000000
,
20000000
,
1000000
00
]
)
end
...
...
@@ -69,8 +69,8 @@ module Gitlab
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
Transaction
.
metric_transaction_duration_
milliseconds
.
observe
({},
duration
)
Transaction
.
metric_transaction_allocated_memory_
megabytes
.
observe
({},
allocated_memory
)
Transaction
.
metric_transaction_duration_
seconds
.
observe
({},
duration
*
1000
)
Transaction
.
metric_transaction_allocated_memory_
bytes
.
observe
({},
allocated_memory
/
2
^
20
)
Thread
.
current
[
THREAD_KEY
]
=
nil
end
...
...
@@ -100,13 +100,15 @@ module Gitlab
method
end
def
increment
(
name
,
value
)
Gitlab
::
Metrics
.
counter
(
"gitlab_transaction_
#{
name
}
_total"
.
to_sym
,
"Transaction counter
#{
name
}
"
,
{}).
increment
({},
value
)
def
increment
(
name
,
value
,
compat
=
true
)
Gitlab
::
Metrics
.
counter
(
"gitlab_transaction_
#{
name
}
_total"
.
to_sym
,
"Transaction counter
#{
name
}
"
,
{})
.
increment
({},
value
)
if
compat
@values
[
name
]
+=
value
end
def
set
(
name
,
value
)
Gitlab
::
Metrics
.
gauge
(
"gitlab_transaction_
#{
name
}
"
.
to_sym
,
"Transaction gauge
#{
name
}
"
,
{},
:livesum
).
set
({},
value
)
def
set
(
name
,
value
,
compat
=
true
)
Gitlab
::
Metrics
.
gauge
(
"gitlab_transaction_
#{
name
}
"
.
to_sym
,
"Transaction gauge
#{
name
}
"
,
{},
:livesum
)
.
set
({},
value
)
if
compat
@values
[
name
]
=
value
end
...
...
spec/lib/gitlab/metrics/samplers/ruby_sampler_spec.rb
0 → 100644
View file @
c97dc61a
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