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
8ad18845
Commit
8ad18845
authored
Jun 14, 2016
by
Patricio Cano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Rubocop error
parent
9c87eeb3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
130 additions
and
0 deletions
+130
-0
lib/api/sidekiq_metrics.rb
lib/api/sidekiq_metrics.rb
+90
-0
spec/requests/api/sidekiq_metrics_spec.rb
spec/requests/api/sidekiq_metrics_spec.rb
+40
-0
No files found.
lib/api/sidekiq_metrics.rb
0 → 100644
View file @
8ad18845
require
'sidekiq/api'
module
API
class
SidekiqMetrics
<
Grape
::
API
before
{
authenticated_as_admin!
}
helpers
do
def
queue_metrics
Sidekiq
::
Queue
.
all
.
each_with_object
({})
do
|
queue
,
hash
|
hash
[
queue
.
name
]
=
{
backlog:
queue
.
size
,
latency:
queue
.
latency
.
to_i
}
end
end
def
process_metrics
Sidekiq
::
ProcessSet
.
new
.
map
do
|
process
|
{
hostname:
process
[
'hostname'
],
pid:
process
[
'pid'
],
tag:
process
[
'tag'
],
started_at:
Time
.
at
(
process
[
'started_at'
]),
queues:
process
[
'queues'
],
labels:
process
[
'labels'
],
concurrency:
process
[
'concurrency'
],
busy:
process
[
'busy'
]
}
end
end
def
job_stats
stats
=
Sidekiq
::
Stats
.
new
{
processed:
stats
.
processed
,
failed:
stats
.
failed
,
enqueued:
stats
.
enqueued
}
end
end
# Get Sidekiq Queue metrics
#
# Parameters:
# None
#
# Example:
# GET /sidekiq/queue_metrics
#
get
'sidekiq/queue_metrics'
do
{
queues:
queue_metrics
}
end
# Get Sidekiq Process metrics
#
# Parameters:
# None
#
# Example:
# GET /sidekiq/process_metrics
#
get
'sidekiq/process_metrics'
do
{
processes:
process_metrics
}
end
# Get Sidekiq Job statistics
#
# Parameters:
# None
#
# Example:
# GET /sidekiq/job_stats
#
get
'sidekiq/job_stats'
do
{
jobs:
job_stats
}
end
# Get Sidekiq Compound metrics. Includes all previous metrics
#
# Parameters:
# None
#
# Example:
# GET /sidekiq/compound_metrics
#
get
'sidekiq/compound_metrics'
do
{
queues:
queue_metrics
,
processes:
process_metrics
,
jobs:
job_stats
}
end
end
end
spec/requests/api/sidekiq_metrics_spec.rb
0 → 100644
View file @
8ad18845
require
'spec_helper'
describe
API
::
SidekiqMetrics
,
api:
true
do
include
ApiHelpers
let
(
:admin
)
{
create
(
:user
,
:admin
)
}
describe
'GET sidekiq/*'
do
it
'defines the `queue_metrics` endpoint'
do
get
api
(
'/sidekiq/queue_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
Hash
end
it
'defines the `process_metrics` endpoint'
do
get
api
(
'/sidekiq/process_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
[
'processes'
]).
to
be_an
Array
end
it
'defines the `job_stats` endpoint'
do
get
api
(
'/sidekiq/job_stats'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
Hash
end
it
'defines the `compound_metrics` endpoint'
do
get
api
(
'/sidekiq/compound_metrics'
,
admin
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_a
Hash
expect
(
json_response
[
'queues'
]).
to
be_a
Hash
expect
(
json_response
[
'processes'
]).
to
be_an
Array
expect
(
json_response
[
'jobs'
]).
to
be_a
Hash
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