ce7cb702218693d08ea6d83464d2457c9250027c
This commit is contained in:
commit
34c5f8963c
1 changed files with 145336 additions and 0 deletions
48
packages/smartctl/verify_test.go
Normal file
48
packages/smartctl/verify_test.go
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
type scsiCollector struct{}
|
||||
|
||||
func (scsiCollector) Describe(descriptors chan<- *prometheus.Desc) {
|
||||
new(SMARTctlManagerCollector).Describe(descriptors)
|
||||
}
|
||||
|
||||
func (scsiCollector) Collect(metrics chan<- prometheus.Metric) {
|
||||
data := gjson.Parse(`{"scsi_error_counter_log":{"read":{},"write":{},"verify":{"errors_corrected_by_rereads_rewrites":1,"errors_corrected_by_eccfast":2,"errors_corrected_by_eccdelayed":3,"total_uncorrected_errors":4}}}`)
|
||||
logger := slog.New(slog.NewTextHandler(io.Discard, nil))
|
||||
smart := NewSMARTctl(logger, data, metrics, Device{Label: "synthetic"})
|
||||
smart.mineSCSIErrorCounterLog()
|
||||
}
|
||||
|
||||
func TestSCSIVerifyScrape(t *testing.T) {
|
||||
registry := prometheus.NewPedanticRegistry()
|
||||
registry.MustRegister(scsiCollector{})
|
||||
response := httptest.NewRecorder()
|
||||
request := httptest.NewRequest(http.MethodGet, "/metrics", nil)
|
||||
promhttp.HandlerFor(registry, promhttp.HandlerOpts{}).ServeHTTP(response, request)
|
||||
if response.Code != http.StatusOK {
|
||||
t.Fatalf("metrics returned HTTP %d: %s", response.Code, response.Body.String())
|
||||
}
|
||||
for _, expected := range []string{
|
||||
`smartctl_verify_errors_corrected_by_rereads_rewrites{device="synthetic"} 1`,
|
||||
`smartctl_verify_errors_corrected_by_eccfast{device="synthetic"} 2`,
|
||||
`smartctl_verify_errors_corrected_by_eccdelayed{device="synthetic"} 3`,
|
||||
`smartctl_verify_total_uncorrected_errors{device="synthetic"} 4`,
|
||||
} {
|
||||
if !strings.Contains(response.Body.String(), expected+"\n") {
|
||||
t.Errorf("missing metric: %s", expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue