Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
63
plugins/inputs/kube_inventory/endpoint.go
Normal file
63
plugins/inputs/kube_inventory/endpoint.go
Normal file
|
@ -0,0 +1,63 @@
|
|||
package kube_inventory
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
discoveryv1 "k8s.io/api/discovery/v1"
|
||||
|
||||
"github.com/influxdata/telegraf"
|
||||
)
|
||||
|
||||
func collectEndpoints(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
|
||||
list, err := ki.client.getEndpoints(ctx)
|
||||
if err != nil {
|
||||
acc.AddError(err)
|
||||
return
|
||||
}
|
||||
for _, i := range list.Items {
|
||||
gatherEndpoint(i, acc)
|
||||
}
|
||||
}
|
||||
|
||||
func gatherEndpoint(e discoveryv1.EndpointSlice, acc telegraf.Accumulator) {
|
||||
creationTS := e.GetCreationTimestamp()
|
||||
if creationTS.IsZero() {
|
||||
return
|
||||
}
|
||||
|
||||
fields := map[string]interface{}{
|
||||
"created": e.GetCreationTimestamp().UnixNano(),
|
||||
"generation": e.Generation,
|
||||
}
|
||||
|
||||
tags := map[string]string{
|
||||
"endpoint_name": e.Name,
|
||||
"namespace": e.Namespace,
|
||||
}
|
||||
|
||||
for _, endpoint := range e.Endpoints {
|
||||
fields["ready"] = *endpoint.Conditions.Ready
|
||||
|
||||
if endpoint.Hostname != nil {
|
||||
tags["hostname"] = *endpoint.Hostname
|
||||
}
|
||||
if endpoint.NodeName != nil {
|
||||
tags["node_name"] = *endpoint.NodeName
|
||||
}
|
||||
if endpoint.TargetRef != nil {
|
||||
tags[strings.ToLower(endpoint.TargetRef.Kind)] = endpoint.TargetRef.Name
|
||||
}
|
||||
|
||||
for _, port := range e.Ports {
|
||||
if port.Port != nil {
|
||||
fields["port"] = *port.Port
|
||||
}
|
||||
|
||||
tags["port_name"] = *port.Name
|
||||
tags["port_protocol"] = string(*port.Protocol)
|
||||
|
||||
acc.AddFields(endpointMeasurement, fields, tags)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue