mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-08 22:45:55 +02:00
Set default config values
This commit is contained in:
parent
8d1bac14f6
commit
06a878bb4c
@ -72,6 +72,11 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m.matches = make(map[string]map[string]NetstatCollectorMetric)
|
m.matches = make(map[string]map[string]NetstatCollectorMetric)
|
||||||
|
|
||||||
|
// Set default configuration,
|
||||||
|
m.config.SendAbsoluteValues = true
|
||||||
|
m.config.SendDerivedValues = false
|
||||||
|
// Read configuration file, allow overwriting default config
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
err := json.Unmarshal(config, &m.config)
|
err := json.Unmarshal(config, &m.config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -79,6 +84,8 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check access to net statistic file
|
||||||
file, err := os.Open(NETSTATFILE)
|
file, err := os.Open(NETSTATFILE)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, err.Error())
|
cclog.ComponentError(m.name, err.Error())
|
||||||
@ -89,11 +96,19 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
scanner := bufio.NewScanner(file)
|
scanner := bufio.NewScanner(file)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
l := scanner.Text()
|
l := scanner.Text()
|
||||||
|
|
||||||
|
// Skip lines with no net device entry
|
||||||
if !strings.Contains(l, ":") {
|
if !strings.Contains(l, ":") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Split line into fields
|
||||||
f := strings.Fields(l)
|
f := strings.Fields(l)
|
||||||
|
|
||||||
|
// Get net device entry
|
||||||
dev := strings.Trim(f[0], ": ")
|
dev := strings.Trim(f[0], ": ")
|
||||||
|
|
||||||
|
// Check if device is a included device
|
||||||
if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok {
|
if _, ok := stringArrayContains(m.config.IncludeDevices, dev); ok {
|
||||||
m.matches[dev] = make(map[string]NetstatCollectorMetric)
|
m.matches[dev] = make(map[string]NetstatCollectorMetric)
|
||||||
for name, idx := range nameIndexMap {
|
for name, idx := range nameIndexMap {
|
||||||
@ -102,7 +117,10 @@ func (m *NetstatCollector) Init(config json.RawMessage) error {
|
|||||||
lastValue: 0,
|
lastValue: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.devtags[dev] = map[string]string{"device": dev, "type": "node"}
|
m.devtags[dev] = map[string]string{
|
||||||
|
"device": dev,
|
||||||
|
"type": "node",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(m.devtags) == 0 {
|
if len(m.devtags) == 0 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user