Skip to content

Commit

Permalink
adding IgnoreZeroValues config
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed May 31, 2022
1 parent cea79f3 commit 1570cf4
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 29 deletions.
31 changes: 9 additions & 22 deletions plugins/inputs/sflow_a10/packetdecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@ 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
}

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,
}
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/inputs/sflow_a10/packetdecoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{
Expand All @@ -100,6 +100,7 @@ func TestDecodeCounterSample(t *testing.T) {
"testCounter2": uint64(29),
},
},
NeedsIpAndPort: true,
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions plugins/inputs/sflow_a10/sflow_3_2_t2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3003,32 +3003,32 @@
<ctr:ctrBlkSz>6</ctr:ctrBlkSz>
<ctr:counter>
<ctr:offset>0</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>bw_limit_drop</ctr:fieldName>
</ctr:counter>
<ctr:counter>
<ctr:offset>1</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>bw_limit_ignored</ctr:fieldName>
</ctr:counter>
<ctr:counter>
<ctr:offset>2</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>egr_pps_limit_drop</ctr:fieldName>
</ctr:counter>
<ctr:counter>
<ctr:offset>3</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>ing_pps_limit_drop</ctr:fieldName>
</ctr:counter>
<ctr:counter>
<ctr:offset>4</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>pps_limit_ignored</ctr:fieldName>
</ctr:counter>
<ctr:counter>
<ctr:offset>5</ctr:offset>
<ctr:dtype>u64</ctr:dtype>
<ctr:dtype>u32</ctr:dtype>
<ctr:fieldName>license_expire_drop</ctr:fieldName>
</ctr:counter>
</ctr:counterBlock>
Expand Down
6 changes: 6 additions & 0 deletions plugins/inputs/sflow_a10/sflow_a10.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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

Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 1570cf4

Please sign in to comment.