/
summary.go
53 lines (44 loc) · 1.17 KB
/
summary.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cluster
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
import (
"context"
"strconv"
)
const (
masterRoleLabel = "node-role.kubernetes.io/master"
workerRoleLabel = "node-role.kubernetes.io/worker"
)
// emitSummary emits joined metric to be able to report better on all clusters
// state in single dashboard
func (mon *Monitor) emitSummary(ctx context.Context) error {
if !mon.hourlyRun {
return nil
}
cv, err := mon.getClusterVersion(ctx)
if err != nil {
return err
}
ns, err := mon.listNodes(ctx)
if err != nil {
return err
}
var masterCount, workerCount int
for _, node := range ns.Items {
if _, ok := node.Labels[masterRoleLabel]; ok {
masterCount++
}
if _, ok := node.Labels[workerRoleLabel]; ok {
workerCount++
}
}
mon.emitGauge("cluster.summary", 1, map[string]string{
"actualVersion": actualVersion(cv),
"desiredVersion": desiredVersion(cv),
"masterCount": strconv.Itoa(masterCount),
"workerCount": strconv.Itoa(workerCount),
"provisioningState": mon.oc.Properties.ProvisioningState.String(),
"createdAt": mon.oc.Properties.CreatedAt.String(),
})
return nil
}