mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-12 06:24:10 +01:00
``` git ls-files \*.js \*.go \ | xargs sed -i '1i // SPDX-FileCopyrightText: 2022 Free Mobile\n// SPDX-License-Identifier: AGPL-3.0-only\n' git ls-files \*.vue \ | xargs sed -i '1i <!-- SPDX-FileCopyrightText: 2022 Free Mobile -->\n<!-- SPDX-License-Identifier: AGPL-3.0-only -->\n' ```
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package flow
|
|
|
|
import (
|
|
"time"
|
|
|
|
"akvorado/inlet/flow/decoder"
|
|
"akvorado/inlet/flow/decoder/netflow"
|
|
)
|
|
|
|
// Message describes a decoded flow message.
|
|
type Message = decoder.FlowMessage
|
|
|
|
type wrappedDecoder struct {
|
|
c *Component
|
|
orig decoder.Decoder
|
|
}
|
|
|
|
// Decode decodes a flow while keeping some stats.
|
|
func (wd *wrappedDecoder) Decode(in decoder.RawFlow) []*Message {
|
|
timeTrackStart := time.Now()
|
|
decoded := wd.orig.Decode(in)
|
|
timeTrackStop := time.Now()
|
|
|
|
if decoded == nil {
|
|
wd.c.metrics.decoderErrors.WithLabelValues(wd.orig.Name()).
|
|
Inc()
|
|
return nil
|
|
}
|
|
wd.c.metrics.decoderTime.WithLabelValues(wd.orig.Name()).
|
|
Observe(float64((timeTrackStop.Sub(timeTrackStart)).Nanoseconds()) / 1000 / 1000 / 1000)
|
|
wd.c.metrics.decoderStats.WithLabelValues(wd.orig.Name()).
|
|
Inc()
|
|
return decoded
|
|
}
|
|
|
|
// Name returns the name of the original decoder.
|
|
func (wd *wrappedDecoder) Name() string {
|
|
return wd.orig.Name()
|
|
}
|
|
|
|
// wrapDecoder wraps the provided decoders to get statistics from it.
|
|
func (c *Component) wrapDecoder(d decoder.Decoder) decoder.Decoder {
|
|
return &wrappedDecoder{
|
|
c: c,
|
|
orig: d,
|
|
}
|
|
}
|
|
|
|
var decoders = map[string]decoder.NewDecoderFunc{
|
|
"netflow": netflow.New,
|
|
}
|