master
go 166 lines 7.3 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 package panos
4
5 import "github.com/netdata/netdata/go/plugins/pkg/metrix"
6
7 type collectorMetrics struct {
8 system systemMetrics
9 ha haMetrics
10 env environmentMetricInstruments
11 lic licenseMetricInstruments
12 ipsec ipsecMetricInstruments
13 bgp bgpMetricInstruments
14 }
15
16 type systemMetrics struct {
17 uptime metrix.SnapshotGaugeVec
18 certStatus metrix.SnapshotStateSetVec
19 operationalMode metrix.SnapshotStateSetVec
20 }
21
22 type haMetrics struct {
23 status metrix.StateSetInstrument
24 localState metrix.StateSetInstrument
25 peerState metrix.StateSetInstrument
26 peerConnectionStatus metrix.StateSetInstrument
27 stateSync metrix.StateSetInstrument
28 linkStatus metrix.SnapshotStateSetVec
29 }
30
31 type environmentMetricInstruments struct {
32 temperature metrix.SnapshotGaugeVec
33 fanSpeed metrix.SnapshotGaugeVec
34 voltage metrix.SnapshotGaugeVec
35 sensorAlarm metrix.SnapshotStateSetVec
36 powerSupplyPresence metrix.SnapshotStateSetVec
37 powerSupplyAlarm metrix.SnapshotStateSetVec
38 }
39
40 type licenseMetricInstruments struct {
41 countTotal metrix.SnapshotGauge
42 countExpired metrix.SnapshotGauge
43 status metrix.SnapshotStateSetVec
44 timeUntilExpiration metrix.SnapshotGaugeVec
45 }
46
47 type ipsecMetricInstruments struct {
48 tunnelsActive metrix.SnapshotGauge
49 saLifetime metrix.SnapshotGaugeVec
50 }
51
52 type bgpMetricInstruments struct {
53 peerState metrix.SnapshotStateSetVec
54 peerUptime metrix.SnapshotGaugeVec
55 peerMessagesIn metrix.SnapshotCounterVec
56 peerMessagesOut metrix.SnapshotCounterVec
57 peerUpdatesIn metrix.SnapshotCounterVec
58 peerUpdatesOut metrix.SnapshotCounterVec
59 peerFlaps metrix.SnapshotCounterVec
60 peerEstablishedTransitions metrix.SnapshotCounterVec
61
62 peerPrefixesReceivedTotal metrix.SnapshotGaugeVec
63 peerPrefixesReceivedAccepted metrix.SnapshotGaugeVec
64 peerPrefixesReceivedRejected metrix.SnapshotGaugeVec
65 peerPrefixesAdvertised metrix.SnapshotGaugeVec
66
67 vrPeersByState map[string]metrix.SnapshotGaugeVec
68 vrPeersConfigured metrix.SnapshotGaugeVec
69 vrPeersEstablished metrix.SnapshotGaugeVec
70 }
71
72 var bgpStates = []string{"idle", "connect", "active", "opensent", "openconfirm", "established", "unknown"}
73 var certStatusStates = []string{"valid", "invalid"}
74 var haStates = []string{"active", "passive", "non_functional", "suspended", "unknown"}
75 var haStatusStates = []string{"enabled", "disabled"}
76 var licenseStatusStates = []string{"valid", "expired"}
77 var operationalModeStates = []string{"normal", "other"}
78 var upDownStates = []string{"up", "down", "unknown"}
79 var haSyncStates = []string{"synchronized", "not_synchronized", "unknown"}
80 var alarmStates = []string{"clear", "alarm"}
81 var presenceStates = []string{"present", "absent"}
82
83 func newCollectorMetrics(store metrix.CollectorStore) *collectorMetrics {
84 meter := store.Write().SnapshotMeter("")
85 system := meter.Vec("hostname", "model", "serial", "sw_version")
86 haLink := meter.Vec("link")
87 environment := meter.Vec("sensor_type", "slot", "sensor")
88 licenses := meter.Vec("feature", "description")
89 ipsecTunnels := meter.Vec("tunnel", "gateway", "remote", "tunnel_id", "protocol", "encryption")
90 bgpPeer := meter.Vec("vr", "peer_address", "local_address", "remote_as", "peer_group")
91 bgpPrefix := meter.Vec("vr", "peer_address", "local_address", "remote_as", "peer_group", "afi", "safi")
92 bgpVR := meter.Vec("vr")
93
94 return &collectorMetrics{
95 system: systemMetrics{
96 uptime: system.Gauge("system_uptime"),
97 certStatus: newStateSetVec(system, "system_device_certificate_status", certStatusStates),
98 operationalMode: newStateSetVec(system, "system_operational_mode", operationalModeStates),
99 },
100 ha: haMetrics{
101 status: newStateSet(meter, "ha_status", haStatusStates),
102 localState: newStateSet(meter, "ha_local_state", haStates),
103 peerState: newStateSet(meter, "ha_peer_state", haStates),
104 peerConnectionStatus: newStateSet(meter, "ha_peer_connection_status", upDownStates),
105 stateSync: newStateSet(meter, "ha_state_sync_status", haSyncStates),
106 linkStatus: newStateSetVec(haLink, "ha_link_status", upDownStates),
107 },
108 env: environmentMetricInstruments{
109 temperature: environment.Gauge("environment_temperature"),
110 fanSpeed: environment.Gauge("environment_fan_speed"),
111 voltage: environment.Gauge("environment_voltage"),
112 sensorAlarm: newStateSetVec(environment, "environment_sensor_alarm_status", alarmStates),
113 powerSupplyPresence: newStateSetVec(environment, "environment_power_supply_presence_status", presenceStates),
114 powerSupplyAlarm: newStateSetVec(environment, "environment_power_supply_alarm_status", alarmStates),
115 },
116 lic: licenseMetricInstruments{
117 countTotal: meter.Gauge("license_count_total"),
118 countExpired: meter.Gauge("license_count_expired"),
119 status: newStateSetVec(licenses, "license_status", licenseStatusStates),
120 timeUntilExpiration: licenses.Gauge("license_time_until_expiration"),
121 },
122 ipsec: ipsecMetricInstruments{
123 tunnelsActive: meter.Gauge("ipsec_tunnels_active"),
124 saLifetime: ipsecTunnels.Gauge("ipsec_tunnel_sa_lifetime"),
125 },
126 bgp: bgpMetricInstruments{
127 peerState: newStateSetVec(bgpPeer, "bgp_peer_state", bgpStates),
128 peerUptime: bgpPeer.Gauge("bgp_peer_uptime"),
129 peerMessagesIn: bgpPeer.Counter("bgp_peer_messages_in"),
130 peerMessagesOut: bgpPeer.Counter("bgp_peer_messages_out"),
131 peerUpdatesIn: bgpPeer.Counter("bgp_peer_updates_in"),
132 peerUpdatesOut: bgpPeer.Counter("bgp_peer_updates_out"),
133 peerFlaps: bgpPeer.Counter("bgp_peer_flaps"),
134 peerEstablishedTransitions: bgpPeer.Counter("bgp_peer_established_transitions"),
135
136 peerPrefixesReceivedTotal: bgpPrefix.Gauge("bgp_peer_prefixes_received_total"),
137 peerPrefixesReceivedAccepted: bgpPrefix.Gauge("bgp_peer_prefixes_received_accepted"),
138 peerPrefixesReceivedRejected: bgpPrefix.Gauge("bgp_peer_prefixes_received_rejected"),
139 peerPrefixesAdvertised: bgpPrefix.Gauge("bgp_peer_prefixes_advertised"),
140
141 vrPeersByState: newBGPStateGauges(bgpVR, "bgp_vr_peers_by_state"),
142 vrPeersConfigured: bgpVR.Gauge("bgp_vr_peers_total_configured"),
143 vrPeersEstablished: bgpVR.Gauge("bgp_vr_peers_total_established"),
144 },
145 }
146 }
147
148 func newStateSet(meter metrix.SnapshotMeter, name string, states []string) metrix.StateSetInstrument {
149 return meter.StateSet(name, metrix.WithStateSetMode(metrix.ModeEnum), metrix.WithStateSetStates(states...))
150 }
151
152 func newBGPStateGauges(meter metrix.SnapshotVecMeter, prefix string) map[string]metrix.SnapshotGaugeVec {
153 return newStateGaugeVecs(meter, prefix, bgpStates)
154 }
155
156 func newStateSetVec(meter metrix.SnapshotVecMeter, name string, states []string) metrix.SnapshotStateSetVec {
157 return meter.StateSet(name, metrix.WithStateSetMode(metrix.ModeEnum), metrix.WithStateSetStates(states...))
158 }
159
160 func newStateGaugeVecs(meter metrix.SnapshotVecMeter, prefix string, states []string) map[string]metrix.SnapshotGaugeVec {
161 gauges := make(map[string]metrix.SnapshotGaugeVec, len(states))
162 for _, state := range states {
163 gauges[state] = meter.Gauge(prefix + "_" + state)
164 }
165 return gauges
166 }