forked from prometheus-community/fortigate_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsystem_sensor_info.go
More file actions
108 lines (97 loc) · 3.43 KB
/
Copy pathsystem_sensor_info.go
File metadata and controls
108 lines (97 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// 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 (
"log"
"reflect"
"github.com/prometheus-community/fortigate_exporter/pkg/http"
"github.com/prometheus/client_golang/prometheus"
)
func probeSystemSensorInfo(c http.FortiHTTP, meta *TargetMetadata) ([]prometheus.Metric, bool) {
var (
sensorTemperature = prometheus.NewDesc(
"fortigate_sensor_temperature_celsius",
"Sensor temperature in degree celsius",
[]string{"name"}, nil,
)
sensorFan = prometheus.NewDesc(
"fortigate_sensor_fan_rpm",
"Sensor fan rotation speed in RPM",
[]string{"name"}, nil,
)
sensorVoltage = prometheus.NewDesc(
"fortigate_sensor_voltage_volts",
"Sensor voltage in volts",
[]string{"name"}, nil,
)
sensorAlarm = prometheus.NewDesc(
"fortigate_sensor_alarm_status",
"Sensor alarm status",
[]string{"name"}, nil,
)
sensorThresholds = prometheus.NewDesc(
"fortigate_sensor_thresholds",
"Sensor threasholds",
[]string{"name", "threshold"}, nil,
)
)
type SystemSensorInfoResultsThresholds struct {
LowerNonRec float64 `json:"lower_non_recoverable,omitempty"`
LowerCrit float64 `json:"lower_critical,omitempty"`
LowerNonCrit float64 `json:"lower_non_critical,omitempty"`
UpperNonCrit float64 `json:"upper_non_critical,omitempty"`
UpperCrit float64 `json:"upper_critical,omitempty"`
UpperNonRec float64 `json:"upper_non_recoverable,omitempty"`
}
type SystemSensorInfoResults struct {
Name string `json:"name"`
Type string `json:"type"`
Value float64 `json:"value"`
Alarm bool `json:"alarm"`
Thresholds SystemSensorInfoResultsThresholds `json:"thresholds"`
}
type SystemSensorInfo struct {
Results []SystemSensorInfoResults `json:"results"`
}
var res SystemSensorInfo
if err := c.Get("api/v2/monitor/system/sensor-info", "vdom=root", &res); err != nil {
log.Printf("Warning: %v", err)
return nil, false
}
m := []prometheus.Metric{}
for _, r := range res.Results {
switch meta.VersionMajor {
case 7:
alarm := 0.0
if r.Alarm {
alarm = 1.0
}
m = append(m, prometheus.MustNewConstMetric(sensorAlarm, prometheus.GaugeValue, alarm, r.Name))
v := reflect.ValueOf(r.Thresholds)
for i := range v.NumField() {
if v.Field(i).Float() != 0 {
m = append(m, prometheus.MustNewConstMetric(sensorThresholds, prometheus.GaugeValue, v.Field(i).Float(), r.Name, v.Type().Field(i).Name))
}
}
}
switch r.Type {
case "temperature":
m = append(m, prometheus.MustNewConstMetric(sensorTemperature, prometheus.GaugeValue, r.Value, r.Name))
case "fan":
m = append(m, prometheus.MustNewConstMetric(sensorFan, prometheus.GaugeValue, r.Value, r.Name))
case "voltage":
m = append(m, prometheus.MustNewConstMetric(sensorVoltage, prometheus.GaugeValue, r.Value, r.Name))
}
}
return m, true
}