Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
20a4525d
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看板
提交
20a4525d
编写于
4月 28, 2019
作者:
H
huanggze
提交者:
zryfish
4月 28, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor monitoring modules
Signed-off-by:
N
huanggze
<
loganhuang@yunify.com
>
上级
5d8fd5c6
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
432 addition
and
265 deletion
+432
-265
pkg/apiserver/monitoring/monitoring.go
pkg/apiserver/monitoring/monitoring.go
+13
-13
pkg/models/metrics/metrics.go
pkg/models/metrics/metrics.go
+385
-225
pkg/models/metrics/metricsruleconst.go
pkg/models/metrics/metricsruleconst.go
+20
-13
pkg/models/metrics/namespaces.go
pkg/models/metrics/namespaces.go
+4
-4
pkg/models/metrics/util.go
pkg/models/metrics/util.go
+10
-10
未找到文件。
pkg/apiserver/monitoring/monitoring.go
浏览文件 @
20a4525d
...
...
@@ -33,13 +33,13 @@ func MonitorPod(request *restful.Request, response *restful.Response) {
var
res
*
metrics
.
FormatedMetric
if
!
nullRule
{
metricsStr
:=
prometheus
.
SendMonitoringRequest
(
prometheus
.
PrometheusEndpoint
,
queryType
,
params
)
res
=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
"pod_name"
:
""
})
res
=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
metrics
.
MetricLevelPodName
:
""
})
}
response
.
WriteAsJson
(
res
)
}
else
{
// multiple
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelPod
)
rawMetrics
:=
metrics
.
GetPodLevelMetrics
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
)
// paging
...
...
@@ -52,7 +52,7 @@ func MonitorContainer(request *restful.Request, response *restful.Response) {
requestParams
:=
prometheus
.
ParseMonitoringRequestParams
(
request
)
metricName
:=
requestParams
.
MetricsName
if
requestParams
.
MetricsFilter
!=
""
{
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelContainer
)
rawMetrics
:=
metrics
.
GetContainerLevelMetrics
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
)
// paging
...
...
@@ -70,7 +70,7 @@ func MonitorContainer(request *restful.Request, response *restful.Response) {
func
MonitorWorkload
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
requestParams
:=
prometheus
.
ParseMonitoringRequestParams
(
request
)
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelWorkload
)
rawMetrics
:=
metrics
.
GetWorkloadLevelMetrics
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
)
...
...
@@ -89,7 +89,7 @@ func MonitorAllWorkspaces(request *restful.Request, response *restful.Response)
tp
:=
requestParams
.
Tp
if
tp
==
"statistics"
{
// merge multiple metric: all-devops, all-roles, all-projects...this api is designed for admin
res
:=
metrics
.
Monitor
AllWorkspacesStatistics
()
res
:=
metrics
.
Get
AllWorkspacesStatistics
()
response
.
WriteAsJson
(
res
)
}
else
if
tp
==
"rank"
{
...
...
@@ -114,7 +114,7 @@ func MonitorOneWorkspace(request *restful.Request, response *restful.Response) {
tp
:=
requestParams
.
Tp
if
tp
==
"rank"
{
// multiple
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelWorkspace
)
rawMetrics
:=
metrics
.
GetWorkspaceLevelMetrics
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
)
...
...
@@ -130,7 +130,7 @@ func MonitorOneWorkspace(request *restful.Request, response *restful.Response) {
res
:=
metrics
.
MonitorOneWorkspaceStatistics
(
wsName
)
response
.
WriteAsJson
(
res
)
}
else
{
res
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelWorkspace
)
res
:=
metrics
.
GetWorkspaceLevelMetrics
(
requestParams
)
response
.
WriteAsJson
(
res
)
}
}
...
...
@@ -138,7 +138,7 @@ func MonitorOneWorkspace(request *restful.Request, response *restful.Response) {
func
MonitorNamespace
(
request
*
restful
.
Request
,
response
*
restful
.
Response
)
{
requestParams
:=
prometheus
.
ParseMonitoringRequestParams
(
request
)
// multiple
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelNamespace
)
rawMetrics
:=
metrics
.
GetNamespaceLevelMetrics
(
requestParams
)
// sorting
sortedMetrics
,
maxMetricCount
:=
metrics
.
Sort
(
requestParams
.
SortMetricName
,
requestParams
.
SortType
,
rawMetrics
)
...
...
@@ -155,12 +155,12 @@ func MonitorCluster(request *restful.Request, response *restful.Response) {
// single
queryType
,
params
:=
metrics
.
AssembleClusterMetricRequestInfo
(
requestParams
,
metricName
)
metricsStr
:=
prometheus
.
SendMonitoringRequest
(
prometheus
.
PrometheusEndpoint
,
queryType
,
params
)
res
:=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
"cluster"
:
"local"
})
res
:=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
metrics
.
MetricLevelCluster
:
"local"
})
response
.
WriteAsJson
(
res
)
}
else
{
// multiple
res
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelCluster
)
res
:=
metrics
.
GetClusterLevelMetrics
(
requestParams
)
response
.
WriteAsJson
(
res
)
}
}
...
...
@@ -173,7 +173,7 @@ func MonitorNode(request *restful.Request, response *restful.Response) {
// single
queryType
,
params
:=
metrics
.
AssembleNodeMetricRequestInfo
(
requestParams
,
metricName
)
metricsStr
:=
prometheus
.
SendMonitoringRequest
(
prometheus
.
PrometheusEndpoint
,
queryType
,
params
)
res
:=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
"node"
:
""
})
res
:=
metrics
.
ReformatJson
(
metricsStr
,
metricName
,
map
[
string
]
string
{
metrics
.
MetricLevelNode
:
""
})
// The raw node-exporter result doesn't include ip address information
// Thereby, append node ip address to .data.result[].metric
...
...
@@ -183,7 +183,7 @@ func MonitorNode(request *restful.Request, response *restful.Response) {
response
.
WriteAsJson
(
res
)
}
else
{
// multiple
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelNode
)
rawMetrics
:=
metrics
.
GetNodeLevelMetrics
(
requestParams
)
nodeAddress
:=
metrics
.
GetNodeAddressInfo
()
for
i
:=
0
;
i
<
len
(
rawMetrics
.
Results
);
i
++
{
...
...
@@ -206,7 +206,7 @@ func MonitorComponent(request *restful.Request, response *restful.Response) {
requestParams
.
MetricsFilter
=
requestParams
.
ComponentName
+
"_.*"
}
rawMetrics
:=
metrics
.
MonitorAllMetrics
(
requestParams
,
metrics
.
MetricLevelComponent
)
rawMetrics
:=
metrics
.
GetComponentLevelMetrics
(
requestParams
)
response
.
WriteAsJson
(
rawMetrics
)
}
pkg/models/metrics/metrics.go
浏览文件 @
20a4525d
此差异已折叠。
点击以展开。
pkg/models/metrics/metricsruleconst.go
浏览文件 @
20a4525d
...
...
@@ -14,19 +14,20 @@ limitations under the License.
package
metrics
const
(
ResultTypeVector
=
"vector"
ResultTypeMatrix
=
"matrix"
MetricStatus
=
"status"
MetricStatusError
=
"error"
MetricStatusSuccess
=
"success"
ResultItemMetric
=
"metric"
ResultItemMetricResource
=
"resource"
ResultItemMetricNodeIp
=
"node_ip"
ResultItemMetricNodeName
=
"node_name"
ResultItemValue
=
"value"
ResultItemValues
=
"values"
ResultSortTypeDesc
=
"desc"
ResultSortTypeAsc
=
"asc"
ResultTypeVector
=
"vector"
ResultTypeMatrix
=
"matrix"
MetricStatus
=
"status"
MetricStatusError
=
"error"
MetricStatusSuccess
=
"success"
ResultItemMetric
=
"metric"
ResultItemMetricResource
=
"resource"
ResultItemMetricResourceName
=
"resource_name"
ResultItemMetricNodeIp
=
"node_ip"
ResultItemMetricNodeName
=
"node_name"
ResultItemValue
=
"value"
ResultItemValues
=
"values"
ResultSortTypeDesc
=
"desc"
ResultSortTypeAsc
=
"asc"
)
const
(
...
...
@@ -90,6 +91,12 @@ const (
WorkspaceJoinedKey
=
"label_kubesphere_io_workspace"
)
// The metrics need to include extra info out of prometheus
// eg. add node name info to the etcd_server_list metric
const
(
EtcdServerList
=
"etcd_server_list"
)
type
MetricMap
map
[
string
]
string
var
ClusterMetricsNames
=
[]
string
{
...
...
pkg/models/metrics/namespaces.go
浏览文件 @
20a4525d
...
...
@@ -41,14 +41,14 @@ func GetNamespacesWithMetrics(namespaces []*v1.Namespace) []*v1.Namespace {
MetricsFilter
:
"namespace_cpu_usage|namespace_memory_usage_wo_cache|namespace_pod_count"
,
}
rawMetrics
:=
MonitorAllMetrics
(
&
params
,
MetricLevelNamespace
)
rawMetrics
:=
GetNamespaceLevelMetrics
(
&
params
)
for
_
,
result
:=
range
rawMetrics
.
Results
{
for
_
,
data
:=
range
result
.
Data
.
Result
{
metricDescMap
,
ok
:=
data
[
"metric"
]
.
(
map
[
string
]
interface
{})
metricDescMap
,
ok
:=
data
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})
if
ok
{
if
ns
,
exist
:=
metricDescMap
[
"resource_name"
];
exist
{
timeAndValue
,
ok
:=
data
[
"value"
]
.
([]
interface
{})
if
ns
,
exist
:=
metricDescMap
[
ResultItemMetricResourceName
];
exist
{
timeAndValue
,
ok
:=
data
[
ResultItemValue
]
.
([]
interface
{})
if
ok
&&
len
(
timeAndValue
)
==
2
{
for
i
:=
0
;
i
<
len
(
namespaces
);
i
++
{
if
namespaces
[
i
]
.
Name
==
ns
{
...
...
pkg/models/metrics/util.go
浏览文件 @
20a4525d
...
...
@@ -89,8 +89,8 @@ func Sort(sortMetricName string, sortType string, rawMetrics *FormatedLevelMetri
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
{})[
"resource_name"
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
resourceName1
:=
(
*
p
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
return
resourceName1
.
(
string
)
<
resourceName2
.
(
string
)
}
...
...
@@ -105,8 +105,8 @@ func Sort(sortMetricName string, sortType string, rawMetrics *FormatedLevelMetri
v2
,
_
:=
strconv
.
ParseFloat
(
value2
[
len
(
value2
)
-
1
]
.
(
string
),
64
)
if
v1
==
v2
{
resourceName1
:=
(
*
p
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
resourceName1
:=
(
*
p
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
resourceName2
:=
(
*
q
)[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
return
resourceName1
.
(
string
)
>
resourceName2
.
(
string
)
}
...
...
@@ -116,8 +116,8 @@ func Sort(sortMetricName string, sortType string, rawMetrics *FormatedLevelMetri
for
_
,
r
:=
range
metricItem
.
Data
.
Result
{
// record the ordering of resource_name to indexMap
// example: {"metric":{
"resource_name"
: "Deployment:xxx"},"value":[1541142931.731,"3"]}
resourceName
,
exist
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
// example: {"metric":{
ResultItemMetricResourceName
: "Deployment:xxx"},"value":[1541142931.731,"3"]}
resourceName
,
exist
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
if
exist
{
if
_
,
exist
:=
indexMap
[
resourceName
.
(
string
)];
!
exist
{
indexMap
[
resourceName
.
(
string
)]
=
i
...
...
@@ -129,7 +129,7 @@ func Sort(sortMetricName string, sortType string, rawMetrics *FormatedLevelMetri
// iterator all metric to find max metricItems length
for
_
,
r
:=
range
metricItem
.
Data
.
Result
{
k
,
ok
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
k
,
ok
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
if
ok
{
currentResourceMap
[
k
.
(
string
)]
=
1
}
...
...
@@ -158,7 +158,7 @@ func Sort(sortMetricName string, sortType string, rawMetrics *FormatedLevelMetri
sortedMetric
:=
make
([]
map
[
string
]
interface
{},
len
(
indexMap
))
for
j
:=
0
;
j
<
len
(
re
.
Data
.
Result
);
j
++
{
r
:=
re
.
Data
.
Result
[
j
]
k
,
exist
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
"resource_name"
]
k
,
exist
:=
r
[
ResultItemMetric
]
.
(
map
[
string
]
interface
{})[
ResultItemMetricResourceName
]
if
exist
{
index
,
exist
:=
indexMap
[
k
.
(
string
)]
if
exist
{
...
...
@@ -290,9 +290,9 @@ func ReformatJson(metric string, metricsName string, needAddParams map[string]st
for
n
:=
range
needAddParams
{
if
v
,
ok
:=
metricMap
[
n
];
ok
{
delete
(
metricMap
,
n
)
metricMap
[
"resource_name"
]
=
v
metricMap
[
ResultItemMetricResourceName
]
=
v
}
else
{
metricMap
[
"resource_name"
]
=
needAddParams
[
n
]
metricMap
[
ResultItemMetricResourceName
]
=
needAddParams
[
n
]
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录