55
66 "github.com/bluecmd/fortigate_exporter/pkg/http"
77 "github.com/prometheus/client_golang/prometheus"
8-
98)
109
1110func probeSwitchPortStats (c http.FortiHTTP , meta * TargetMetadata ) ([]prometheus.Metric , bool ) {
@@ -70,79 +69,79 @@ func probeSwitchPortStats(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.
7069 "Number of packets received on the interface" ,
7170 []string {"vdom" , "name" , "interface" }, nil ,
7271 )
73- mRxB = prometheus .NewDesc (
74- "fortiswitch_port_receive_bytes_total" ,
75- "Number of bytes received on the interface" ,
76- []string {"vdom" , "name" , "interface" }, nil ,
77- )
78- mRxUcast = prometheus .NewDesc (
79- "fortiswitch_port_receive_unicast_packets_total" ,
80- "Number of unicast packets received on the interface" ,
81- []string {"vdom" , "name" , "interface" }, nil ,
82- )
83- mRxMcast = prometheus .NewDesc (
84- "fortiswitch_port_receive_multicast_packets_total" ,
85- "Number of multicast packets received on the interface" ,
86- []string {"vdom" , "name" , "interface" }, nil ,
87- )
88- mRxBcast = prometheus .NewDesc (
89- "fortiswitch_port_receive_broadcast_packets_total" ,
90- "Number of broadcast packets received on the interface" ,
91- []string {"vdom" , "name" , "interface" }, nil ,
92- )
93- mRxErr = prometheus .NewDesc (
94- "fortiswitch_port_receive_errors_total" ,
95- "Number of transmission errors detected on the interface" ,
96- []string {"vdom" , "name" , "interface" }, nil ,
97- )
98- mRxDrops = prometheus .NewDesc (
99- "fortiswitch_port_receive_drops_total" ,
100- "Number of dropped packets detected during transmission on the interface" ,
101- []string {"vdom" , "name" , "interface" }, nil ,
102- )
103- mRxOverS = prometheus .NewDesc (
104- "fortiswitch_port_receive_oversized_packets_total" ,
105- "Number of oversized packets received on the interface" ,
106- []string {"vdom" , "name" , "interface" }, nil ,
72+ mRxB = prometheus .NewDesc (
73+ "fortiswitch_port_receive_bytes_total" ,
74+ "Number of bytes received on the interface" ,
75+ []string {"vdom" , "name" , "interface" }, nil ,
76+ )
77+ mRxUcast = prometheus .NewDesc (
78+ "fortiswitch_port_receive_unicast_packets_total" ,
79+ "Number of unicast packets received on the interface" ,
80+ []string {"vdom" , "name" , "interface" }, nil ,
81+ )
82+ mRxMcast = prometheus .NewDesc (
83+ "fortiswitch_port_receive_multicast_packets_total" ,
84+ "Number of multicast packets received on the interface" ,
85+ []string {"vdom" , "name" , "interface" }, nil ,
86+ )
87+ mRxBcast = prometheus .NewDesc (
88+ "fortiswitch_port_receive_broadcast_packets_total" ,
89+ "Number of broadcast packets received on the interface" ,
90+ []string {"vdom" , "name" , "interface" }, nil ,
91+ )
92+ mRxErr = prometheus .NewDesc (
93+ "fortiswitch_port_receive_errors_total" ,
94+ "Number of transmission errors detected on the interface" ,
95+ []string {"vdom" , "name" , "interface" }, nil ,
96+ )
97+ mRxDrops = prometheus .NewDesc (
98+ "fortiswitch_port_receive_drops_total" ,
99+ "Number of dropped packets detected during transmission on the interface" ,
100+ []string {"vdom" , "name" , "interface" }, nil ,
101+ )
102+ mRxOverS = prometheus .NewDesc (
103+ "fortiswitch_port_receive_oversized_packets_total" ,
104+ "Number of oversized packets received on the interface" ,
105+ []string {"vdom" , "name" , "interface" }, nil ,
107106 )
108107 )
109108
110109 type portStats struct {
111- TxPackets float64 `json:"tx-packets"`
112- TxBytes float64 `json:"tx-bytes"`
113- TxErrors float64 `json:"tx-errors"`
114- TxMcast float64 `json:"tx-mcast"`
115- TxUcast float64 `json:"tx-ucast"`
116- TxBcast float64 `json:"tx-bcast"`
117- TxDrops float64 `json:"tx-drops"`
118- TxOversize float64 `json:"tx-oversize"`
119- RxPackets float64 `json:"rx-packets"`
120- RxBytes float64 `json:"rx-bytes"`
121- RxErrors float64 `json:"rx-errors"`
122- RxMcast float64 `json:"rx-mcast"`
123- RxUcast float64 `json:"rx-ucast"`
124- RxBcast float64 `json:"rx-bcast"`
125- RxDrops float64 `json:"rx-drops"`
126- RxOversize float64 `json:"rx-oversize"`
110+ TxPackets float64 `json:"tx-packets"`
111+ TxBytes float64 `json:"tx-bytes"`
112+ TxErrors float64 `json:"tx-errors"`
113+ TxMcast float64 `json:"tx-mcast"`
114+ TxUcast float64 `json:"tx-ucast"`
115+ TxBcast float64 `json:"tx-bcast"`
116+ TxDrops float64 `json:"tx-drops"`
117+ TxOversize float64 `json:"tx-oversize"`
118+ RxPackets float64 `json:"rx-packets"`
119+ RxBytes float64 `json:"rx-bytes"`
120+ RxErrors float64 `json:"rx-errors"`
121+ RxMcast float64 `json:"rx-mcast"`
122+ RxUcast float64 `json:"rx-ucast"`
123+ RxBcast float64 `json:"rx-bcast"`
124+ RxDrops float64 `json:"rx-drops"`
125+ RxOversize float64 `json:"rx-oversize"`
127126 }
128127 type portsInfo struct {
129- Interface string
130- Status string
131- Duplex string
132- Speed float64
133- Vlan string
128+ Interface string
129+ Status string
130+ Duplex string
131+ Speed float64
132+ Vlan string
134133 }
135134 type swResult struct {
136- Name string
137- FgPeerIntfName string `json:"fgt_peer_intf_name"`
138- Status string
139- State string
140- Connection string `json:"connecting_from"`
141- VDOM string
142- Ports []portsInfo
143- PortStats map [string ]portStats `json:"port_stats"`
135+ Name string
136+ FgPeerIntfName string `json:"fgt_peer_intf_name"`
137+ Status string
138+ State string
139+ Connection string `json:"connecting_from"`
140+ VDOM string
141+ Ports []portsInfo
142+ PortStats map [string ]portStats `json:"port_stats"`
144143 }
145-
144+
146145 type swResponse struct {
147146 //Results map[string]swResult
148147 Results []swResult `json:"results"`
@@ -157,43 +156,43 @@ func probeSwitchPortStats(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.
157156 return nil , false
158157 }
159158 m := []prometheus.Metric {}
160- // for _, v := range r {
161- for _ , swr := range r .Results {
162- swStatus := 0.0
163- if swr .Status == "Connected" {
164- swStatus = 1.0
165- }
166- m = append (m , prometheus .MustNewConstMetric (mSwitchStatus , prometheus .GaugeValue , swStatus , swr .VDOM , swr .Name , swr .FgPeerIntfName , swr .Connection , swr .State ))
167-
168- for _ , pi := range swr .Ports {
169- pStatus := 0.0
170- if pi .Status == "up" {
171- pStatus = 1.0
172- }
173- m = append (m , prometheus .MustNewConstMetric (mPortStatus , prometheus .GaugeValue , pStatus , swr .VDOM , swr .Name , pi .Interface , pi .Vlan , pi .Duplex ))
174- m = append (m , prometheus .MustNewConstMetric (mPortSpeed , prometheus .GaugeValue , pi .Speed * 1000 * 1000 , swr .VDOM , swr .Name , pi .Interface , pi .Vlan , pi .Duplex ))
159+ // for _, v := range r {
160+ for _ , swr := range r .Results {
161+ swStatus := 0.0
162+ if swr .Status == "Connected" {
163+ swStatus = 1.0
164+ }
165+ m = append (m , prometheus .MustNewConstMetric (mSwitchStatus , prometheus .GaugeValue , swStatus , swr .VDOM , swr .Name , swr .FgPeerIntfName , swr .Connection , swr .State ))
175166
167+ for _ , pi := range swr .Ports {
168+ pStatus := 0.0
169+ if pi .Status == "up" {
170+ pStatus = 1.0
176171 }
172+ m = append (m , prometheus .MustNewConstMetric (mPortStatus , prometheus .GaugeValue , pStatus , swr .VDOM , swr .Name , pi .Interface , pi .Vlan , pi .Duplex ))
173+ m = append (m , prometheus .MustNewConstMetric (mPortSpeed , prometheus .GaugeValue , pi .Speed * 1000 * 1000 , swr .VDOM , swr .Name , pi .Interface , pi .Vlan , pi .Duplex ))
177174
178- for port , ps := range swr .PortStats {
179- m = append (m , prometheus .MustNewConstMetric (mTxPkts , prometheus .CounterValue , ps .TxPackets , swr .VDOM , swr .Name , port ))
180- m = append (m , prometheus .MustNewConstMetric (mTxB , prometheus .CounterValue , ps .TxBytes , swr .VDOM , swr .Name , port ))
181- m = append (m , prometheus .MustNewConstMetric (mTxUcast , prometheus .CounterValue , ps .TxUcast , swr .VDOM , swr .Name , port ))
182- m = append (m , prometheus .MustNewConstMetric (mTxBcast , prometheus .CounterValue , ps .TxBcast , swr .VDOM , swr .Name , port ))
183- m = append (m , prometheus .MustNewConstMetric (mTxMcast , prometheus .CounterValue , ps .TxMcast , swr .VDOM , swr .Name , port ))
184- m = append (m , prometheus .MustNewConstMetric (mTxErr , prometheus .CounterValue , ps .TxErrors , swr .VDOM , swr .Name , port ))
185- m = append (m , prometheus .MustNewConstMetric (mTxDrops , prometheus .CounterValue , ps .TxDrops , swr .VDOM , swr .Name , port ))
186- m = append (m , prometheus .MustNewConstMetric (mTxOverS , prometheus .CounterValue , ps .TxOversize , swr .VDOM , swr .Name , port ))
187- m = append (m , prometheus .MustNewConstMetric (mRxPkts , prometheus .CounterValue , ps .RxPackets , swr .VDOM , swr .Name , port ))
188- m = append (m , prometheus .MustNewConstMetric (mRxB , prometheus .CounterValue , ps .RxBytes , swr .VDOM , swr .Name , port ))
189- m = append (m , prometheus .MustNewConstMetric (mRxUcast , prometheus .CounterValue , ps .RxUcast , swr .VDOM , swr .Name , port ))
190- m = append (m , prometheus .MustNewConstMetric (mRxBcast , prometheus .CounterValue , ps .RxBcast , swr .VDOM , swr .Name , port ))
191- m = append (m , prometheus .MustNewConstMetric (mRxMcast , prometheus .CounterValue , ps .RxMcast , swr .VDOM , swr .Name , port ))
192- m = append (m , prometheus .MustNewConstMetric (mRxErr , prometheus .CounterValue , ps .RxErrors , swr .VDOM , swr .Name , port ))
193- m = append (m , prometheus .MustNewConstMetric (mRxDrops , prometheus .CounterValue , ps .RxDrops , swr .VDOM , swr .Name , port ))
194- m = append (m , prometheus .MustNewConstMetric (mRxOverS , prometheus .CounterValue , ps .RxOversize , swr .VDOM , swr .Name , port ))
195- }
196175 }
197- // }
176+
177+ for port , ps := range swr .PortStats {
178+ m = append (m , prometheus .MustNewConstMetric (mTxPkts , prometheus .CounterValue , ps .TxPackets , swr .VDOM , swr .Name , port ))
179+ m = append (m , prometheus .MustNewConstMetric (mTxB , prometheus .CounterValue , ps .TxBytes , swr .VDOM , swr .Name , port ))
180+ m = append (m , prometheus .MustNewConstMetric (mTxUcast , prometheus .CounterValue , ps .TxUcast , swr .VDOM , swr .Name , port ))
181+ m = append (m , prometheus .MustNewConstMetric (mTxBcast , prometheus .CounterValue , ps .TxBcast , swr .VDOM , swr .Name , port ))
182+ m = append (m , prometheus .MustNewConstMetric (mTxMcast , prometheus .CounterValue , ps .TxMcast , swr .VDOM , swr .Name , port ))
183+ m = append (m , prometheus .MustNewConstMetric (mTxErr , prometheus .CounterValue , ps .TxErrors , swr .VDOM , swr .Name , port ))
184+ m = append (m , prometheus .MustNewConstMetric (mTxDrops , prometheus .CounterValue , ps .TxDrops , swr .VDOM , swr .Name , port ))
185+ m = append (m , prometheus .MustNewConstMetric (mTxOverS , prometheus .CounterValue , ps .TxOversize , swr .VDOM , swr .Name , port ))
186+ m = append (m , prometheus .MustNewConstMetric (mRxPkts , prometheus .CounterValue , ps .RxPackets , swr .VDOM , swr .Name , port ))
187+ m = append (m , prometheus .MustNewConstMetric (mRxB , prometheus .CounterValue , ps .RxBytes , swr .VDOM , swr .Name , port ))
188+ m = append (m , prometheus .MustNewConstMetric (mRxUcast , prometheus .CounterValue , ps .RxUcast , swr .VDOM , swr .Name , port ))
189+ m = append (m , prometheus .MustNewConstMetric (mRxBcast , prometheus .CounterValue , ps .RxBcast , swr .VDOM , swr .Name , port ))
190+ m = append (m , prometheus .MustNewConstMetric (mRxMcast , prometheus .CounterValue , ps .RxMcast , swr .VDOM , swr .Name , port ))
191+ m = append (m , prometheus .MustNewConstMetric (mRxErr , prometheus .CounterValue , ps .RxErrors , swr .VDOM , swr .Name , port ))
192+ m = append (m , prometheus .MustNewConstMetric (mRxDrops , prometheus .CounterValue , ps .RxDrops , swr .VDOM , swr .Name , port ))
193+ m = append (m , prometheus .MustNewConstMetric (mRxOverS , prometheus .CounterValue , ps .RxOversize , swr .VDOM , swr .Name , port ))
194+ }
195+ }
196+ // }
198197 return m , true
199198}
0 commit comments