Avoid vet warning struct field commands has json tag but is not exported

This commit is contained in:
Holger Obermaier 2022-01-25 11:12:06 +01:00
parent 2de0ab8c45
commit e7e51aa4fa
4 changed files with 19 additions and 18 deletions

View File

@ -16,8 +16,8 @@ import (
const CUSTOMCMDPATH = `/home/unrz139/Work/cc-metric-collector/collectors/custom`
type CustomCmdCollectorConfig struct {
commands []string `json:"commands"`
files []string `json:"files"`
Commands []string `json:"commands"`
Files []string `json:"files"`
ExcludeMetrics []string `json:"exclude_metrics"`
}
@ -42,7 +42,7 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
}
}
m.setup()
for _, c := range m.config.commands {
for _, c := range m.config.Commands {
cmdfields := strings.Fields(c)
command := exec.Command(cmdfields[0], strings.Join(cmdfields[1:], " "))
command.Wait()
@ -51,7 +51,7 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
m.commands = append(m.commands, c)
}
}
for _, f := range m.config.files {
for _, f := range m.config.Files {
_, err = ioutil.ReadFile(f)
if err == nil {
m.files = append(m.files, f)

View File

@ -15,7 +15,7 @@ import (
const LUSTREFILE = `/proc/fs/lustre/llite/lnec-XXXXXX/stats`
type LustreCollectorConfig struct {
procfiles []string `json:"procfiles"`
Procfiles []string `json:"procfiles"`
ExcludeMetrics []string `json:"exclude_metrics"`
}
@ -48,7 +48,7 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
"statfs": {"statfs": 1},
"inode_permission": {"inode_permission": 1}}
m.devices = make([]string, 0)
for _, p := range m.config.procfiles {
for _, p := range m.config.Procfiles {
_, err := ioutil.ReadFile(p)
if err == nil {
m.devices = append(m.devices, p)

View File

@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"log"
// "os"
"os/exec"
"strconv"
@ -22,14 +23,14 @@ type NfsCollector struct {
metricCollector
tags map[string]string
config struct {
nfsutils string `json:"nfsutils"`
excludeMetrics []string `json:"exclude_metrics,omitempty"`
Nfsutils string `json:"nfsutils"`
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
}
data map[string]map[string]NfsCollectorData
}
func (m *NfsCollector) initStats() error {
cmd := exec.Command(m.config.nfsutils, "-l")
cmd := exec.Command(m.config.Nfsutils, "-l")
cmd.Wait()
buffer, err := cmd.Output()
if err == nil {
@ -57,7 +58,7 @@ func (m *NfsCollector) initStats() error {
}
func (m *NfsCollector) updateStats() error {
cmd := exec.Command(m.config.nfsutils, "-l")
cmd := exec.Command(m.config.Nfsutils, "-l")
cmd.Wait()
buffer, err := cmd.Output()
if err == nil {
@ -90,7 +91,7 @@ func (m *NfsCollector) Init(config json.RawMessage) error {
m.setup()
// Set default mmpmon binary
m.config.nfsutils = "/usr/sbin/nfsstat"
m.config.Nfsutils = "/usr/sbin/nfsstat"
// Read JSON configuration
if len(config) > 0 {
@ -108,9 +109,9 @@ func (m *NfsCollector) Init(config json.RawMessage) error {
"type": "node",
}
// Check if mmpmon is in executable search path
_, err = exec.LookPath(m.config.nfsutils)
_, err = exec.LookPath(m.config.Nfsutils)
if err != nil {
return fmt.Errorf("NfsCollector.Init(): Failed to find nfsstat binary '%s': %v", m.config.nfsutils, err)
return fmt.Errorf("NfsCollector.Init(): Failed to find nfsstat binary '%s': %v", m.config.Nfsutils, err)
}
m.data = make(map[string]map[string]NfsCollectorData)
m.initStats()
@ -128,7 +129,7 @@ func (m *NfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
for version, metrics := range m.data {
for name, data := range metrics {
if _, skip := stringArrayContains(m.config.excludeMetrics, name); skip {
if _, skip := stringArrayContains(m.config.ExcludeMetrics, name); skip {
continue
}
value := data.current - data.last

View File

@ -16,7 +16,7 @@ const MAX_NUM_PROCS = 10
const DEFAULT_NUM_PROCS = 2
type TopProcsCollectorConfig struct {
num_procs int `json:"num_procs"`
Num_procs int `json:"num_procs"`
}
type TopProcsCollector struct {
@ -36,9 +36,9 @@ func (m *TopProcsCollector) Init(config json.RawMessage) error {
return err
}
} else {
m.config.num_procs = int(DEFAULT_NUM_PROCS)
m.config.Num_procs = int(DEFAULT_NUM_PROCS)
}
if m.config.num_procs <= 0 || m.config.num_procs > MAX_NUM_PROCS {
if m.config.Num_procs <= 0 || m.config.Num_procs > MAX_NUM_PROCS {
return errors.New(fmt.Sprintf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS))
}
m.setup()
@ -65,7 +65,7 @@ func (m *TopProcsCollector) Read(interval time.Duration, output chan lp.CCMetric
}
lines := strings.Split(string(stdout), "\n")
for i := 1; i < m.config.num_procs+1; i++ {
for i := 1; i < m.config.Num_procs+1; i++ {
name := fmt.Sprintf("topproc%d", i)
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": string(lines[i])}, time.Now())
if err == nil {