Skip to content
This repository has been archived by the owner on Sep 28, 2020. It is now read-only.

Commit

Permalink
Update on missing metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Pablo Opazo committed Nov 16, 2018
1 parent e083150 commit 77e123d
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 33 deletions.
3 changes: 3 additions & 0 deletions ..gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nut_exporter
*.tar.gz

110 changes: 77 additions & 33 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,39 +112,83 @@ func recordMetrics(upscBinary string, upsArg string){
log.Fatal(err)
}

batteryChargeValue, _ := strconv.ParseFloat(batteryChargeRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryCharge.Set(batteryChargeValue)

batteryPacksValue, _ := strconv.ParseFloat(batteryPacksRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryPacks.Set(batteryPacksValue)

batteryVoltageValue, _ := strconv.ParseFloat(batteryVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryVoltage.Set(batteryVoltageValue)

batteryVoltageNominalValue, _ := strconv.ParseFloat(batteryVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryVoltageNominal.Set(batteryVoltageNominalValue)

inputVoltageValue, _ := strconv.ParseFloat(inputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
inputVoltage.Set(inputVoltageValue)

inputVoltageNominalValue, _ := strconv.ParseFloat(inputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
inputVoltageNominal.Set(inputVoltageNominalValue)

outputVoltageValue, _ := strconv.ParseFloat(outputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
outputVoltage.Set(outputVoltageValue)

outputVoltageNominalValue, _ := strconv.ParseFloat(outputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
outputVoltageNominal.Set(outputVoltageNominalValue)

upsPowerNominalValue, _ := strconv.ParseFloat(upsPowerNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsPowerNominal.Set(upsPowerNominalValue)

upsTempValue, _ := strconv.ParseFloat(upsTempRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsTemp.Set(upsTempValue)

upsLoadValue, _ := strconv.ParseFloat(upsLoadRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsLoad.Set(upsLoadValue)

if batteryChargeRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(batteryCharge)
} else {
batteryChargeValue, _ := strconv.ParseFloat(batteryChargeRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryCharge.Set(batteryChargeValue)
}

if batteryPacksRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(batteryPacks)
} else {
batteryPacksValue, _ := strconv.ParseFloat(batteryPacksRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryPacks.Set(batteryPacksValue)
}

if batteryVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(batteryVoltage)
} else {
batteryVoltageValue, _ := strconv.ParseFloat(batteryVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryVoltage.Set(batteryVoltageValue)
}

if batteryVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(batteryVoltageNominal)
} else {
batteryVoltageNominalValue, _ := strconv.ParseFloat(batteryVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
batteryVoltageNominal.Set(batteryVoltageNominalValue)
}

if inputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(inputVoltage)
} else {
inputVoltageValue, _ := strconv.ParseFloat(inputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
inputVoltage.Set(inputVoltageValue)
}

if inputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(inputVoltageNominal)
} else {
inputVoltageNominalValue, _ := strconv.ParseFloat(inputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
inputVoltageNominal.Set(inputVoltageNominalValue)
}

if outputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(outputVoltage)
} else {
outputVoltageValue, _ := strconv.ParseFloat(outputVoltageRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
outputVoltage.Set(outputVoltageValue)
}

if outputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(outputVoltageNominal)
} else {
outputVoltageNominalValue, _ := strconv.ParseFloat(outputVoltageNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
outputVoltageNominal.Set(outputVoltageNominalValue)
}

if upsPowerNominalRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(upsPowerNominal)
} else {
upsPowerNominalValue, _ := strconv.ParseFloat(upsPowerNominalRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsPowerNominal.Set(upsPowerNominalValue)
}

if upsTempRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(upsTemp)
} else {
upsTempValue, _ := strconv.ParseFloat(upsTempRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsTemp.Set(upsTempValue)
}

if upsLoadRegex.FindAllStringSubmatch(string(upsOutput), -1) == nil {
prometheus.Unregister(upsLoad)
} else {
upsLoadValue, _ := strconv.ParseFloat(upsLoadRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1], 64)
upsLoad.Set(upsLoadValue)
}

upsStatusValue := upsStatusRegex.FindAllStringSubmatch(string(upsOutput), -1)[0][1]

switch upsStatusValue {
Expand Down
Binary file added nut_exporter
Binary file not shown.

0 comments on commit 77e123d

Please sign in to comment.