| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package snmp |
| 4 | |
| 5 | import "github.com/netdata/netdata/go/plugins/plugin/go.d/collector/snmp/ddsnmp/ddprofiledefinition" |
| 6 | |
| 7 | type bgpScope string |
| 8 | |
| 9 | const ( |
| 10 | bgpScopePeers bgpScope = "peers" |
| 11 | bgpScopePeerFamilies bgpScope = "peer_families" |
| 12 | bgpScopeDevices bgpScope = "devices" |
| 13 | ) |
| 14 | |
| 15 | type bgpMetricSpecDef struct { |
| 16 | description string |
| 17 | family string |
| 18 | unit string |
| 19 | chartType string |
| 20 | metricType ddprofiledefinition.ProfileMetricType |
| 21 | isTable bool |
| 22 | } |
| 23 | |
| 24 | func buildBGPMetricName(scope bgpScope, leaf string) string { |
| 25 | switch scope { |
| 26 | case bgpScopePeerFamilies: |
| 27 | return "bgp.peer_families." + leaf |
| 28 | case bgpScopeDevices: |
| 29 | return "bgp.devices." + leaf |
| 30 | default: |
| 31 | return "bgp.peers." + leaf |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | func bgpMetricSpec(name string) (bgpMetricSpecDef, bool) { |
| 36 | switch name { |
| 37 | case "bgp.devices.peer_counts": |
| 38 | return bgpMetricSpecDef{ |
| 39 | description: "BGP device peer counts", |
| 40 | family: "BGP/Devices", |
| 41 | unit: "peers", |
| 42 | metricType: ddprofiledefinition.ProfileMetricTypeGauge, |
| 43 | }, true |
| 44 | case "bgp.devices.peer_states": |
| 45 | return bgpMetricSpecDef{ |
| 46 | description: "BGP device peer states", |
| 47 | family: "BGP/Devices", |
| 48 | unit: "peers", |
| 49 | metricType: ddprofiledefinition.ProfileMetricTypeGauge, |
| 50 | }, true |
| 51 | case "bgp.peers.availability": |
| 52 | return tableSpec("BGP peer availability", "BGP/Peers", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 53 | case "bgp.peers.connection_state": |
| 54 | return tableSpec("BGP peer connection state", "BGP/Peers", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 55 | case "bgp.peers.previous_connection_state": |
| 56 | return tableSpec("BGP peer previous connection state", "BGP/Peers", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 57 | case "bgp.peers.established_uptime": |
| 58 | return tableSpec("BGP peer established uptime", "BGP/Peers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 59 | case "bgp.peers.update_traffic": |
| 60 | return tableSpec("BGP peer update traffic", "BGP/Peers/Traffic", "updates/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 61 | case "bgp.peers.message_traffic": |
| 62 | return tableSpec("BGP peer message traffic", "BGP/Peers/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 63 | case "bgp.peers.notification_traffic": |
| 64 | return tableSpec("BGP peer notification traffic", "BGP/Peers/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 65 | case "bgp.peers.route_refresh_traffic": |
| 66 | return tableSpec("BGP peer route refresh traffic", "BGP/Peers/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 67 | case "bgp.peers.open_traffic": |
| 68 | return tableSpec("BGP peer open traffic", "BGP/Peers/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 69 | case "bgp.peers.keepalive_traffic": |
| 70 | return tableSpec("BGP peer keepalive traffic", "BGP/Peers/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 71 | case "bgp.peers.established_transitions": |
| 72 | return tableSpec("BGP peer established transitions", "BGP/Peers/Events", "transitions/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 73 | case "bgp.peers.down_transitions": |
| 74 | return tableSpec("BGP peer down transitions", "BGP/Peers/Events", "transitions", ddprofiledefinition.ProfileMetricTypeMonotonicCount), true |
| 75 | case "bgp.peers.up_transitions": |
| 76 | return tableSpec("BGP peer up transitions", "BGP/Peers/Events", "transitions", ddprofiledefinition.ProfileMetricTypeMonotonicCount), true |
| 77 | case "bgp.peers.flaps": |
| 78 | return tableSpec("BGP peer flaps", "BGP/Peers/Events", "flaps", ddprofiledefinition.ProfileMetricTypeMonotonicCount), true |
| 79 | case "bgp.peers.last_received_update_age": |
| 80 | return tableSpec("BGP peer time since last update", "BGP/Peers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 81 | case "bgp.peers.last_error": |
| 82 | return tableSpec("BGP peer last error", "BGP/Peers/Errors", "code", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 83 | case "bgp.peers.last_down_reason": |
| 84 | return tableSpec("BGP peer last down reason", "BGP/Peers/Errors", "reason", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 85 | case "bgp.peers.last_received_notification_reason": |
| 86 | return tableSpec("BGP peer last received notification reason", "BGP/Peers/Errors", "reason", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 87 | case "bgp.peers.last_sent_notification_reason": |
| 88 | return tableSpec("BGP peer last sent notification reason", "BGP/Peers/Errors", "reason", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 89 | case "bgp.peers.negotiated_timers": |
| 90 | return tableSpec("BGP peer negotiated timers", "BGP/Peers/Timers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 91 | case "bgp.peers.configured_timers": |
| 92 | return tableSpec("BGP peer configured timers", "BGP/Peers/Timers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 93 | case "bgp.peer_families.availability": |
| 94 | return tableSpec("BGP peer-family availability", "BGP/Peer Families", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 95 | case "bgp.peer_families.connection_state": |
| 96 | return tableSpec("BGP peer-family connection state", "BGP/Peer Families", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 97 | case "bgp.peer_families.established_uptime": |
| 98 | return tableSpec("BGP peer-family established uptime", "BGP/Peer Families", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 99 | case "bgp.peer_families.update_traffic": |
| 100 | return tableSpec("BGP peer-family update traffic", "BGP/Peer Families/Traffic", "updates/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 101 | case "bgp.peer_families.message_traffic": |
| 102 | return tableSpec("BGP peer-family message traffic", "BGP/Peer Families/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 103 | case "bgp.peer_families.notification_traffic": |
| 104 | return tableSpec("BGP peer-family notification traffic", "BGP/Peer Families/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 105 | case "bgp.peer_families.route_refresh_traffic": |
| 106 | return tableSpec("BGP peer-family route refresh traffic", "BGP/Peer Families/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 107 | case "bgp.peer_families.open_traffic": |
| 108 | return tableSpec("BGP peer-family open traffic", "BGP/Peer Families/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 109 | case "bgp.peer_families.keepalive_traffic": |
| 110 | return tableSpec("BGP peer-family keepalive traffic", "BGP/Peer Families/Traffic", "messages/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 111 | case "bgp.peer_families.established_transitions": |
| 112 | return tableSpec("BGP peer-family established transitions", "BGP/Peer Families/Events", "transitions/s", ddprofiledefinition.ProfileMetricTypeRate), true |
| 113 | case "bgp.peer_families.down_transitions": |
| 114 | return tableSpec("BGP peer-family down transitions", "BGP/Peer Families/Events", "transitions", ddprofiledefinition.ProfileMetricTypeMonotonicCount), true |
| 115 | case "bgp.peer_families.last_received_update_age": |
| 116 | return tableSpec("BGP peer-family time since last update", "BGP/Peer Families", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 117 | case "bgp.peer_families.last_error": |
| 118 | return tableSpec("BGP peer-family last error", "BGP/Peer Families/Errors", "code", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 119 | case "bgp.peer_families.graceful_restart_state": |
| 120 | return tableSpec("BGP peer-family graceful restart state", "BGP/Peer Families", "status", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 121 | case "bgp.peer_families.unavailability_reason": |
| 122 | return tableSpec("BGP peer-family unavailability reason", "BGP/Peer Families/Errors", "reason", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 123 | case "bgp.peer_families.negotiated_timers": |
| 124 | return tableSpec("BGP peer-family negotiated timers", "BGP/Peer Families/Timers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 125 | case "bgp.peer_families.configured_timers": |
| 126 | return tableSpec("BGP peer-family configured timers", "BGP/Peer Families/Timers", "seconds", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 127 | case "bgp.peer_families.route_counts.current": |
| 128 | return tableSpec("BGP peer-family current route counts", "BGP/Peer Families/Routes", "prefixes", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 129 | case "bgp.peer_families.route_totals": |
| 130 | return tableSpec("BGP peer-family route totals", "BGP/Peer Families/Routes", "prefixes", ddprofiledefinition.ProfileMetricTypeMonotonicCount), true |
| 131 | case "bgp.peer_families.route_limits": |
| 132 | return tableSpec("BGP peer-family route limits", "BGP/Peer Families/Routes", "prefixes", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 133 | case "bgp.peer_families.route_limit_thresholds": |
| 134 | return tableSpec("BGP peer-family route limit thresholds", "BGP/Peer Families/Routes", "%", ddprofiledefinition.ProfileMetricTypeGauge), true |
| 135 | default: |
| 136 | return bgpMetricSpecDef{}, false |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | func tableSpec(description, family, unit string, metricType ddprofiledefinition.ProfileMetricType) bgpMetricSpecDef { |
| 141 | return bgpMetricSpecDef{ |
| 142 | description: description, |
| 143 | family: family, |
| 144 | unit: unit, |
| 145 | metricType: metricType, |
| 146 | isTable: true, |
| 147 | } |
| 148 | } |