VictoriaMetrics/vendor/github.com/prometheus/procfs/proc_snmp6.go

382 lines
11 KiB
Go
Raw Normal View History

2022-08-02 06:19:38 +00:00
// Copyright 2022 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package procfs
import (
"bufio"
"bytes"
"errors"
"io"
"os"
"strconv"
"strings"
"github.com/prometheus/procfs/internal/util"
)
// ProcSnmp6 models the content of /proc/<pid>/net/snmp6.
type ProcSnmp6 struct {
// The process ID.
PID int
Ip6
Icmp6
Udp6
UdpLite6
}
type Ip6 struct { // nolint:revive
2022-12-28 23:00:02 +00:00
InReceives *float64
InHdrErrors *float64
InTooBigErrors *float64
InNoRoutes *float64
InAddrErrors *float64
InUnknownProtos *float64
InTruncatedPkts *float64
InDiscards *float64
InDelivers *float64
OutForwDatagrams *float64
OutRequests *float64
OutDiscards *float64
OutNoRoutes *float64
ReasmTimeout *float64
ReasmReqds *float64
ReasmOKs *float64
ReasmFails *float64
FragOKs *float64
FragFails *float64
FragCreates *float64
InMcastPkts *float64
OutMcastPkts *float64
InOctets *float64
OutOctets *float64
InMcastOctets *float64
OutMcastOctets *float64
InBcastOctets *float64
OutBcastOctets *float64
InNoECTPkts *float64
InECT1Pkts *float64
InECT0Pkts *float64
InCEPkts *float64
2022-08-02 06:19:38 +00:00
}
type Icmp6 struct {
2022-12-28 23:00:02 +00:00
InMsgs *float64
InErrors *float64
OutMsgs *float64
OutErrors *float64
InCsumErrors *float64
InDestUnreachs *float64
InPktTooBigs *float64
InTimeExcds *float64
InParmProblems *float64
InEchos *float64
InEchoReplies *float64
InGroupMembQueries *float64
InGroupMembResponses *float64
InGroupMembReductions *float64
InRouterSolicits *float64
InRouterAdvertisements *float64
InNeighborSolicits *float64
InNeighborAdvertisements *float64
InRedirects *float64
InMLDv2Reports *float64
OutDestUnreachs *float64
OutPktTooBigs *float64
OutTimeExcds *float64
OutParmProblems *float64
OutEchos *float64
OutEchoReplies *float64
OutGroupMembQueries *float64
OutGroupMembResponses *float64
OutGroupMembReductions *float64
OutRouterSolicits *float64
OutRouterAdvertisements *float64
OutNeighborSolicits *float64
OutNeighborAdvertisements *float64
OutRedirects *float64
OutMLDv2Reports *float64
InType1 *float64
InType134 *float64
InType135 *float64
InType136 *float64
InType143 *float64
OutType133 *float64
OutType135 *float64
OutType136 *float64
OutType143 *float64
2022-08-02 06:19:38 +00:00
}
type Udp6 struct { // nolint:revive
2022-12-28 23:00:02 +00:00
InDatagrams *float64
NoPorts *float64
InErrors *float64
OutDatagrams *float64
RcvbufErrors *float64
SndbufErrors *float64
InCsumErrors *float64
IgnoredMulti *float64
2022-08-02 06:19:38 +00:00
}
type UdpLite6 struct { // nolint:revive
2022-12-28 23:00:02 +00:00
InDatagrams *float64
NoPorts *float64
InErrors *float64
OutDatagrams *float64
RcvbufErrors *float64
SndbufErrors *float64
InCsumErrors *float64
2022-08-02 06:19:38 +00:00
}
func (p Proc) Snmp6() (ProcSnmp6, error) {
filename := p.path("net/snmp6")
data, err := util.ReadFileNoStat(filename)
if err != nil {
// On systems with IPv6 disabled, this file won't exist.
// Do nothing.
if errors.Is(err, os.ErrNotExist) {
return ProcSnmp6{PID: p.PID}, nil
}
return ProcSnmp6{PID: p.PID}, err
}
procSnmp6, err := parseSNMP6Stats(bytes.NewReader(data))
procSnmp6.PID = p.PID
return procSnmp6, err
}
// parseSnmp6 parses the metrics from proc/<pid>/net/snmp6 file
// and returns a map contains those metrics.
func parseSNMP6Stats(r io.Reader) (ProcSnmp6, error) {
var (
scanner = bufio.NewScanner(r)
procSnmp6 = ProcSnmp6{}
)
for scanner.Scan() {
stat := strings.Fields(scanner.Text())
if len(stat) < 2 {
continue
}
// Expect to have "6" in metric name, skip line otherwise
if sixIndex := strings.Index(stat[0], "6"); sixIndex != -1 {
protocol := stat[0][:sixIndex+1]
key := stat[0][sixIndex+1:]
value, err := strconv.ParseFloat(stat[1], 64)
if err != nil {
return procSnmp6, err
}
switch protocol {
case "Ip6":
switch key {
case "InReceives":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InReceives = &value
2022-08-02 06:19:38 +00:00
case "InHdrErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InHdrErrors = &value
2022-08-02 06:19:38 +00:00
case "InTooBigErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InTooBigErrors = &value
2022-08-02 06:19:38 +00:00
case "InNoRoutes":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InNoRoutes = &value
2022-08-02 06:19:38 +00:00
case "InAddrErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InAddrErrors = &value
2022-08-02 06:19:38 +00:00
case "InUnknownProtos":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InUnknownProtos = &value
2022-08-02 06:19:38 +00:00
case "InTruncatedPkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InTruncatedPkts = &value
2022-08-02 06:19:38 +00:00
case "InDiscards":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InDiscards = &value
2022-08-02 06:19:38 +00:00
case "InDelivers":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InDelivers = &value
2022-08-02 06:19:38 +00:00
case "OutForwDatagrams":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutForwDatagrams = &value
2022-08-02 06:19:38 +00:00
case "OutRequests":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutRequests = &value
2022-08-02 06:19:38 +00:00
case "OutDiscards":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutDiscards = &value
2022-08-02 06:19:38 +00:00
case "OutNoRoutes":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutNoRoutes = &value
2022-08-02 06:19:38 +00:00
case "ReasmTimeout":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.ReasmTimeout = &value
2022-08-02 06:19:38 +00:00
case "ReasmReqds":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.ReasmReqds = &value
2022-08-02 06:19:38 +00:00
case "ReasmOKs":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.ReasmOKs = &value
2022-08-02 06:19:38 +00:00
case "ReasmFails":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.ReasmFails = &value
2022-08-02 06:19:38 +00:00
case "FragOKs":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.FragOKs = &value
2022-08-02 06:19:38 +00:00
case "FragFails":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.FragFails = &value
2022-08-02 06:19:38 +00:00
case "FragCreates":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.FragCreates = &value
2022-08-02 06:19:38 +00:00
case "InMcastPkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InMcastPkts = &value
2022-08-02 06:19:38 +00:00
case "OutMcastPkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutMcastPkts = &value
2022-08-02 06:19:38 +00:00
case "InOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InOctets = &value
2022-08-02 06:19:38 +00:00
case "OutOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutOctets = &value
2022-08-02 06:19:38 +00:00
case "InMcastOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InMcastOctets = &value
2022-08-02 06:19:38 +00:00
case "OutMcastOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutMcastOctets = &value
2022-08-02 06:19:38 +00:00
case "InBcastOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InBcastOctets = &value
2022-08-02 06:19:38 +00:00
case "OutBcastOctets":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.OutBcastOctets = &value
2022-08-02 06:19:38 +00:00
case "InNoECTPkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InNoECTPkts = &value
2022-08-02 06:19:38 +00:00
case "InECT1Pkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InECT1Pkts = &value
2022-08-02 06:19:38 +00:00
case "InECT0Pkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InECT0Pkts = &value
2022-08-02 06:19:38 +00:00
case "InCEPkts":
2022-12-28 23:00:02 +00:00
procSnmp6.Ip6.InCEPkts = &value
2022-08-02 06:19:38 +00:00
}
case "Icmp6":
switch key {
case "InMsgs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InMsgs = &value
2022-08-02 06:19:38 +00:00
case "InErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InErrors = &value
2022-08-02 06:19:38 +00:00
case "OutMsgs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutMsgs = &value
2022-08-02 06:19:38 +00:00
case "OutErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutErrors = &value
2022-08-02 06:19:38 +00:00
case "InCsumErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InCsumErrors = &value
2022-08-02 06:19:38 +00:00
case "InDestUnreachs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InDestUnreachs = &value
2022-08-02 06:19:38 +00:00
case "InPktTooBigs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InPktTooBigs = &value
2022-08-02 06:19:38 +00:00
case "InTimeExcds":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InTimeExcds = &value
2022-08-02 06:19:38 +00:00
case "InParmProblems":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InParmProblems = &value
2022-08-02 06:19:38 +00:00
case "InEchos":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InEchos = &value
2022-08-02 06:19:38 +00:00
case "InEchoReplies":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InEchoReplies = &value
2022-08-02 06:19:38 +00:00
case "InGroupMembQueries":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InGroupMembQueries = &value
2022-08-02 06:19:38 +00:00
case "InGroupMembResponses":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InGroupMembResponses = &value
2022-08-02 06:19:38 +00:00
case "InGroupMembReductions":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InGroupMembReductions = &value
2022-08-02 06:19:38 +00:00
case "InRouterSolicits":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InRouterSolicits = &value
2022-08-02 06:19:38 +00:00
case "InRouterAdvertisements":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InRouterAdvertisements = &value
2022-08-02 06:19:38 +00:00
case "InNeighborSolicits":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InNeighborSolicits = &value
2022-08-02 06:19:38 +00:00
case "InNeighborAdvertisements":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InNeighborAdvertisements = &value
2022-08-02 06:19:38 +00:00
case "InRedirects":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InRedirects = &value
2022-08-02 06:19:38 +00:00
case "InMLDv2Reports":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InMLDv2Reports = &value
2022-08-02 06:19:38 +00:00
case "OutDestUnreachs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutDestUnreachs = &value
2022-08-02 06:19:38 +00:00
case "OutPktTooBigs":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutPktTooBigs = &value
2022-08-02 06:19:38 +00:00
case "OutTimeExcds":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutTimeExcds = &value
2022-08-02 06:19:38 +00:00
case "OutParmProblems":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutParmProblems = &value
2022-08-02 06:19:38 +00:00
case "OutEchos":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutEchos = &value
2022-08-02 06:19:38 +00:00
case "OutEchoReplies":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutEchoReplies = &value
2022-08-02 06:19:38 +00:00
case "OutGroupMembQueries":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutGroupMembQueries = &value
2022-08-02 06:19:38 +00:00
case "OutGroupMembResponses":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutGroupMembResponses = &value
2022-08-02 06:19:38 +00:00
case "OutGroupMembReductions":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutGroupMembReductions = &value
2022-08-02 06:19:38 +00:00
case "OutRouterSolicits":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutRouterSolicits = &value
2022-08-02 06:19:38 +00:00
case "OutRouterAdvertisements":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutRouterAdvertisements = &value
2022-08-02 06:19:38 +00:00
case "OutNeighborSolicits":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutNeighborSolicits = &value
2022-08-02 06:19:38 +00:00
case "OutNeighborAdvertisements":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutNeighborAdvertisements = &value
2022-08-02 06:19:38 +00:00
case "OutRedirects":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutRedirects = &value
2022-08-02 06:19:38 +00:00
case "OutMLDv2Reports":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutMLDv2Reports = &value
2022-08-02 06:19:38 +00:00
case "InType1":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InType1 = &value
2022-08-02 06:19:38 +00:00
case "InType134":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InType134 = &value
2022-08-02 06:19:38 +00:00
case "InType135":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InType135 = &value
2022-08-02 06:19:38 +00:00
case "InType136":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InType136 = &value
2022-08-02 06:19:38 +00:00
case "InType143":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.InType143 = &value
2022-08-02 06:19:38 +00:00
case "OutType133":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutType133 = &value
2022-08-02 06:19:38 +00:00
case "OutType135":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutType135 = &value
2022-08-02 06:19:38 +00:00
case "OutType136":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutType136 = &value
2022-08-02 06:19:38 +00:00
case "OutType143":
2022-12-28 23:00:02 +00:00
procSnmp6.Icmp6.OutType143 = &value
2022-08-02 06:19:38 +00:00
}
case "Udp6":
switch key {
case "InDatagrams":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.InDatagrams = &value
2022-08-02 06:19:38 +00:00
case "NoPorts":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.NoPorts = &value
2022-08-02 06:19:38 +00:00
case "InErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.InErrors = &value
2022-08-02 06:19:38 +00:00
case "OutDatagrams":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.OutDatagrams = &value
2022-08-02 06:19:38 +00:00
case "RcvbufErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.RcvbufErrors = &value
2022-08-02 06:19:38 +00:00
case "SndbufErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.SndbufErrors = &value
2022-08-02 06:19:38 +00:00
case "InCsumErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.InCsumErrors = &value
2022-08-02 06:19:38 +00:00
case "IgnoredMulti":
2022-12-28 23:00:02 +00:00
procSnmp6.Udp6.IgnoredMulti = &value
2022-08-02 06:19:38 +00:00
}
case "UdpLite6":
switch key {
case "InDatagrams":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.InDatagrams = &value
2022-08-02 06:19:38 +00:00
case "NoPorts":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.NoPorts = &value
2022-08-02 06:19:38 +00:00
case "InErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.InErrors = &value
2022-08-02 06:19:38 +00:00
case "OutDatagrams":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.OutDatagrams = &value
2022-08-02 06:19:38 +00:00
case "RcvbufErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.RcvbufErrors = &value
2022-08-02 06:19:38 +00:00
case "SndbufErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.SndbufErrors = &value
2022-08-02 06:19:38 +00:00
case "InCsumErrors":
2022-12-28 23:00:02 +00:00
procSnmp6.UdpLite6.InCsumErrors = &value
2022-08-02 06:19:38 +00:00
}
}
}
}
return procSnmp6, scanner.Err()
}