Skip to content

Commit

Permalink
Update perfdata generation and remove nonsensical perfdata
Browse files Browse the repository at this point in the history
  • Loading branch information
martialblog committed Jun 24, 2024
1 parent 4204a0e commit 63b7ee4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
8 changes: 2 additions & 6 deletions cmd/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s
check.ExitError(fmt.Errorf(output))
}
p := perfdata.PerfdataList{
{Label: "statuscode", Value: sc},
{Label: "statuscode", Value: float64(sc)},
}

check.ExitRaw(rc, output, "|", p.String())
Expand All @@ -68,10 +68,6 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s

p := perfdata.PerfdataList{
{Label: "statuscode", Value: 200},
{Label: "version", Value: info.Version},
{Label: "builddate", Value: info.BuildDate},
{Label: "builduser", Value: info.BuildUser},
{Label: "revision", Value: info.Revision},
}

check.ExitRaw(rc, output, "|", p.String())
Expand All @@ -85,7 +81,7 @@ Ready: Checks the readiness of an endpoint, which returns OK if the Prometheus s
}

p := perfdata.PerfdataList{
{Label: "statuscode", Value: sc},
{Label: "statuscode", Value: float64(sc)},
}

check.ExitRaw(rc, output, "|", p.String())
Expand Down
2 changes: 1 addition & 1 deletion cmd/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestHealthCmd(t *testing.T) {
w.Write([]byte(`{"status":"success","data":{"version":"2.30.3","revision":"foo","branch":"HEAD","buildUser":"root@foo","buildDate":"20211005-16:10:52","goVersion":"go1.17.1"}}`))
})),
args: []string{"run", "../main.go", "health", "--info"},
expected: "[OK] - Prometheus Server information\n\nVersion: 2.30.3\nBranch: HEAD\nBuildDate: 20211005-16:10:52\nBuildUser: root@foo\nRevision: foo | statuscode=200 version=2.30.3 builddate=20211005-16:10:52 builduser=root@foo revision=foo\n",
expected: "[OK] - Prometheus Server information\n\nVersion: 2.30.3\nBranch: HEAD\nBuildDate: 20211005-16:10:52\nBuildUser: root@foo\nRevision: foo | statuscode=200\n",
},
{
name: "health-bearer-ok",
Expand Down
6 changes: 3 additions & 3 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func generateMetricOutput(rc int, metric string, value string) string {
return fmt.Sprintf(" \\_[%s] %s - value: %s\n", check.StatusText(rc), metric, value)
}

func generatePerfdata(metric, value string, warning, critical *check.Threshold) perfdata.Perfdata {
func generatePerfdata(metric string, value float64, warning, critical *check.Threshold) perfdata.Perfdata {
// We trim the trailing "} from the string, so that the Perfdata won't have a trailing _
return perfdata.Perfdata{
Label: replacer.Replace(metric),
Expand Down Expand Up @@ -138,7 +138,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
metricOutput.WriteString(generateMetricOutput(rc, sample.Metric.String(), sample.Value.String()))

// Generate Perfdata from API return
perf := generatePerfdata(sample.Metric.String(), sample.Value.String(), warn, crit)
perf := generatePerfdata(sample.Metric.String(), float64(sample.Value), warn, crit)
perfList.Add(&perf)
}
states = vStates
Expand Down Expand Up @@ -172,7 +172,7 @@ Note: Time range values e.G. 'go_memstats_alloc_bytes_total[0s]' only the latest
metricOutput.WriteString(generateMetricOutput(rc, samplepair.String(), samplepair.Value.String()))

// Generate Perfdata from API return
perf := generatePerfdata(samplestream.Metric.String(), samplepair.Value.String(), warn, crit)
perf := generatePerfdata(samplestream.Metric.String(), float64(samplepair.Value), warn, crit)
perfList.Add(&perf)
}
states = mStates
Expand Down

0 comments on commit 63b7ee4

Please sign in to comment.