Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
8ad18845
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8ad18845
编写于
6月 14, 2016
作者:
P
Patricio Cano
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed Rubocop error
上级
9c87eeb3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
130 addition
and
0 deletion
+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
未找到文件。
lib/api/sidekiq_metrics.rb
0 → 100644
浏览文件 @
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
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录