Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
f79ae414
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
f79ae414
编写于
11月 21, 2018
作者:
Z
zryfish
提交者:
GitHub
11月 21, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #210 from carmanzhang/monitor
changed promqls and fixed several monitoring bugs
上级
7f780bd3
982c4ac3
变更
5
展开全部
显示空白变更内容
内联
并排
Showing
5 changed file
with
289 addition
and
183 deletion
+289
-183
pkg/apis/v1alpha/monitoring/monitor_handler.go
pkg/apis/v1alpha/monitoring/monitor_handler.go
+7
-6
pkg/models/metrics/metrics.go
pkg/models/metrics/metrics.go
+91
-28
pkg/models/metrics/metricsrule.go
pkg/models/metrics/metricsrule.go
+12
-2
pkg/models/metrics/metricsruleconst.go
pkg/models/metrics/metricsruleconst.go
+151
-146
pkg/models/metrics/util.go
pkg/models/metrics/util.go
+28
-1
未找到文件。
pkg/apis/v1alpha/monitoring/monitor_handler.go
浏览文件 @
f79ae414
...
...
@@ -73,12 +73,14 @@ func (u Monitor) monitorAllWorkspaces(request *restful.Request, response *restfu
requestParams
:=
client
.
ParseMonitoringRequestParams
(
request
)
if
requestParams
.
Tp
==
"_statistics"
{
tp
:=
requestParams
.
Tp
if
tp
==
"_statistics"
{
// merge multiple metric: all-devops, all-roles, all-projects...this api is designed for admin
res
:=
metrics
.
MonitorAllWorkspacesStatistics
()
response
.
WriteAsJson
(
res
)
}
else
{
}
else
if
tp
==
"rank"
{
rawMetrics
:=
metrics
.
MonitorAllWorkspaces
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
,
metrics
.
MetricLevelWorkspace
)
...
...
@@ -86,6 +88,9 @@ func (u Monitor) monitorAllWorkspaces(request *restful.Request, response *restfu
pagedMetrics
:=
metrics
.
Page
(
requestParams
.
PageNum
,
requestParams
.
LimitNum
,
sortedMetrics
,
maxMetricCount
)
response
.
WriteAsJson
(
pagedMetrics
)
}
else
{
res
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelWorkspace
)
response
.
WriteAsJson
(
res
)
}
}
...
...
@@ -145,10 +150,6 @@ func (u Monitor) monitorCluster(request *restful.Request, response *restful.Resp
queryType
,
params
:=
metrics
.
AssembleClusterMetricRequestInfo
(
requestParams
,
metricName
)
res
:=
metrics
.
GetMetric
(
queryType
,
params
,
metricName
)
if
metricName
==
metrics
.
MetricNameWorkspaceAllProjectCount
{
res
=
metrics
.
MonitorWorkspaceNamespaceHistory
(
res
)
}
response
.
WriteAsJson
(
res
)
}
else
{
// multiple
...
...
pkg/models/metrics/metrics.go
浏览文件 @
f79ae414
...
...
@@ -277,12 +277,28 @@ func AssembleNamespaceMetricRequestInfo(monitoringRequest *client.MonitoringRequ
return
queryType
,
params
}
func
AssembleWorkspaceMetricRequestInfo
(
monitoringRequest
*
client
.
MonitoringRequestParams
,
namespaceList
[]
string
,
metricName
string
)
(
string
,
string
)
{
func
AssembleSpecificWorkspaceMetricRequestInfo
(
monitoringRequest
*
client
.
MonitoringRequestParams
,
namespaceList
[]
string
,
metricName
string
)
(
string
,
string
)
{
nsFilter
:=
"^("
+
strings
.
Join
(
namespaceList
,
"|"
)
+
")$"
queryType
:=
monitoringRequest
.
QueryType
rule
:=
MakeWorkspacePromQL
(
metricName
,
nsFilter
)
rule
:=
MakeSpecificWorkspacePromQL
(
metricName
,
nsFilter
)
paramValues
:=
monitoringRequest
.
Params
params
:=
makeRequestParamString
(
rule
,
paramValues
)
return
queryType
,
params
}
func
AssembleAllWorkspaceMetricRequestInfo
(
monitoringRequest
*
client
.
MonitoringRequestParams
,
namespaceList
[]
string
,
metricName
string
)
(
string
,
string
)
{
var
nsFilter
=
"^()$"
if
namespaceList
!=
nil
{
nsFilter
=
"^("
+
strings
.
Join
(
namespaceList
,
"|"
)
+
")$"
}
queryType
:=
monitoringRequest
.
QueryType
rule
:=
MakeAllWorkspacesPromQL
(
metricName
,
nsFilter
)
paramValues
:=
monitoringRequest
.
Params
params
:=
makeRequestParamString
(
rule
,
paramValues
)
return
queryType
,
params
...
...
@@ -330,6 +346,9 @@ func MonitorAllWorkspaces(monitoringRequest *client.MonitoringRequestParams) *Fo
}
var
filterMetricsName
[]
string
for
_
,
metricName
:=
range
WorkspaceMetricsNames
{
if
metricName
==
MetricNameWorkspaceAllProjectCount
{
continue
}
bol
,
err
:=
regexp
.
MatchString
(
metricsFilter
,
metricName
)
if
err
==
nil
&&
bol
{
filterMetricsName
=
append
(
filterMetricsName
,
metricName
)
...
...
@@ -400,7 +419,7 @@ func collectWorkspaceMetric(monitoringRequest *client.MonitoringRequestParams, w
wg
.
Add
(
1
)
go
func
(
metricName
string
)
{
queryType
,
params
:=
AssembleWorkspaceMetricRequestInfo
(
monitoringRequest
,
namespaceArray
,
metricName
)
queryType
,
params
:=
Assemble
Specific
WorkspaceMetricRequestInfo
(
monitoringRequest
,
namespaceArray
,
metricName
)
ch
<-
GetMetric
(
queryType
,
params
,
metricName
)
wg
.
Done
()
...
...
@@ -448,11 +467,6 @@ func MonitorAllMetrics(monitoringRequest *client.MonitoringRequestParams, resour
queryType
,
params
:=
AssembleClusterMetricRequestInfo
(
monitoringRequest
,
metricName
)
clusterMetrics
:=
GetMetric
(
queryType
,
params
,
metricName
)
// for this special case, get namespace history which in a workspace by determining namespace label
if
metricName
==
MetricNameWorkspaceAllProjectCount
{
clusterMetrics
=
MonitorWorkspaceNamespaceHistory
(
clusterMetrics
)
}
ch
<-
clusterMetrics
wg
.
Done
()
...
...
@@ -476,6 +490,8 @@ func MonitorAllMetrics(monitoringRequest *client.MonitoringRequestParams, resour
}
case
MetricLevelWorkspace
:
{
// a specific workspace's metrics
if
monitoringRequest
.
WsName
!=
""
{
namespaceArray
,
err
:=
workspaces
.
WorkspaceNamespaces
(
monitoringRequest
.
WsName
)
if
err
!=
nil
{
glog
.
Errorln
(
err
.
Error
())
...
...
@@ -484,6 +500,10 @@ func MonitorAllMetrics(monitoringRequest *client.MonitoringRequestParams, resour
if
monitoringRequest
.
Tp
==
"rank"
{
for
_
,
metricName
:=
range
NamespaceMetricsNames
{
if
metricName
==
MetricNameWorkspaceAllProjectCount
{
continue
}
bol
,
err
:=
regexp
.
MatchString
(
metricsFilter
,
metricName
)
ns
:=
"^("
+
strings
.
Join
(
namespaceArray
,
"|"
)
+
")$"
monitoringRequest
.
NsFilter
=
ns
...
...
@@ -498,13 +518,56 @@ func MonitorAllMetrics(monitoringRequest *client.MonitoringRequestParams, resour
}
}
else
{
for
_
,
metricName
:=
range
WorkspaceMetricsNames
{
if
metricName
==
MetricNameWorkspaceAllProjectCount
{
continue
}
bol
,
err
:=
regexp
.
MatchString
(
metricsFilter
,
metricName
)
if
err
==
nil
&&
bol
{
wg
.
Add
(
1
)
go
func
(
metricName
string
)
{
queryType
,
params
:=
AssembleSpecificWorkspaceMetricRequestInfo
(
monitoringRequest
,
namespaceArray
,
metricName
)
ch
<-
GetMetric
(
queryType
,
params
,
metricName
)
wg
.
Done
()
}(
metricName
)
}
}
}
}
else
{
// sum all workspaces
_
,
namespaceWorkspaceMap
,
err
:=
workspaces
.
GetAllOrgAndProjList
()
if
err
!=
nil
{
glog
.
Errorln
(
err
.
Error
())
}
nsList
:=
make
([]
string
,
0
)
for
ns
:=
range
namespaceWorkspaceMap
{
if
namespaceWorkspaceMap
[
ns
]
==
""
{
nsList
=
append
(
nsList
,
ns
)
}
}
for
_
,
metricName
:=
range
WorkspaceMetricsNames
{
bol
,
err
:=
regexp
.
MatchString
(
metricsFilter
,
metricName
)
if
err
==
nil
&&
bol
{
wg
.
Add
(
1
)
go
func
(
metricName
string
)
{
queryType
,
params
:=
AssembleWorkspaceMetricRequestInfo
(
monitoringRequest
,
namespaceArray
,
metricName
)
queryType
,
params
:=
AssembleAllWorkspaceMetricRequestInfo
(
monitoringRequest
,
nil
,
metricName
)
if
metricName
==
MetricNameWorkspaceAllProjectCount
{
res
:=
GetMetric
(
queryType
,
params
,
metricName
)
res
=
MonitorWorkspaceNamespaceHistory
(
res
)
ch
<-
res
}
else
{
ch
<-
GetMetric
(
queryType
,
params
,
metricName
)
}
wg
.
Done
()
}(
metricName
)
}
...
...
pkg/models/metrics/metricsrule.go
浏览文件 @
f79ae414
...
...
@@ -57,8 +57,18 @@ func MakeWorkloadRule(wkKind, wkName, namespace string) string {
return
rule
}
func
MakeWorkspacePromQL
(
metricsName
string
,
nsFilter
string
)
string
{
promql
:=
RulePromQLTmplMap
[
metricsName
]
func
MakeAllWorkspacesPromQL
(
metricsName
,
nsFilter
string
)
string
{
var
promql
=
RulePromQLTmplMap
[
metricsName
]
nsFilter
=
"!~
\"
"
+
nsFilter
+
"
\"
"
promql
=
strings
.
Replace
(
promql
,
"$1"
,
nsFilter
,
-
1
)
return
promql
}
func
MakeSpecificWorkspacePromQL
(
metricsName
,
nsFilter
string
)
string
{
var
promql
=
RulePromQLTmplMap
[
metricsName
]
nsFilter
=
"=~
\"
"
+
nsFilter
+
"
\"
"
promql
=
strings
.
Replace
(
promql
,
"$1"
,
nsFilter
,
-
1
)
return
promql
}
...
...
pkg/models/metrics/metricsruleconst.go
浏览文件 @
f79ae414
此差异已折叠。
点击以展开。
pkg/models/metrics/util.go
浏览文件 @
f79ae414
...
...
@@ -23,6 +23,8 @@ import (
"strconv"
"unicode"
"runtime/debug"
"github.com/golang/glog"
)
...
...
@@ -50,6 +52,12 @@ func (wrapper FormatedMetricDataWrapper) Swap(i, j int) {
// sorted metric by ascending or descending order
func
Sort
(
sortMetricName
string
,
sortType
string
,
fmtLevelMetric
*
FormatedLevelMetric
,
resourceType
string
)
(
*
FormatedLevelMetric
,
int
)
{
defer
func
()
{
if
err
:=
recover
();
err
!=
nil
{
glog
.
Errorln
(
err
)
debug
.
PrintStack
()
}
}()
if
sortMetricName
==
""
{
return
fmtLevelMetric
,
-
1
...
...
@@ -75,6 +83,12 @@ func Sort(sortMetricName string, sortType string, fmtLevelMetric *FormatedLevelM
value2
:=
(
*
q
)[
ResultItemValue
]
.
([]
interface
{})
v1
,
_
:=
strconv
.
ParseFloat
(
value1
[
len
(
value1
)
-
1
]
.
(
string
),
64
)
v2
,
_
:=
strconv
.
ParseFloat
(
value2
[
len
(
value2
)
-
1
]
.
(
string
),
64
)
if
v1
==
v2
{
resourceName1
:=
(
*
p
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
resourceType
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
resourceType
]
return
resourceName1
.
(
string
)
<
resourceName2
.
(
string
)
}
return
v1
<
v2
}})
}
else
{
...
...
@@ -84,6 +98,13 @@ func Sort(sortMetricName string, sortType string, fmtLevelMetric *FormatedLevelM
value2
:=
(
*
q
)[
ResultItemValue
]
.
([]
interface
{})
v1
,
_
:=
strconv
.
ParseFloat
(
value1
[
len
(
value1
)
-
1
]
.
(
string
),
64
)
v2
,
_
:=
strconv
.
ParseFloat
(
value2
[
len
(
value2
)
-
1
]
.
(
string
),
64
)
if
v1
==
v2
{
resourceName1
:=
(
*
p
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
resourceType
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
resourceType
]
return
resourceName1
.
(
string
)
>
resourceName2
.
(
string
)
}
return
v1
>
v2
}})
}
...
...
@@ -110,7 +131,13 @@ func Sort(sortMetricName string, sortType string, fmtLevelMetric *FormatedLevelM
}
}
for
resource
,
_
:=
range
currentResourceMap
{
var
keys
[]
string
for
k
:=
range
currentResourceMap
{
keys
=
append
(
keys
,
k
)
}
sort
.
Strings
(
keys
)
for
_
,
resource
:=
range
keys
{
if
_
,
exist
:=
indexMap
[
resource
];
!
exist
{
indexMap
[
resource
]
=
i
i
=
i
+
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录