Skip to content

Commit

Permalink
more code
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed May 20, 2022
1 parent 0048ac9 commit cea79f3
Show file tree
Hide file tree
Showing 5 changed files with 1,338 additions and 6,682 deletions.
55 changes: 36 additions & 19 deletions plugins/inputs/sflow_a10/metricencoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sflow_a10

import (
"fmt"
"strconv"
"time"

"github.com/influxdata/telegraf"
Expand All @@ -23,28 +24,44 @@ func makeMetricsForCounters(p *V5Format, d *PacketDecoder) ([]telegraf.Metric, e
continue
}

// this is for 293 and 294
// as per A10, each packet of either counter block 293 or 294 is just a single sample of 293 or 294
// this is for packets tagged 293 and 294
// as per A10, each packet that contains counter block tagged 293 or 294 is just a single sample
if !sample.SampleCounterData.NeedsIpAndPort() {
for j := 0; j < len(sample.SampleCounterData.CounterRecords); j++ {
counterRecord := sample.SampleCounterData.CounterRecords[j]
if counterRecord.CounterData == nil {
d.debug(fmt.Sprintf(" nil CounterData tag is %x for sourceID %x", counterRecord.CounterFormat&4095, sample.SampleCounterData.SourceID))
continue
}
counterFields := counterRecord.CounterData.GetFields()
counterTags := map[string]string{"agent_address": p.AgentAddress.String()}
if len(counterFields) > 0 {
m, err := metric.New("sflow_a10", counterTags, counterFields, now)
if err != nil {
d.debug(fmt.Sprintf(" error sending new metric to telegraf %s", err))
return nil, err
}

d.debug(fmt.Sprintf(" sending 293 or 294 metric to telegraf %s", m))
metrics = append(metrics, m)
if len(sample.SampleCounterData.CounterRecords) != 1 {
d.Log.Error(" SampleCounterData.CounterRecords with false NeedsIpPort has length != 1")
continue
}

counterRecord := sample.SampleCounterData.CounterRecords[0]
if counterRecord.CounterData == nil {
d.debug(fmt.Sprintf(" nil CounterData tag is %x for sourceID %x", counterRecord.CounterFormat&4095, sample.SampleCounterData.SourceID))
continue
}
counterFields := counterRecord.CounterData.GetFields()
counterTags := map[string]string{"agent_address": p.AgentAddress.String()}

// hardcoded stuff for tag 294
// tag 294 contains Ethernet counters *and* interface index/speed/type
// we need to add the latter as tags
if counterRecord.IsEthernetCounters {
counterTags["ifindex"] = strconv.FormatUint(counterFields["ifindex"].(uint64), 10)
delete(counterFields, "ifindex")
delete(counterFields, "ifspeed")
delete(counterFields, "iftype")
d.debug(fmt.Sprintf(" Ethernet counters, %v, %v", counterTags, counterFields))
}

if len(counterFields) > 0 {
m, err := metric.New("sflow_a10", counterTags, counterFields, now)
if err != nil {
d.debug(fmt.Sprintf(" error sending new metric to telegraf %s", err))
return nil, err
}

d.debug(fmt.Sprintf(" sending 293 or 294 metric to telegraf %s", m))
metrics = append(metrics, m)
}

return metrics, nil
}

Expand Down
2 changes: 2 additions & 0 deletions plugins/inputs/sflow_a10/packetdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ func (d *PacketDecoder) decodeCounterRecords(r io.Reader, sourceID uint32, agent
// plus, we are not getting any IP and PORT information
cr.NeedsIpAndPort = tag != 293 && tag != 294

cr.IsEthernetCounters = tag == 294

d.debug(fmt.Sprintf(" tag %x for sourceID %x needs ip and and port: %t", tag, sourceID, cr.NeedsIpAndPort))
d.debug(fmt.Sprintf(" tag %x for sourceID %x found on xml file list. Gonna decode counter record", tag, sourceID))

Expand Down
Loading

0 comments on commit cea79f3

Please sign in to comment.