forked from SumoLogic/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingress.go
60 lines (48 loc) · 1.59 KB
/
ingress.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
package kube_inventory
import (
"context"
"time"
v1beta1EXT "github.com/ericchiang/k8s/apis/extensions/v1beta1"
"github.com/influxdata/telegraf"
)
func collectIngress(ctx context.Context, acc telegraf.Accumulator, ki *KubernetesInventory) {
list, err := ki.client.getIngress(ctx)
if err != nil {
acc.AddError(err)
return
}
for _, i := range list.Items {
if err = ki.gatherIngress(*i, acc); err != nil {
acc.AddError(err)
return
}
}
}
func (ki *KubernetesInventory) gatherIngress(i v1beta1EXT.Ingress, acc telegraf.Accumulator) error {
if i.Metadata.CreationTimestamp.GetSeconds() == 0 && i.Metadata.CreationTimestamp.GetNanos() == 0 {
return nil
}
fields := map[string]interface{}{
"created": time.Unix(i.Metadata.CreationTimestamp.GetSeconds(), int64(i.Metadata.CreationTimestamp.GetNanos())).UnixNano(),
"generation": i.Metadata.GetGeneration(),
}
tags := map[string]string{
"ingress_name": i.Metadata.GetName(),
"namespace": i.Metadata.GetNamespace(),
}
for _, ingress := range i.GetStatus().GetLoadBalancer().GetIngress() {
tags["hostname"] = ingress.GetHostname()
tags["ip"] = ingress.GetIp()
for _, rule := range i.GetSpec().GetRules() {
for _, path := range rule.GetIngressRuleValue().GetHttp().GetPaths() {
fields["backend_service_port"] = path.GetBackend().GetServicePort().GetIntVal()
fields["tls"] = i.GetSpec().GetTls() != nil
tags["backend_service_name"] = path.GetBackend().GetServiceName()
tags["path"] = path.GetPath()
tags["host"] = rule.GetHost()
acc.AddFields(ingressMeasurement, fields, tags)
}
}
}
return nil
}