/
daemonsets.go
107 lines (96 loc) · 3.75 KB
/
daemonsets.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2020 OpenTelemetry Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package collection
import (
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"go.opentelemetry.io/collector/translator/conventions"
appsv1 "k8s.io/api/apps/v1"
metadata "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/experimentalmetricmetadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/k8sclusterreceiver/utils"
)
var daemonSetCurrentScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s.daemonset.current_scheduled_nodes",
Description: "Number of nodes that are running at least 1 daemon pod and are supposed to run the daemon pod",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
var daemonSetDesiredScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s.daemonset.desired_scheduled_nodes",
Description: "Number of nodes that should be running the daemon pod (including nodes currently running the daemon pod)",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
var daemonSetMisScheduledMetric = &metricspb.MetricDescriptor{
Name: "k8s.daemonset.misscheduled_nodes",
Description: "Number of nodes that are running the daemon pod, but are not supposed to run the daemon pod",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
var daemonSetReadyMetric = &metricspb.MetricDescriptor{
Name: "k8s.daemonset.ready_nodes",
Description: "Number of nodes that should be running the daemon pod and have one or more of the daemon pod running and ready",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
}
func getMetricsForDaemonSet(ds *appsv1.DaemonSet) []*resourceMetrics {
metrics := []*metricspb.Metric{
{
MetricDescriptor: daemonSetCurrentScheduledMetric,
Timeseries: []*metricspb.TimeSeries{
utils.GetInt64TimeSeries(int64(ds.Status.CurrentNumberScheduled)),
},
},
{
MetricDescriptor: daemonSetDesiredScheduledMetric,
Timeseries: []*metricspb.TimeSeries{
utils.GetInt64TimeSeries(int64(ds.Status.DesiredNumberScheduled)),
},
},
{
MetricDescriptor: daemonSetMisScheduledMetric,
Timeseries: []*metricspb.TimeSeries{
utils.GetInt64TimeSeries(int64(ds.Status.NumberMisscheduled)),
},
},
{
MetricDescriptor: daemonSetReadyMetric,
Timeseries: []*metricspb.TimeSeries{
utils.GetInt64TimeSeries(int64(ds.Status.NumberReady)),
},
},
}
return []*resourceMetrics{
{
resource: getResourceForDaemonSet(ds),
metrics: metrics,
},
}
}
func getResourceForDaemonSet(ds *appsv1.DaemonSet) *resourcepb.Resource {
return &resourcepb.Resource{
Type: k8sType,
Labels: map[string]string{
conventions.AttributeK8sDaemonSetUID: string(ds.UID),
conventions.AttributeK8sDaemonSet: ds.Name,
conventions.AttributeK8sNamespace: ds.Namespace,
conventions.AttributeK8sCluster: ds.ClusterName,
},
}
}
func getMetadataForDaemonSet(ds *appsv1.DaemonSet) map[metadata.ResourceID]*KubernetesMetadata {
return map[metadata.ResourceID]*KubernetesMetadata{
metadata.ResourceID(ds.UID): getGenericMetadata(&ds.ObjectMeta, k8sKindDaemonSet),
}
}