mirror of
https://github.com/ClusterCockpit/cc-metric-collector.git
synced 2025-04-08 22:45:55 +02:00
Refactor: Avoid struct deep copy
This commit is contained in:
parent
d7a3379cdc
commit
c0f59d7d90
@ -180,25 +180,27 @@ func (m *NetstatCollector) Read(interval time.Duration, output chan lp.CCMetric)
|
|||||||
|
|
||||||
// Check if device is a included device
|
// Check if device is a included device
|
||||||
if devmetrics, ok := m.matches[dev]; ok {
|
if devmetrics, ok := m.matches[dev]; ok {
|
||||||
for _, data := range devmetrics {
|
for i := range devmetrics {
|
||||||
v, err := strconv.ParseFloat(f[data.index], 64)
|
data := &devmetrics[i]
|
||||||
if err == nil {
|
|
||||||
if m.config.SendAbsoluteValues {
|
|
||||||
if y, err := lp.New(data.name, data.tags, m.meta, map[string]interface{}{"value": v}, now); err == nil {
|
|
||||||
output <- y
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if m.config.SendDerivedValues {
|
|
||||||
|
|
||||||
vdiff := v - data.lastValue
|
// Read value
|
||||||
value := vdiff / timeDiff
|
v, err := strconv.ParseFloat(f[data.index], 64)
|
||||||
if data.lastValue == 0 {
|
if err != nil {
|
||||||
value = 0
|
continue
|
||||||
}
|
}
|
||||||
data.lastValue = v
|
if m.config.SendAbsoluteValues {
|
||||||
if y, err := lp.New(data.name+"_bw", data.rate_tags, m.meta, map[string]interface{}{"value": value}, now); err == nil {
|
if y, err := lp.New(data.name, data.tags, m.meta, map[string]interface{}{"value": v}, now); err == nil {
|
||||||
output <- y
|
output <- y
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if m.config.SendDerivedValues {
|
||||||
|
rate := (v - data.lastValue) / timeDiff
|
||||||
|
if data.lastValue == 0 {
|
||||||
|
rate = 0
|
||||||
|
}
|
||||||
|
data.lastValue = v
|
||||||
|
if y, err := lp.New(data.name+"_bw", data.rate_tags, m.meta, map[string]interface{}{"value": rate}, now); err == nil {
|
||||||
|
output <- y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user