mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-17 10:25:56 +02:00
Add comments
This commit is contained in:
parent
06a878bb4c
commit
737f2dbe9a
@ -134,24 +134,36 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if !m.init {
|
if !m.init {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Current time stamp
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
// time difference to last time stamp
|
||||||
|
timeDiff := now.Sub(m.lastTimestamp).Seconds()
|
||||||
|
// Save current timestamp
|
||||||
|
m.lastTimestamp = now
|
||||||
|
|
||||||
file, err := os.Open(string(NETSTATFILE))
|
file, err := os.Open(string(NETSTATFILE))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cclog.ComponentError(m.name, err.Error())
|
cclog.ComponentError(m.name, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
tdiff := now.Sub(m.lastTimestamp)
|
|
||||||
|
|
||||||
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 devmetrics, ok := m.matches[dev]; ok {
|
if devmetrics, ok := m.matches[dev]; ok {
|
||||||
for name, data := range devmetrics {
|
for name, data := range devmetrics {
|
||||||
v, err := strconv.ParseFloat(f[data.index], 64)
|
v, err := strconv.ParseFloat(f[data.index], 64)
|
||||||
@ -170,7 +182,7 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
if m.config.SendDerivedValues {
|
if m.config.SendDerivedValues {
|
||||||
|
|
||||||
vdiff := v - data.lastValue
|
vdiff := v - data.lastValue
|
||||||
value := vdiff / tdiff.Seconds()
|
value := vdiff / timeDiff
|
||||||
if data.lastValue == 0 {
|
if data.lastValue == 0 {
|
||||||
value = 0
|
value = 0
|
||||||
}
|
}
|
||||||
@ -190,7 +202,6 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m.lastTimestamp = time.Now()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *NetstatCollector) Close() {
|
func (m *NetstatCollector) Close() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user