in pkg/metrics/collector/kernel_metrics.go [117:155]
func (c *kernelStatCollector) Update(ch chan<- prometheus.Metric) error {
// Get snmp values.
data, err := os.ReadFile("/proc/net/snmp")
if err != nil {
return fmt.Errorf("could not read proc/net/snmp")
}
output := string(data)
netstats, err := parseKeyValueLines(output, snmpLabel)
if err != nil {
return err
}
if val, ok := netstats[tcpSegsIn]; ok {
ch <- prometheus.MustNewConstMetric(segmentsReceivedDesc, prometheus.CounterValue, float64(val))
}
if val, ok := netstats[tcpSegsOut]; ok {
ch <- prometheus.MustNewConstMetric(segmentsSentDesc, prometheus.CounterValue, float64(val))
}
if val, ok := netstats[tcpSegsRetrans]; ok {
ch <- prometheus.MustNewConstMetric(segmentsRetransmittedDesc, prometheus.CounterValue, float64(val))
}
// Get netstat values
data, err = os.ReadFile("/proc/net/netstat")
if err != nil {
return fmt.Errorf("could not read proc/net/netstat")
}
output = string(data)
nstats, err := parseKeyValueLines(output, netstatLabel)
if err != nil {
return err
}
if val, ok := nstats[tcpTimeoutRehash]; ok {
ch <- prometheus.MustNewConstMetric(tcpTimeoutDesc, prometheus.CounterValue, float64(val))
}
if val, ok := nstats[tcpDuplicateRehash]; ok {
ch <- prometheus.MustNewConstMetric(tcpDuplicateDesc, prometheus.CounterValue, float64(val))
}
return nil
}