summaryrefslogtreecommitdiff
path: root/vendor/github.com/prometheus/procfs/netstat.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2022-02-17 13:46:51 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2022-02-22 14:38:57 -0500
commit80c5962dba7f5ecd6b602aecd0df479bd04391b1 (patch)
treea1d7fada738182c2eb8cd6993f33625ae704ba94 /vendor/github.com/prometheus/procfs/netstat.go
parentd3903a85910979d8212028cf814574047015db58 (diff)
downloadpodman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.tar.gz
podman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.tar.bz2
podman-80c5962dba7f5ecd6b602aecd0df479bd04391b1.zip
Add containers-common spec and command to podman
Since containers-common package is tied to specific versions of Podman, add tools to build the package into the contrib directory This should help other distributions to figure out which commont package to ship. Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/prometheus/procfs/netstat.go')
-rw-r--r--vendor/github.com/prometheus/procfs/netstat.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/vendor/github.com/prometheus/procfs/netstat.go b/vendor/github.com/prometheus/procfs/netstat.go
new file mode 100644
index 000000000..94d892f11
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/netstat.go
@@ -0,0 +1,68 @@
+// Copyright 2020 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"
+ "os"
+ "path/filepath"
+ "strconv"
+ "strings"
+)
+
+// NetStat contains statistics for all the counters from one file
+type NetStat struct {
+ Filename string
+ Stats map[string][]uint64
+}
+
+// NetStat retrieves stats from /proc/net/stat/
+func (fs FS) NetStat() ([]NetStat, error) {
+ statFiles, err := filepath.Glob(fs.proc.Path("net/stat/*"))
+ if err != nil {
+ return nil, err
+ }
+
+ var netStatsTotal []NetStat
+
+ for _, filePath := range statFiles {
+ file, err := os.Open(filePath)
+ if err != nil {
+ return nil, err
+ }
+
+ netStatFile := NetStat{
+ Filename: filepath.Base(filePath),
+ Stats: make(map[string][]uint64),
+ }
+ scanner := bufio.NewScanner(file)
+ scanner.Scan()
+ // First string is always a header for stats
+ var headers []string
+ headers = append(headers, strings.Fields(scanner.Text())...)
+
+ // Other strings represent per-CPU counters
+ for scanner.Scan() {
+ for num, counter := range strings.Fields(scanner.Text()) {
+ value, err := strconv.ParseUint(counter, 16, 32)
+ if err != nil {
+ return nil, err
+ }
+ netStatFile.Stats[headers[num]] = append(netStatFile.Stats[headers[num]], value)
+ }
+ }
+ netStatsTotal = append(netStatsTotal, netStatFile)
+ }
+ return netStatsTotal, nil
+}