Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(monitor): support to monitor vm and expose influxdb svc as nodeport type #2116

Merged
merged 7 commits into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(monitor): support configure vm alert rule
1. fix alert rule expression for vm
2. add vm name in alert message
3. round values in prometheus alert annotation to two decimals

Signed-off-by: willzgli <[email protected]>
  • Loading branch information
willzgli committed Nov 11, 2022
commit c66149d280e1014f26c07983cad620aa6a1a7358
20 changes: 20 additions & 0 deletions pkg/monitor/services/rest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
alarmPolicyTypeCluster = "cluster"
alarmPolicyTypeNode = "node"
alarmPolicyTypePod = "pod"
alarmPolicyTypeVM = "virtualMachine"
alarmPolicyTypeKey = "alarmPolicyType"
alarmObjectsTypeKey = "alarmObjectsType"
filterNamespaceKey = "namespace"
Expand Down Expand Up @@ -350,6 +351,21 @@ func (r *AlarmMetric) GetExpr(alarmPolicy *AlarmPolicy) string {
} else {
metric = r.MetricName
}
case alarmPolicyTypeVM:
filter := MetricFilter{}
if alarmPolicy.AlarmPolicySettings.AlarmObjects != "" {
alarmObjects := strings.Split(alarmPolicy.AlarmPolicySettings.AlarmObjects, ",")
filter.WorkloadName = strings.Join(alarmObjects, "|")
}
if alarmPolicy.Namespace != "" {
filter.Namespace = alarmPolicy.Namespace
}
if filter.WorkloadName != "" || filter.Namespace != "" {
metric = fmt.Sprintf("%s{%s}", r.MetricName, filter.ToStr())
metric = strings.ReplaceAll(metric, "workload_name", "name") //In vm metrics label, use name to replace workload_name
} else {
metric = r.MetricName
}
}
var value string
b, err := parseBool(r.Evaluator.Value)
Expand Down Expand Up @@ -407,6 +423,10 @@ func (r *AlarmMetric) GetAnnotations(alarmPolicy *AlarmPolicy) map[string]string
annotations[alarmObjectsTypeKey] = alarmPolicySettings.AlarmObjectsType
annotations[measurementKey] = r.Measurement
annotations[valueKey] = valueStr

if r.Unit == "%" { // if value is a percentage type, format the value for readable
annotations[valueKey] = "{{ $value | printf \"%.2f\" }}"
}
annotations[metricDisplayNameKey] = r.MetricDisplayName

return annotations
Expand Down
7 changes: 7 additions & 0 deletions pkg/notify/apiserver/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const (
workloadKindKey = "workloadKind"
namespaceKey = "namespace"
workloadNameKey = "workloadName"
virtualMachineKey = "virtualMachine"
podNameKey = "podName"
nodeNameKey = "nodeName"
nodeRoleKey = "nodeRole"
Expand Down Expand Up @@ -263,6 +264,11 @@ func getVariables(alert Alert) map[string]string {
summary = fmt.Sprintf("%s\n工作负载名称:%s", summary, workloadNameValue)
}

virtualMachineName, ok := labels["name"]
if ok {
summary = fmt.Sprintf("%s\n虚拟机名称:%s", summary, virtualMachineName)
}

namespaceValue, ok := labels["namespace"]
if ok {
summary = fmt.Sprintf("%s\n命名空间:%s", summary, namespaceValue)
Expand Down Expand Up @@ -301,6 +307,7 @@ func getVariables(alert Alert) map[string]string {
variables[evaluateValueKey] = evaluateValue
variables[metricDisplayNameKey] = metricDisplayNameValue
variables[summaryKey] = summary
variables[virtualMachineKey] = virtualMachineName

return variables
}
Expand Down