Skip to content

Commit

Permalink
add 3 desc, and fix up_time to remaining_time
Browse files Browse the repository at this point in the history
  • Loading branch information
kerwenwwer committed Jul 7, 2021
1 parent 33b3bc8 commit 3f12b99
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,21 @@ var (
[]string{"device"},
nil)

UptimeDesc = prometheus.NewDesc(
"ups_uptime",
"UPS Uptime(min)",
RtimeDesc = prometheus.NewDesc(
"ups_remaining_runtime",
"UPS Remaining Runtime(min)",
[]string{"device"},
nil)

OutVoltageDesc = prometheus.NewDesc(
"ups_out_voltage",
"UPS Output Voltage(V): pass-> 1 non_pass -> 0",
[]string{"device"},
nil)

TestDesc = prometheus.NewDesc(
"ups_test_result",
"UPS Test Result",
[]string{"device"},
nil)
)
Expand All @@ -50,7 +62,9 @@ func (l *PwrstatCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- LoadDesc
ch <- StateDesc
ch <- BatteryDesc
ch <- UptimeDesc
ch <- RtimeDesc
ch <- OutVoltageDesc
ch <- TestDesc
}

func (l *PwrstatCollector) Collect(ch chan<- prometheus.Metric) {
Expand Down Expand Up @@ -82,9 +96,24 @@ func (l *PwrstatCollector) Collect(ch chan<- prometheus.Metric) {
} else if k == "Remaining Runtime" {
value_arr := strings.Fields(v)
if value, err := strconv.ParseFloat(value_arr[0], 64); err == nil {
ch <- prometheus.MustNewConstMetric(UptimeDesc,
ch <- prometheus.MustNewConstMetric(RtimeDesc,
prometheus.GaugeValue, value, status.Status["Model Name"])
}
} else if k == "Output Voltage" {
value_arr := strings.Fields(v)
if value, err := strconv.ParseFloat(value_arr[0], 64); err == nil {
ch <- prometheus.MustNewConstMetric(OutVoltageDesc,
prometheus.GaugeValue, value, status.Status["Model Name"])
}
} else if k == "Test Result" {
value_arr := strings.Fields(v)
if value_arr[0] == "Passed" {
ch <- prometheus.MustNewConstMetric(TestDesc,
prometheus.GaugeValue, 1, status.Status["Model Name"])
} else {
ch <- prometheus.MustNewConstMetric(TestDesc,
prometheus.GaugeValue, 0, status.Status["Model Name"])
}
}
}
}
Expand Down

0 comments on commit 3f12b99

Please sign in to comment.