Skip to content

Commit 27e2773

Browse files
committed
formatting
1 parent 9d0a753 commit 27e2773

File tree

3 files changed

+133
-135
lines changed

3 files changed

+133
-135
lines changed

pkg/probe/fortiswitch_health.go

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/bluecmd/fortigate_exporter/pkg/http"
77
"github.com/prometheus/client_golang/prometheus"
8-
98
)
109

1110
func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
@@ -57,17 +56,17 @@ func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Met
5756
)
5857
)
5958
type Sum struct {
60-
Value float64 `json:"value"`
61-
Rating string `json:"rating"`
59+
Value float64 `json:"value"`
60+
Rating string `json:"rating"`
6261
}
6362
type Status struct {
6463
Value float64 `json:"value"`
6564
Unit string `json:"unit"`
66-
}
65+
}
6766
type Uptime struct {
68-
Days Status `json:"days"`
69-
Hours Status `json:"hours"`
70-
Minutes Status `json:"minutes"`
67+
Days Status `json:"days"`
68+
Hours Status `json:"hours"`
69+
Minutes Status `json:"minutes"`
7170
}
7271
type Network struct {
7372
In1Min Status `json:"in-1min"`
@@ -90,15 +89,15 @@ func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Met
9089
Uptime Uptime `json:"uptime"`
9190
}
9291
type Temperature struct {
93-
Module string
94-
Status Status
92+
Module string
93+
Status Status
9594
}
9695
type Summary struct {
97-
Overall string `json:"overall"`
98-
CPU Sum
99-
Memory Sum
100-
Uptime Sum
101-
Temperature Sum
96+
Overall string `json:"overall"`
97+
CPU Sum
98+
Memory Sum
99+
Uptime Sum
100+
Temperature Sum
102101
}
103102
type Poe struct {
104103
Value int `json:"value"`
@@ -111,10 +110,10 @@ func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Met
111110
Summary Summary `json:"summary"`
112111
Poe Poe `json:"poe"`
113112
}
114-
113+
115114
type swResponse struct {
116-
Results map[string]Results `json:"results"`
117-
VDOM string
115+
Results map[string]Results `json:"results"`
116+
VDOM string
118117
}
119118
var r swResponse
120119
//var r map[string]swResponse
@@ -126,27 +125,27 @@ func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Met
126125
}
127126
m := []prometheus.Metric{}
128127
//for _, sw := range r {
129-
for fswitch, hr := range r.Results {
130-
131-
m = append(m, prometheus.MustNewConstMetric(mSumCPU, prometheus.GaugeValue, hr.Summary.CPU.Value, hr.Summary.CPU.Rating, fswitch, r.VDOM))
132-
m = append(m, prometheus.MustNewConstMetric(mSumMem, prometheus.GaugeValue, hr.Summary.Memory.Value, hr.Summary.Memory.Rating, fswitch, r.VDOM))
133-
m = append(m, prometheus.MustNewConstMetric(mSumUpTime, prometheus.GaugeValue, hr.Summary.Uptime.Value, hr.Summary.Uptime.Rating, fswitch, r.VDOM))
134-
m = append(m, prometheus.MustNewConstMetric(mSumTemp, prometheus.GaugeValue, hr.Summary.Temperature.Value, hr.Summary.Temperature.Rating, fswitch, r.VDOM))
128+
for fswitch, hr := range r.Results {
135129

136-
for _, ts := range hr.Temperature {
137-
m = append(m, prometheus.MustNewConstMetric(mTemp, prometheus.GaugeValue, ts.Status.Value, ts.Status.Unit, ts.Module, fswitch, r.VDOM))
138-
}
139-
140-
CpuUnit := hr.PerformanceStatus.CPU.System.Unit
141-
/*if CpuUnit == "%" {
142-
CpuUnit = "%%"
143-
}*/
130+
m = append(m, prometheus.MustNewConstMetric(mSumCPU, prometheus.GaugeValue, hr.Summary.CPU.Value, hr.Summary.CPU.Rating, fswitch, r.VDOM))
131+
m = append(m, prometheus.MustNewConstMetric(mSumMem, prometheus.GaugeValue, hr.Summary.Memory.Value, hr.Summary.Memory.Rating, fswitch, r.VDOM))
132+
m = append(m, prometheus.MustNewConstMetric(mSumUpTime, prometheus.GaugeValue, hr.Summary.Uptime.Value, hr.Summary.Uptime.Rating, fswitch, r.VDOM))
133+
m = append(m, prometheus.MustNewConstMetric(mSumTemp, prometheus.GaugeValue, hr.Summary.Temperature.Value, hr.Summary.Temperature.Rating, fswitch, r.VDOM))
144134

145-
m = append(m, prometheus.MustNewConstMetric(mCpuUser, prometheus.GaugeValue, hr.PerformanceStatus.CPU.User.Value, CpuUnit, fswitch, r.VDOM))
146-
m = append(m, prometheus.MustNewConstMetric(mCpuNice, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Nice.Value, CpuUnit, fswitch, r.VDOM))
147-
m = append(m, prometheus.MustNewConstMetric(mCpuSystem, prometheus.GaugeValue, hr.PerformanceStatus.CPU.System.Value, CpuUnit, fswitch, r.VDOM))
148-
m = append(m, prometheus.MustNewConstMetric(mCpuIdle, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Idle.Value, CpuUnit, fswitch, r.VDOM))
135+
for _, ts := range hr.Temperature {
136+
m = append(m, prometheus.MustNewConstMetric(mTemp, prometheus.GaugeValue, ts.Status.Value, ts.Status.Unit, ts.Module, fswitch, r.VDOM))
149137
}
138+
139+
CpuUnit := hr.PerformanceStatus.CPU.System.Unit
140+
/*if CpuUnit == "%" {
141+
CpuUnit = "%%"
142+
}*/
143+
144+
m = append(m, prometheus.MustNewConstMetric(mCpuUser, prometheus.GaugeValue, hr.PerformanceStatus.CPU.User.Value, CpuUnit, fswitch, r.VDOM))
145+
m = append(m, prometheus.MustNewConstMetric(mCpuNice, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Nice.Value, CpuUnit, fswitch, r.VDOM))
146+
m = append(m, prometheus.MustNewConstMetric(mCpuSystem, prometheus.GaugeValue, hr.PerformanceStatus.CPU.System.Value, CpuUnit, fswitch, r.VDOM))
147+
m = append(m, prometheus.MustNewConstMetric(mCpuIdle, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Idle.Value, CpuUnit, fswitch, r.VDOM))
148+
}
150149
//}
151150
return m, true
152151
}

pkg/probe/fortiswitch_health_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func TestSwitchHealth(t *testing.T) {
1515
if !testProbe(probeSwitchHealth, c, r) {
1616
t.Errorf("probeSwitchHealth() returned non-success")
1717
}
18-
18+
1919
em := `
2020
# HELP fortiswitch_health_performance_stats_cpu_idle Fortiswitch CPU idle
2121
# TYPE fortiswitch_health_performance_stats_cpu_idle gauge

pkg/probe/fortiswitch_port_stats.go

Lines changed: 98 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55

66
"github.com/bluecmd/fortigate_exporter/pkg/http"
77
"github.com/prometheus/client_golang/prometheus"
8-
98
)
109

1110
func 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

Comments
 (0)