* Removed unused code
* Use cclog for logging
* Wrap errors so that they can be unwrapped
* Revert wrong use of slices.Delete()
* Fix derivative values should be float
* Suggestions from the gocritic linter
* Fixed: interface method AddChannel must have all named params (inamedparam)
* Enable linter: errorlint
* Replace fmt.Sprintf("%d", i)) by strconv.Itoa(i) for improved performance
* Correct misspelled words
* Break up very long lines into multiple lines
* lp.NewMessage -> lp.NewMetric
* Preallocate slices of known length
This commit is contained in:
Holger Obermaier
2026-02-13 09:36:14 +01:00
committed by GitHub
parent b69281dae6
commit 9908d76aac
29 changed files with 311 additions and 395 deletions

View File

@@ -10,7 +10,6 @@ package collectors
import (
"encoding/json"
"fmt"
"log"
"slices"
// "os"
@@ -49,7 +48,7 @@ func (m *nfsCollector) initStats() error {
// Wait for cmd end
if err := cmd.Wait(); err != nil {
return fmt.Errorf("initStats(): %w", err)
return fmt.Errorf("%s initStats(): %w", m.name, err)
}
buffer, err := cmd.Output()
@@ -81,7 +80,7 @@ func (m *nfsCollector) updateStats() error {
// Wait for cmd end
if err := cmd.Wait(); err != nil {
return fmt.Errorf("updateStats(): %w", err)
return fmt.Errorf("%s updateStats(): %w", m.name, err)
}
buffer, err := cmd.Output()
@@ -114,8 +113,7 @@ func (m *nfsCollector) MainInit(config json.RawMessage) error {
if len(config) > 0 {
err := json.Unmarshal(config, &m.config)
if err != nil {
log.Print(err.Error())
return err
return fmt.Errorf("%s Init(): failed to unmarshal JSON config: %w", m.name, err)
}
}
m.meta = map[string]string{
@@ -128,11 +126,11 @@ func (m *nfsCollector) MainInit(config json.RawMessage) error {
// Check if nfsstat is in executable search path
_, err := exec.LookPath(m.config.Nfsstats)
if err != nil {
return fmt.Errorf("NfsCollector.Init(): Failed to find nfsstat binary '%s': %v", m.config.Nfsstats, err)
return fmt.Errorf("%s Init(): Failed to find nfsstat binary '%s': %w", m.name, m.config.Nfsstats, err)
}
m.data = make(map[string]NfsCollectorData)
if err := m.initStats(); err != nil {
return fmt.Errorf("NfsCollector.Init(): %w", err)
return fmt.Errorf("%s Init(): %w", m.name, err)
}
m.init = true
m.parallel = true
@@ -152,7 +150,7 @@ func (m *nfsCollector) Read(interval time.Duration, output chan lp.CCMessage) {
)
return
}
prefix := ""
var prefix string
switch m.version {
case "v3":
prefix = "nfs3"