Add gauges for allocated memory for queued UDP and TCP packages (#1503)

* Two new states will be added to the tcpstat collector called rx_queued_bytes and tx_queued_bytes.

For UDP datagrams an additional collector 'udp_queues' can be used to expose the total lengths of the tx_queue and rx_queue.
@SuperQ and @discordianfish this changes gives us the option to check for overloaded UDP + TCP processing.
The names of the new TCP states and the UDP metric can be discussed.
The current reasons are just:

I don't want to add another collector for the same exposed file, so I just added the new states to the tcpstat collector.
I chose the name 'udp_queue' instead of 'udpstat' as UDP has no state.


Signed-off-by: Peter Bueschel <peter.bueschel@logmein.com>
This commit is contained in:
Peter Bueschel 2020-03-31 10:46:32 +02:00 committed by GitHub
commit da5972b539
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 189 additions and 4 deletions

View file

@ -52,6 +52,10 @@ const (
tcpListen
// TCP_CLOSING
tcpClosing
// TCP_RX_BUFFER
tcpRxQueuedBytes
// TCP_TX_BUFFER
tcpTxQueuedBytes
)
type tcpStatCollector struct {
@ -122,16 +126,34 @@ func parseTCPStats(r io.Reader) (map[tcpConnectionState]float64, error) {
if len(parts) == 0 {
continue
}
if len(parts) < 4 {
if len(parts) < 5 {
return nil, fmt.Errorf("invalid TCP stats line: %q", line)
}
qu := strings.Split(parts[4], ":")
if len(qu) < 2 {
return nil, fmt.Errorf("cannot parse tx_queues and rx_queues: %q", line)
}
tx, err := strconv.ParseUint(qu[0], 16, 64)
if err != nil {
return nil, err
}
tcpStats[tcpConnectionState(tcpTxQueuedBytes)] += float64(tx)
rx, err := strconv.ParseUint(qu[1], 16, 64)
if err != nil {
return nil, err
}
tcpStats[tcpConnectionState(tcpRxQueuedBytes)] += float64(rx)
st, err := strconv.ParseInt(parts[3], 16, 8)
if err != nil {
return nil, err
}
tcpStats[tcpConnectionState(st)]++
}
return tcpStats, nil
@ -161,6 +183,10 @@ func (st tcpConnectionState) String() string {
return "listen"
case tcpClosing:
return "closing"
case tcpRxQueuedBytes:
return "rx_queued_bytes"
case tcpTxQueuedBytes:
return "tx_queued_bytes"
default:
return "unknown"
}