Browse Source

Made the removal of non numeric values more robust.

master
Egon Rijpkema 1 year ago
parent
commit
e69c565871
  1. 6
      nvidia_smi_exporter.go

6
nvidia_smi_exporter.go

@ -45,6 +45,11 @@ func metrics(response http.ResponseWriter, request *http.Request) { @@ -45,6 +45,11 @@ func metrics(response http.ResponseWriter, request *http.Request) {
name := fmt.Sprintf("%s[%s]", row[0], row[1])
for idx, value := range row[2:] {
metric := strings.Replace(metricList[idx], ".", "_", -1)
// Non numerical values like [N/A] wil break prometeus when a number is expected.
_, err := strconv.Atoi(value)
if err != nil {
value = "-1"
}
result = fmt.Sprintf(
"%s%s{gpu=\"%s\"} %s\n", result,
metric, name, value)
@ -54,7 +59,6 @@ func metrics(response http.ResponseWriter, request *http.Request) { @@ -54,7 +59,6 @@ func metrics(response http.ResponseWriter, request *http.Request) {
deviceCount, err = strconv.Atoi(max_id)
result = fmt.Sprintf(
"%sdeviceCount %d\n", result, deviceCount+1)
result = strings.Replace(result, "[Not Supported]", "-1", -1)
}

Loading…
Cancel
Save