| 1 | package metricsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/ |
| 2 | |
| 3 | import ( |
| 4 | "regexpscip-go gomod github.com/golang/go/src go1.25 regexp/" |
| 5 | "stringsscip-go gomod github.com/golang/go/src go1.25 strings/" |
| 6 | |
| 7 | "github.com/czerwonk/bird_exporter/protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/" |
| 8 | ) |
| 9 | |
| 10 | // DefaultLabelStrategy defines the labels to add to an metric and its data retrieval method |
| 11 | type DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy# struct { |
| 12 | descriptionLabelsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabels. bool |
| 13 | descriptionLabelsRegexscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabelsRegex. *regexpscip-go gomod github.com/golang/go/src go1.25 regexp/.Regexpscip-go gomod github.com/golang/go/src go1.25 regexp/Regexp# |
| 14 | } |
| 15 | |
| 16 | func NewDefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/NewDefaultLabelStrategy().(descriptionLabels bool, descriptionLabelsRegex string) *DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy# { |
| 17 | return &DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#{ |
| 18 | descriptionLabelsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabels.: descriptionLabels, |
| 19 | descriptionLabelsRegexscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabelsRegex.: regexpscip-go gomod github.com/golang/go/src go1.25 regexp/.MustCompilescip-go gomod github.com/golang/go/src go1.25 regexp/MustCompile().(descriptionLabelsRegex), |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | // LabelNames returns the list of label names |
| 24 | func (d *DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#) LabelNamesscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#LabelNames().(p *protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#) []string { |
| 25 | res := []string{"name", "proto", "ip_version", "import_filter", "export_filter"} |
| 26 | if d.descriptionLabelsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabels. && p.Descriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Description. != "" { |
| 27 | res = append(res, labelKeysFromDescriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/labelKeysFromDescription().(p.Descriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Description., d)...) |
| 28 | } |
| 29 | |
| 30 | return res |
| 31 | } |
| 32 | |
| 33 | // LabelValues returns the values for a protocol |
| 34 | func (d *DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#) LabelValuesscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#LabelValues().(p *protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#) []string { |
| 35 | res := []string{p.Namescip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Name., protoStringscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/protoString().(p), p.IPVersionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#IPVersion., p.ImportFilterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#ImportFilter., p.ExportFilterscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#ExportFilter.} |
| 36 | if d.descriptionLabelsscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabels. && p.Descriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Description. != "" { |
| 37 | res = append(res, labelValuesFromDescriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/labelValuesFromDescription().(p.Descriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Description., d)...) |
| 38 | } |
| 39 | |
| 40 | return res |
| 41 | } |
| 42 | |
| 43 | func labelKeysFromDescriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/labelKeysFromDescription().(desc string, d *DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#) []string { |
| 44 | res := []string{} |
| 45 | |
| 46 | matches := d.descriptionLabelsRegexscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabelsRegex..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.25 regexp/Regexp#FindAllStringSubmatch().(desc, -1) |
| 47 | for _, submatch := range matches { |
| 48 | res = append(res, stringsscip-go gomod github.com/golang/go/src go1.25 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25 strings/TrimSpace().(submatch[1])) |
| 49 | } |
| 50 | |
| 51 | return res |
| 52 | } |
| 53 | |
| 54 | func labelValuesFromDescriptionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/labelValuesFromDescription().(desc string, d *DefaultLabelStrategyscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#) []string { |
| 55 | res := []string{} |
| 56 | |
| 57 | matches := d.descriptionLabelsRegexscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/DefaultLabelStrategy#descriptionLabelsRegex..FindAllStringSubmatchscip-go gomod github.com/golang/go/src go1.25 regexp/Regexp#FindAllStringSubmatch().(desc, -1) |
| 58 | for _, submatch := range matches { |
| 59 | res = append(res, stringsscip-go gomod github.com/golang/go/src go1.25 strings/.TrimSpacescip-go gomod github.com/golang/go/src go1.25 strings/TrimSpace().(submatch[2])) |
| 60 | } |
| 61 | |
| 62 | return res |
| 63 | } |
| 64 | |
| 65 | func protoStringscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/metrics`/protoString().(p *protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#) string { |
| 66 | switch p.Protoscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#Proto. { |
| 67 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.BGPscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BGP.: |
| 68 | return "BGP" |
| 69 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.OSPFscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/OSPF.: |
| 70 | if p.IPVersionscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Protocol#IPVersion. == "4" { |
| 71 | return "OSPF" |
| 72 | } |
| 73 | return "OSPFv3" |
| 74 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Staticscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Static.: |
| 75 | return "Static" |
| 76 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Kernelscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Kernel.: |
| 77 | return "Kernel" |
| 78 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Directscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Direct.: |
| 79 | return "Direct" |
| 80 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.Babelscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/Babel.: |
| 81 | return "Babel" |
| 82 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.RPKIscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/RPKI.: |
| 83 | return "RPKI" |
| 84 | case protocolscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/.BFDscip-go gomod github.com/czerwonk/bird_exporter . `github.com/czerwonk/bird_exporter/protocol`/BFD.: |
| 85 | return "BFD" |
| 86 | } |
| 87 | |
| 88 | return "" |
| 89 | } |