Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b99d8ac
added fsw_port_stats probe
Jurka007 Jan 26, 2023
0f115c2
Update README.md
Jurka007 Jan 26, 2023
fd1da11
Update README.md
Jurka007 Jan 26, 2023
d52dba9
fortiswitch_health probe
Jurka007 Jan 31, 2023
80f4880
Update README.md
Jurka007 Feb 1, 2023
57d4fe8
formatting
Jurka007 Jul 24, 2023
9ea139d
Implement fixes and fortiOS 7 api changes
Jurka007 Mar 6, 2025
d31b720
Test fixes
Jurka007 Mar 7, 2025
d6ae32e
Remove debug code
Jurka007 Mar 7, 2025
fcce77d
Fix formating
Jurka007 Mar 7, 2025
cfbf61d
feat(probe): BGP session state as value (#237)
33Fraise33 Jul 25, 2023
6c9f3b8
doc(probe): improve metric descriptions (#239)
33Fraise33 Jul 25, 2023
cfa60f6
feat(probe): support for ippool info (#240)
33Fraise33 Aug 14, 2023
5979f3c
feat: added OSPF metrics and corresponding testcase (#255)
xerox81 Nov 24, 2023
946bbe4
fix(deps): update module github.com/prometheus/client_golang to v1.17…
renovate[bot] Nov 24, 2023
d02870b
chore(ci): bump actions versions
bluecmd Nov 24, 2023
db2cd36
fix(probe): correct OSPF state enum
benclerc Dec 28, 2023
2b9f590
feat: Added pba_per_ip return for ippool to differentiate between ipp…
33Fraise33 Jan 4, 2024
4728591
fix(deps): update module github.com/prometheus/client_golang to v1.18…
renovate[bot] Jan 8, 2024
40dad5b
chore(deps): update actions/setup-go action to v5 (#260)
renovate[bot] Jan 8, 2024
8795d10
Archive this repo
bluecmd Nov 9, 2024
bdc1129
chore: Change project license (#309)
SuperQ Feb 18, 2025
13c4eeb
Update for Prometheus Community (#312)
SuperQ Feb 24, 2025
57ba0c5
Add license header
Jurka007 Mar 7, 2025
64575ff
Update http library path
Jurka007 Mar 7, 2025
cf05e02
Merge branch 'main' into fortiswitch_port_stats
Jurka007 Mar 7, 2025
144805a
Update Poe struct to use float64 instead of int for Value and MaxValue
Jurka007 Apr 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
466 changes: 255 additions & 211 deletions README.md

Large diffs are not rendered by default.

197 changes: 197 additions & 0 deletions pkg/probe/fortiswitch_health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
// Copyright 2025 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package probe

import (
"fmt"
"log"

"github.com/prometheus-community/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)

func probeSwitchHealth(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
mSumCPU = prometheus.NewDesc(
"fortiswitch_health_summary_cpu",
"Boolean indicator if CPU health is good",
[]string{"value", "rating", "fortiswitch", "vdom"}, nil,
)
mSumMem = prometheus.NewDesc(
"fortiswitch_health_summary_memory",
"Boolean indicator if Memory health is good",
[]string{"value", "rating", "fortiswitch", "vdom"}, nil,
)
mSumUpTime = prometheus.NewDesc(
"fortiswitch_health_summary_uptime",
"Boolean indicator if Uptime is good",
[]string{"value", "rating", "fortiswitch", "vdom"}, nil,
)
mSumTemp = prometheus.NewDesc(
"fortiswitch_health_summary_temperature",
"Boolean indicator if Temperature health is good",
[]string{"value", "rating", "fortiswitch", "vdom"}, nil,
)
mTemp = prometheus.NewDesc(
"fortiswitch_health_temperature",
"Temperature per switch sensor",
[]string{"unit", "module", "fortiswitch", "vdom"}, nil,
)
mCpuUser = prometheus.NewDesc(
"fortiswitch_health_performance_stats_cpu_user",
"Fortiswitch CPU user usage",
[]string{"unit", "fortiswitch", "vdom"}, nil,
)
mCpuSystem = prometheus.NewDesc(
"fortiswitch_health_performance_stats_cpu_system",
"Fortiswitch CPU system usage",
[]string{"unit", "fortiswitch", "vdom"}, nil,
)
mCpuIdle = prometheus.NewDesc(
"fortiswitch_health_performance_stats_cpu_idle",
"Fortiswitch CPU idle",
[]string{"unit", "fortiswitch", "vdom"}, nil,
)
mCpuNice = prometheus.NewDesc(
"fortiswitch_health_performance_stats_cpu_nice",
"Fortiswitch CPU nice usage",
[]string{"unit", "fortiswitch", "vdom"}, nil,
)
)
type Sum struct {
Value float64 `json:"value"`
Rating string `json:"rating"`
}
type Status struct {
Value float64 `json:"value"`
Unit string `json:"unit"`
}
type Uptime struct {
Days Status `json:"days"`
Hours Status `json:"hours"`
Minutes Status `json:"minutes"`
}
type Network struct {
In1Min Status `json:"in-1min"`
In10Min Status `json:"in-10min"`
In30Min Status `json:"in-30min"`
}
type Memory struct {
Used Status `json:"used"`
}
type CPU struct {
User Status `json:"user"`
System Status `json:"system"`
Nice Status `json:"nice"`
Idle Status `json:"idle"`
}
type PerformanceStatus struct {
CPU CPU `json:"cpu"`
Memory Memory `json:"memory"`
Network Network `json:"network"`
Uptime Uptime `json:"uptime"`
}
type Temperature struct {
Module string
Status Status
}
type Summary struct {
Overall string `json:"overall"`
CPU Sum
Memory Sum
Uptime Sum
Temperature Sum
}
type Poe struct {
Value float64 `json:"value"`
MaxValue float64 `json:"max_value"`
Unit string `json:"unit"`
}
type Results struct {
PerformanceStatus PerformanceStatus `json:"performance-status"`
Temperature []Temperature `json:"temperature"`
Summary Summary `json:"summary"`
Poe Poe `json:"poe"`
}

type swResponse struct {
Results map[string]Results `json:"results"`
Vdom string
}

var apiPath string

if meta.VersionMajor > 7 || (meta.VersionMajor == 7 && meta.VersionMinor >= 6) {
apiPath = "api/v2/monitor/switch-controller/managed-switch/health-status"
} else {
apiPath = "api/v2/monitor/switch-controller/managed-switch/health"
}

var r swResponse

if err := c.Get(apiPath, "vdom=root", &r); err != nil {
log.Printf("Error: %v", err)
return nil, false
}

m := []prometheus.Metric{}

for fswitch, hr := range r.Results {

var cpuGood float64
if hr.Summary.CPU.Rating == "good" {
cpuGood = 1
} else {
cpuGood = 0
}
m = append(m, prometheus.MustNewConstMetric(mSumCPU, prometheus.GaugeValue, cpuGood, fmt.Sprintf("%.0f", hr.Summary.CPU.Value), hr.Summary.CPU.Rating, fswitch, r.Vdom))

var memGood float64
if hr.Summary.Memory.Rating == "good" {
memGood = 1
} else {
memGood = 0
}
m = append(m, prometheus.MustNewConstMetric(mSumMem, prometheus.GaugeValue, memGood, fmt.Sprintf("%0.f", hr.Summary.Memory.Value), hr.Summary.Memory.Rating, fswitch, r.Vdom))

var uptimeGood float64
if hr.Summary.Uptime.Rating == "good" {
uptimeGood = 1
} else {
uptimeGood = 0
}
m = append(m, prometheus.MustNewConstMetric(mSumUpTime, prometheus.GaugeValue, uptimeGood, fmt.Sprintf("%0.f", hr.Summary.Uptime.Value), hr.Summary.Uptime.Rating, fswitch, r.Vdom))

var tempGood float64
if hr.Summary.Temperature.Rating == "good" {
tempGood = 1
} else {
tempGood = 0
}
m = append(m, prometheus.MustNewConstMetric(mSumTemp, prometheus.GaugeValue, tempGood, fmt.Sprintf("%0.f", hr.Summary.Temperature.Value), hr.Summary.Temperature.Rating, fswitch, r.Vdom))

for _, ts := range hr.Temperature {
m = append(m, prometheus.MustNewConstMetric(mTemp, prometheus.GaugeValue, ts.Status.Value, ts.Status.Unit, ts.Module, fswitch, r.Vdom))
}

CpuUnit := hr.PerformanceStatus.CPU.System.Unit

m = append(m, prometheus.MustNewConstMetric(mCpuUser, prometheus.GaugeValue, hr.PerformanceStatus.CPU.User.Value, CpuUnit, fswitch, r.Vdom))
m = append(m, prometheus.MustNewConstMetric(mCpuNice, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Nice.Value, CpuUnit, fswitch, r.Vdom))
m = append(m, prometheus.MustNewConstMetric(mCpuSystem, prometheus.GaugeValue, hr.PerformanceStatus.CPU.System.Value, CpuUnit, fswitch, r.Vdom))
m = append(m, prometheus.MustNewConstMetric(mCpuIdle, prometheus.GaugeValue, hr.PerformanceStatus.CPU.Idle.Value, CpuUnit, fswitch, r.Vdom))
}

return m, true
}
103 changes: 103 additions & 0 deletions pkg/probe/fortiswitch_health_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright 2025 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package probe

import (
"strings"
"testing"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/testutil"
)

func TestSwitchHealth(t *testing.T) {
c := newFakeClient()
c.prepare("api/v2/monitor/switch-controller/managed-switch/health", "testdata/fsw-health.jsonnet")
r := prometheus.NewPedanticRegistry()
if !testProbe(probeSwitchHealth, c, r) {
t.Errorf("probeSwitchHealth() returned non-success")
}

em := `
# HELP fortiswitch_health_performance_stats_cpu_idle Fortiswitch CPU idle
# TYPE fortiswitch_health_performance_stats_cpu_idle gauge
fortiswitch_health_performance_stats_cpu_idle{fortiswitch="FS00000000000024",unit="%%",vdom="root"} 100
fortiswitch_health_performance_stats_cpu_idle{fortiswitch="FS00000000000027",unit="%%",vdom="root"} 100
fortiswitch_health_performance_stats_cpu_idle{fortiswitch="FS00000000000030",unit="%%",vdom="root"} 100
fortiswitch_health_performance_stats_cpu_idle{fortiswitch="FS00000000000038",unit="%%",vdom="root"} 100
# HELP fortiswitch_health_performance_stats_cpu_nice Fortiswitch CPU nice usage
# TYPE fortiswitch_health_performance_stats_cpu_nice gauge
fortiswitch_health_performance_stats_cpu_nice{fortiswitch="FS00000000000024",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_nice{fortiswitch="FS00000000000027",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_nice{fortiswitch="FS00000000000030",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_nice{fortiswitch="FS00000000000038",unit="%%",vdom="root"} 0
# HELP fortiswitch_health_performance_stats_cpu_system Fortiswitch CPU system usage
# TYPE fortiswitch_health_performance_stats_cpu_system gauge
fortiswitch_health_performance_stats_cpu_system{fortiswitch="FS00000000000024",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_system{fortiswitch="FS00000000000027",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_system{fortiswitch="FS00000000000030",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_system{fortiswitch="FS00000000000038",unit="%%",vdom="root"} 0
# HELP fortiswitch_health_performance_stats_cpu_user Fortiswitch CPU user usage
# TYPE fortiswitch_health_performance_stats_cpu_user gauge
fortiswitch_health_performance_stats_cpu_user{fortiswitch="FS00000000000024",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_user{fortiswitch="FS00000000000027",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_user{fortiswitch="FS00000000000030",unit="%%",vdom="root"} 0
fortiswitch_health_performance_stats_cpu_user{fortiswitch="FS00000000000038",unit="%%",vdom="root"} 0
# HELP fortiswitch_health_summary_cpu Boolean indicator if CPU health is good
# TYPE fortiswitch_health_summary_cpu gauge
fortiswitch_health_summary_cpu{fortiswitch="FS00000000000024",rating="good",value="0",vdom="root"} 1
fortiswitch_health_summary_cpu{fortiswitch="FS00000000000027",rating="good",value="0",vdom="root"} 1
fortiswitch_health_summary_cpu{fortiswitch="FS00000000000030",rating="good",value="0",vdom="root"} 1
fortiswitch_health_summary_cpu{fortiswitch="FS00000000000038",rating="good",value="0",vdom="root"} 1
# HELP fortiswitch_health_summary_memory Boolean indicator if Memory health is good
# TYPE fortiswitch_health_summary_memory gauge
fortiswitch_health_summary_memory{fortiswitch="FS00000000000024",rating="good",value="10",vdom="root"} 1
fortiswitch_health_summary_memory{fortiswitch="FS00000000000027",rating="good",value="15",vdom="root"} 1
fortiswitch_health_summary_memory{fortiswitch="FS00000000000030",rating="good",value="50",vdom="root"} 1
fortiswitch_health_summary_memory{fortiswitch="FS00000000000038",rating="good",value="32",vdom="root"} 1
# HELP fortiswitch_health_summary_temperature Boolean indicator if Temperature health is good
# TYPE fortiswitch_health_summary_temperature gauge
fortiswitch_health_summary_temperature{fortiswitch="FS00000000000024",rating="good",value="49",vdom="root"} 1
fortiswitch_health_summary_temperature{fortiswitch="FS00000000000027",rating="good",value="46",vdom="root"} 1
fortiswitch_health_summary_temperature{fortiswitch="FS00000000000030",rating="good",value="40",vdom="root"} 1
fortiswitch_health_summary_temperature{fortiswitch="FS00000000000038",rating="good",value="42",vdom="root"} 1
# HELP fortiswitch_health_summary_uptime Boolean indicator if Uptime is good
# TYPE fortiswitch_health_summary_uptime gauge
fortiswitch_health_summary_uptime{fortiswitch="FS00000000000024",rating="good",value="39289680",vdom="root"} 1
fortiswitch_health_summary_uptime{fortiswitch="FS00000000000027",rating="good",value="39289740",vdom="root"} 1
fortiswitch_health_summary_uptime{fortiswitch="FS00000000000030",rating="good",value="26612880",vdom="root"} 1
fortiswitch_health_summary_uptime{fortiswitch="FS00000000000038",rating="good",value="26612580",vdom="root"} 1
# HELP fortiswitch_health_temperature Temperature per switch sensor
# TYPE fortiswitch_health_temperature gauge
fortiswitch_health_temperature{fortiswitch="FS00000000000024",module="sensor1(CPU Board Temp)",unit="celsius",vdom="root"} 41.937
fortiswitch_health_temperature{fortiswitch="FS00000000000024",module="sensor2(MAIN Board Temp1)",unit="celsius",vdom="root"} 63.875
fortiswitch_health_temperature{fortiswitch="FS00000000000024",module="sensor3(MAIN Board Temp2)",unit="celsius",vdom="root"} 51.312
fortiswitch_health_temperature{fortiswitch="FS00000000000024",module="sensor4(MAIN Board Temp3)",unit="celsius",vdom="root"} 38.687
fortiswitch_health_temperature{fortiswitch="FS00000000000027",module="sensor1(CPU Board Temp)",unit="celsius",vdom="root"} 39
fortiswitch_health_temperature{fortiswitch="FS00000000000027",module="sensor2(MAIN Board Temp1)",unit="celsius",vdom="root"} 60.625
fortiswitch_health_temperature{fortiswitch="FS00000000000027",module="sensor3(MAIN Board Temp2)",unit="celsius",vdom="root"} 48.937
fortiswitch_health_temperature{fortiswitch="FS00000000000027",module="sensor4(MAIN Board Temp3)",unit="celsius",vdom="root"} 36.062
fortiswitch_health_temperature{fortiswitch="FS00000000000030",module="sensor1(CPU Board Temp)",unit="celsius",vdom="root"} 33.875
fortiswitch_health_temperature{fortiswitch="FS00000000000030",module="sensor2(MAIN Board Temp1)",unit="celsius",vdom="root"} 53.75
fortiswitch_health_temperature{fortiswitch="FS00000000000030",module="sensor3(MAIN Board Temp2)",unit="celsius",vdom="root"} 41
fortiswitch_health_temperature{fortiswitch="FS00000000000030",module="sensor4(MAIN Board Temp3)",unit="celsius",vdom="root"} 30.25
fortiswitch_health_temperature{fortiswitch="FS00000000000038",module="sensor1(CPU Board Temp)",unit="celsius",vdom="root"} 35.437
fortiswitch_health_temperature{fortiswitch="FS00000000000038",module="sensor2(MAIN Board Temp1)",unit="celsius",vdom="root"} 55.625
fortiswitch_health_temperature{fortiswitch="FS00000000000038",module="sensor3(MAIN Board Temp2)",unit="celsius",vdom="root"} 43.125
fortiswitch_health_temperature{fortiswitch="FS00000000000038",module="sensor4(MAIN Board Temp3)",unit="celsius",vdom="root"} 32.312
`
if err := testutil.GatherAndCompare(r, strings.NewReader(em)); err != nil {
t.Fatalf("metric compare: err %v", err)
}
}
Loading