mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-08 14:35:55 +02:00
Avoid vet warning struct field commands has json tag but is not exported
This commit is contained in:
parent
2de0ab8c45
commit
e7e51aa4fa
@ -16,8 +16,8 @@ import (
|
|||||||
const CUSTOMCMDPATH = `/home/unrz139/Work/cc-metric-collector/collectors/custom`
|
const CUSTOMCMDPATH = `/home/unrz139/Work/cc-metric-collector/collectors/custom`
|
||||||
|
|
||||||
type CustomCmdCollectorConfig struct {
|
type CustomCmdCollectorConfig struct {
|
||||||
commands []string `json:"commands"`
|
Commands []string `json:"commands"`
|
||||||
files []string `json:"files"`
|
Files []string `json:"files"`
|
||||||
ExcludeMetrics []string `json:"exclude_metrics"`
|
ExcludeMetrics []string `json:"exclude_metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.setup()
|
m.setup()
|
||||||
for _, c := range m.config.commands {
|
for _, c := range m.config.Commands {
|
||||||
cmdfields := strings.Fields(c)
|
cmdfields := strings.Fields(c)
|
||||||
command := exec.Command(cmdfields[0], strings.Join(cmdfields[1:], " "))
|
command := exec.Command(cmdfields[0], strings.Join(cmdfields[1:], " "))
|
||||||
command.Wait()
|
command.Wait()
|
||||||
@ -51,7 +51,7 @@ func (m *CustomCmdCollector) Init(config json.RawMessage) error {
|
|||||||
m.commands = append(m.commands, c)
|
m.commands = append(m.commands, c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, f := range m.config.files {
|
for _, f := range m.config.Files {
|
||||||
_, err = ioutil.ReadFile(f)
|
_, err = ioutil.ReadFile(f)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.files = append(m.files, f)
|
m.files = append(m.files, f)
|
||||||
|
@ -15,7 +15,7 @@ import (
|
|||||||
const LUSTREFILE = `/proc/fs/lustre/llite/lnec-XXXXXX/stats`
|
const LUSTREFILE = `/proc/fs/lustre/llite/lnec-XXXXXX/stats`
|
||||||
|
|
||||||
type LustreCollectorConfig struct {
|
type LustreCollectorConfig struct {
|
||||||
procfiles []string `json:"procfiles"`
|
Procfiles []string `json:"procfiles"`
|
||||||
ExcludeMetrics []string `json:"exclude_metrics"`
|
ExcludeMetrics []string `json:"exclude_metrics"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ func (m *LustreCollector) Init(config json.RawMessage) error {
|
|||||||
"statfs": {"statfs": 1},
|
"statfs": {"statfs": 1},
|
||||||
"inode_permission": {"inode_permission": 1}}
|
"inode_permission": {"inode_permission": 1}}
|
||||||
m.devices = make([]string, 0)
|
m.devices = make([]string, 0)
|
||||||
for _, p := range m.config.procfiles {
|
for _, p := range m.config.Procfiles {
|
||||||
_, err := ioutil.ReadFile(p)
|
_, err := ioutil.ReadFile(p)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m.devices = append(m.devices, p)
|
m.devices = append(m.devices, p)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
// "os"
|
// "os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -22,14 +23,14 @@ type NfsCollector struct {
|
|||||||
metricCollector
|
metricCollector
|
||||||
tags map[string]string
|
tags map[string]string
|
||||||
config struct {
|
config struct {
|
||||||
nfsutils string `json:"nfsutils"`
|
Nfsutils string `json:"nfsutils"`
|
||||||
excludeMetrics []string `json:"exclude_metrics,omitempty"`
|
ExcludeMetrics []string `json:"exclude_metrics,omitempty"`
|
||||||
}
|
}
|
||||||
data map[string]map[string]NfsCollectorData
|
data map[string]map[string]NfsCollectorData
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NfsCollector) initStats() error {
|
func (m *NfsCollector) initStats() error {
|
||||||
cmd := exec.Command(m.config.nfsutils, "-l")
|
cmd := exec.Command(m.config.Nfsutils, "-l")
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
buffer, err := cmd.Output()
|
buffer, err := cmd.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -57,7 +58,7 @@ func (m *NfsCollector) initStats() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *NfsCollector) updateStats() error {
|
func (m *NfsCollector) updateStats() error {
|
||||||
cmd := exec.Command(m.config.nfsutils, "-l")
|
cmd := exec.Command(m.config.Nfsutils, "-l")
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
buffer, err := cmd.Output()
|
buffer, err := cmd.Output()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -90,7 +91,7 @@ func (m *NfsCollector) Init(config json.RawMessage) error {
|
|||||||
m.setup()
|
m.setup()
|
||||||
|
|
||||||
// Set default mmpmon binary
|
// Set default mmpmon binary
|
||||||
m.config.nfsutils = "/usr/sbin/nfsstat"
|
m.config.Nfsutils = "/usr/sbin/nfsstat"
|
||||||
|
|
||||||
// Read JSON configuration
|
// Read JSON configuration
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
@ -108,9 +109,9 @@ func (m *NfsCollector) Init(config json.RawMessage) error {
|
|||||||
"type": "node",
|
"type": "node",
|
||||||
}
|
}
|
||||||
// Check if mmpmon is in executable search path
|
// Check if mmpmon is in executable search path
|
||||||
_, err = exec.LookPath(m.config.nfsutils)
|
_, err = exec.LookPath(m.config.Nfsutils)
|
||||||
if err != nil {
|
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.data = make(map[string]map[string]NfsCollectorData)
|
||||||
m.initStats()
|
m.initStats()
|
||||||
@ -128,7 +129,7 @@ func (m *NfsCollector) Read(interval time.Duration, output chan lp.CCMetric) {
|
|||||||
|
|
||||||
for version, metrics := range m.data {
|
for version, metrics := range m.data {
|
||||||
for name, data := range metrics {
|
for name, data := range metrics {
|
||||||
if _, skip := stringArrayContains(m.config.excludeMetrics, name); skip {
|
if _, skip := stringArrayContains(m.config.ExcludeMetrics, name); skip {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
value := data.current - data.last
|
value := data.current - data.last
|
||||||
|
@ -16,7 +16,7 @@ const MAX_NUM_PROCS = 10
|
|||||||
const DEFAULT_NUM_PROCS = 2
|
const DEFAULT_NUM_PROCS = 2
|
||||||
|
|
||||||
type TopProcsCollectorConfig struct {
|
type TopProcsCollectorConfig struct {
|
||||||
num_procs int `json:"num_procs"`
|
Num_procs int `json:"num_procs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TopProcsCollector struct {
|
type TopProcsCollector struct {
|
||||||
@ -36,9 +36,9 @@ func (m *TopProcsCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} 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))
|
return errors.New(fmt.Sprintf("num_procs option must be set in 'topprocs' config (range: 1-%d)", MAX_NUM_PROCS))
|
||||||
}
|
}
|
||||||
m.setup()
|
m.setup()
|
||||||
@ -65,7 +65,7 @@ func (m *TopProcsCollector) Read(interval time.Duration, output chan lp.CCMetric
|
|||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(string(stdout), "\n")
|
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)
|
name := fmt.Sprintf("topproc%d", i)
|
||||||
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": string(lines[i])}, time.Now())
|
y, err := lp.New(name, m.tags, m.meta, map[string]interface{}{"value": string(lines[i])}, time.Now())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user