diff --git a/plugins/inputs/sflow_a10/packetdecoder.go b/plugins/inputs/sflow_a10/packetdecoder.go
index f498d1acb99b4..2ea0b196f841d 100644
--- a/plugins/inputs/sflow_a10/packetdecoder.go
+++ b/plugins/inputs/sflow_a10/packetdecoder.go
@@ -13,9 +13,10 @@ import (
)
type PacketDecoder struct {
- onPacket func(p *V5Format)
- Log telegraf.Logger
- CounterBlocks map[uint32]CounterBlock
+ onPacket func(p *V5Format)
+ Log telegraf.Logger
+ CounterBlocks map[uint32]CounterBlock
+ IgnoreZeroValues bool
IPMap *hm.HashMap
PortMap *hm.HashMap
@@ -23,9 +24,10 @@ type PacketDecoder struct {
func NewDecoder() *PacketDecoder {
return &PacketDecoder{
- IPMap: &hm.HashMap{},
- PortMap: &hm.HashMap{},
- CounterBlocks: make(map[uint32]CounterBlock),
+ IPMap: &hm.HashMap{},
+ PortMap: &hm.HashMap{},
+ CounterBlocks: make(map[uint32]CounterBlock),
+ IgnoreZeroValues: true,
}
}
@@ -197,11 +199,6 @@ func (d *PacketDecoder) decodeCounterRecords(r io.Reader, sourceID uint32, agent
d.PortMap.Set(key, portDimensions)
}
- // d.debug(fmt.Sprintf(" got 260 - before assigning portdimensions for sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
- // if val.PortDimensions == nil {
- // val.PortDimensions = portDimensions
- // }
- // d.debug(fmt.Sprintf(" got 260 - assigning portdimensions for sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
continue
} else if tag == 271 { // hex 10F - contains IPv4 information
ipDimensions, err := d.decode271(r)
@@ -215,11 +212,6 @@ func (d *PacketDecoder) decodeCounterRecords(r io.Reader, sourceID uint32, agent
d.IPMap.Set(key, ipDimensions)
}
- // d.debug(fmt.Sprintf(" got 271 - before assigning ipdimensions for sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
- // if val.IPDimensions == nil {
- // val.IPDimensions = ipDimensions // TODO: append in a set instead of overwriting
- // }
- // d.debug(fmt.Sprintf(" got 271 - assigning ipdimensions for sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
continue
} else if tag == 272 { // hex 110 - contains IPv6 information
ipDimensions, err := d.decode272(r)
@@ -233,11 +225,6 @@ func (d *PacketDecoder) decodeCounterRecords(r io.Reader, sourceID uint32, agent
d.IPMap.Set(key, ipDimensions)
}
- // d.debug(fmt.Sprintf(" got 272 - before assigning portdimensions for sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
- // if val.IPDimensions == nil {
- // val.IPDimensions = ipDimensions
- // }
- // d.debug(fmt.Sprintf(" got 272 - assigning portdimensions fo2r sourceID %x and agentAddress %v, now it's %v", sourceID, agentAddress, val))
continue
}
@@ -314,7 +301,7 @@ func (d *PacketDecoder) decodeCounterRecord(r io.Reader, cr *CounterRecord, tag
continue
}
- if counterValue != uint64(0) { // no point in returning 0 value for metric
+ if counterValue != uint64(0) || (counterValue == uint64(0) && !d.IgnoreZeroValues) {
//d.debug(fmt.Sprintf(" getting non-zero counter %s with value hex %x %#v %T for sourceID %x", counter.FieldName, counterValue, counterValue, counterValue, sourceID))
cr.CounterData.CounterFields[counter.FieldName] = counterValue
}
diff --git a/plugins/inputs/sflow_a10/packetdecoder_test.go b/plugins/inputs/sflow_a10/packetdecoder_test.go
index e1eaad57663e9..52f07f9ade864 100644
--- a/plugins/inputs/sflow_a10/packetdecoder_test.go
+++ b/plugins/inputs/sflow_a10/packetdecoder_test.go
@@ -91,7 +91,7 @@ func TestDecodeCounterSample(t *testing.T) {
SequenceNumber: uint32(5),
SourceID: uint32(278808),
CounterRecords: []CounterRecord{
- CounterRecord{
+ {
CounterFormat: CounterFormatType(217),
CounterData: &CounterData{
CounterFields: map[string]interface{}{
@@ -100,6 +100,7 @@ func TestDecodeCounterSample(t *testing.T) {
"testCounter2": uint64(29),
},
},
+ NeedsIpAndPort: true,
},
},
},
diff --git a/plugins/inputs/sflow_a10/sflow_3_2_t2.xml b/plugins/inputs/sflow_a10/sflow_3_2_t2.xml
index 2269959f38bc5..8c43a4d790f49 100644
--- a/plugins/inputs/sflow_a10/sflow_3_2_t2.xml
+++ b/plugins/inputs/sflow_a10/sflow_3_2_t2.xml
@@ -3003,32 +3003,32 @@
6
0
- u64
+ u32
bw_limit_drop
1
- u64
+ u32
bw_limit_ignored
2
- u64
+ u32
egr_pps_limit_drop
3
- u64
+ u32
ing_pps_limit_drop
4
- u64
+ u32
pps_limit_ignored
5
- u64
+ u32
license_expire_drop
diff --git a/plugins/inputs/sflow_a10/sflow_a10.go b/plugins/inputs/sflow_a10/sflow_a10.go
index cb57cb26ff55e..e6f818a5d28df 100644
--- a/plugins/inputs/sflow_a10/sflow_a10.go
+++ b/plugins/inputs/sflow_a10/sflow_a10.go
@@ -31,6 +31,10 @@ const sampleConfig = `
# XML file containing counter definitions, according to A10 specification
a10_definitions_file = "/path/to/xml_file.xml"
+
+ # if true, metrics with zero values will not be sent to the output
+ # this is to lighten the load on the metrics database backend
+ ignore_zero_values = true
`
const (
@@ -45,6 +49,7 @@ type SFlow_A10 struct {
ServiceAddress string `toml:"service_address"`
ReadBufferSize internal.Size `toml:"read_buffer_size"`
A10DefinitionsFile string `toml:"a10_definitions_file"`
+ IgnoreZeroValues bool `toml:"ignore_zero_values"`
sync.Mutex
@@ -115,6 +120,7 @@ func (s *SFlow_A10) initInternal(xmlData []byte) error {
return err
}
s.decoder.CounterBlocks = counterBlocks
+ s.decoder.IgnoreZeroValues = s.IgnoreZeroValues
return nil
}