aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Kochie <superq@gmail.com>2020-02-18 11:33:46 +0100
committerGitHub <noreply@github.com>2020-02-18 11:33:46 +0100
commit14df2a1a1a24f14070fe5a158f8b099c0e000fa3 (patch)
tree05d72e1f5166d5e70d0a2847ff2fa46b66f68080
parentdcfd6104332b22d3de1afa5425b6316b7a2952c6 (diff)
downloadprometheus_node_collector-14df2a1a1a24f14070fe5a158f8b099c0e000fa3.tar.bz2
prometheus_node_collector-14df2a1a1a24f14070fe5a158f8b099c0e000fa3.tar.xz
prometheus_node_collector-14df2a1a1a24f14070fe5a158f8b099c0e000fa3.zip
Update to latest procfs library (#1611)
Bump to v0.0.10 procfs library. Signed-off-by: Ben Kochie <superq@gmail.com>
-rw-r--r--collector/softnet_linux.go2
-rw-r--r--go.mod2
-rw-r--r--go.sum4
-rw-r--r--vendor/github.com/prometheus/procfs/Makefile.common12
-rw-r--r--vendor/github.com/prometheus/procfs/crypto.go160
-rw-r--r--vendor/github.com/prometheus/procfs/fixtures.ttar37
-rw-r--r--vendor/github.com/prometheus/procfs/loadavg.go62
-rw-r--r--vendor/github.com/prometheus/procfs/net_conntrackstat.go153
-rw-r--r--vendor/github.com/prometheus/procfs/net_softnet.go101
-rw-r--r--vendor/github.com/prometheus/procfs/net_udp.go229
-rw-r--r--vendor/github.com/prometheus/procfs/net_unix.go222
-rw-r--r--vendor/github.com/prometheus/procfs/proc_status.go5
-rw-r--r--vendor/github.com/prometheus/procfs/swaps.go89
-rw-r--r--vendor/github.com/prometheus/procfs/sysfs/class_infiniband.go2
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/parse.go16
-rw-r--r--vendor/github.com/prometheus/procfs/xfs/xfs.go1
-rw-r--r--vendor/modules.txt2
17 files changed, 849 insertions, 250 deletions
diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go
index 1f0bdec..e48f182 100644
--- a/collector/softnet_linux.go
+++ b/collector/softnet_linux.go
@@ -70,7 +70,7 @@ func NewSoftnetCollector(logger log.Logger) (Collector, error) {
70 70
71// Update gets parsed softnet statistics using procfs. 71// Update gets parsed softnet statistics using procfs.
72func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error { 72func (c *softnetCollector) Update(ch chan<- prometheus.Metric) error {
73 stats, err := c.fs.GatherSoftnetStats() 73 stats, err := c.fs.NetSoftnetStat()
74 if err != nil { 74 if err != nil {
75 return fmt.Errorf("could not get softnet statistics: %s", err) 75 return fmt.Errorf("could not get softnet statistics: %s", err)
76 } 76 }
diff --git a/go.mod b/go.mod
index a811337..547fd44 100644
--- a/go.mod
+++ b/go.mod
@@ -15,7 +15,7 @@ require (
15 github.com/prometheus/client_golang v1.0.0 15 github.com/prometheus/client_golang v1.0.0
16 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 16 github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90
17 github.com/prometheus/common v0.7.0 17 github.com/prometheus/common v0.7.0
18 github.com/prometheus/procfs v0.0.8 18 github.com/prometheus/procfs v0.0.10
19 github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 19 github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745
20 github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a 20 github.com/soundcloud/go-runit v0.0.0-20150630195641-06ad41a06c4a
21 go.uber.org/atomic v1.3.2 // indirect 21 go.uber.org/atomic v1.3.2 // indirect
diff --git a/go.sum b/go.sum
index 810a854..7a9b22f 100644
--- a/go.sum
+++ b/go.sum
@@ -87,8 +87,8 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2
87github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= 87github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
88github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs= 88github.com/prometheus/procfs v0.0.2 h1:6LJUbpNm42llc4HRCuvApCSWB/WfhuNo9K98Q9sNGfs=
89github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= 89github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
90github.com/prometheus/procfs v0.0.8 h1:+fpWZdT24pJBiqJdAwYBjPSk+5YmQzYNPYzQsdzLkt8= 90github.com/prometheus/procfs v0.0.10 h1:QJQN3jYQhkamO4mhfUWqdDH2asK7ONOI9MTWjyAxNKM=
91github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= 91github.com/prometheus/procfs v0.0.10/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
92github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 h1:IuH7WumZNax0D+rEqmy2TyhKCzrtMGqbZO0b8rO00JA= 92github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745 h1:IuH7WumZNax0D+rEqmy2TyhKCzrtMGqbZO0b8rO00JA=
93github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8= 93github.com/siebenmann/go-kstat v0.0.0-20160321171754-d34789b79745/go.mod h1:G81aIFAMS9ECrwBYR9YxhlPjWgrItd+Kje78O6+uqm8=
94github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= 94github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
diff --git a/vendor/github.com/prometheus/procfs/Makefile.common b/vendor/github.com/prometheus/procfs/Makefile.common
index d7aea1b..066866e 100644
--- a/vendor/github.com/prometheus/procfs/Makefile.common
+++ b/vendor/github.com/prometheus/procfs/Makefile.common
@@ -69,12 +69,12 @@ else
69 GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH) 69 GO_BUILD_PLATFORM ?= $(GOHOSTOS)-$(GOHOSTARCH)
70endif 70endif
71 71
72PROMU_VERSION ?= 0.4.0 72PROMU_VERSION ?= 0.5.0
73PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz 73PROMU_URL := https://github.com/prometheus/promu/releases/download/v$(PROMU_VERSION)/promu-$(PROMU_VERSION).$(GO_BUILD_PLATFORM).tar.gz
74 74
75GOLANGCI_LINT := 75GOLANGCI_LINT :=
76GOLANGCI_LINT_OPTS ?= 76GOLANGCI_LINT_OPTS ?=
77GOLANGCI_LINT_VERSION ?= v1.16.0 77GOLANGCI_LINT_VERSION ?= v1.18.0
78# golangci-lint only supports linux, darwin and windows platforms on i386/amd64. 78# golangci-lint only supports linux, darwin and windows platforms on i386/amd64.
79# windows isn't included here because of the path separator being different. 79# windows isn't included here because of the path separator being different.
80ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin)) 80ifeq ($(GOHOSTOS),$(filter $(GOHOSTOS),linux darwin))
@@ -86,7 +86,8 @@ endif
86PREFIX ?= $(shell pwd) 86PREFIX ?= $(shell pwd)
87BIN_DIR ?= $(shell pwd) 87BIN_DIR ?= $(shell pwd)
88DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD)) 88DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))
89DOCKERFILE_PATH ?= ./ 89DOCKERFILE_PATH ?= ./Dockerfile
90DOCKERBUILD_CONTEXT ?= ./
90DOCKER_REPO ?= prom 91DOCKER_REPO ?= prom
91 92
92DOCKER_ARCHS ?= amd64 93DOCKER_ARCHS ?= amd64
@@ -200,7 +201,7 @@ endif
200.PHONY: common-build 201.PHONY: common-build
201common-build: promu 202common-build: promu
202 @echo ">> building binaries" 203 @echo ">> building binaries"
203 GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) 204 GO111MODULE=$(GO111MODULE) $(PROMU) build --prefix $(PREFIX) $(PROMU_BINARIES)
204 205
205.PHONY: common-tarball 206.PHONY: common-tarball
206common-tarball: promu 207common-tarball: promu
@@ -211,9 +212,10 @@ common-tarball: promu
211common-docker: $(BUILD_DOCKER_ARCHS) 212common-docker: $(BUILD_DOCKER_ARCHS)
212$(BUILD_DOCKER_ARCHS): common-docker-%: 213$(BUILD_DOCKER_ARCHS): common-docker-%:
213 docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" \ 214 docker build -t "$(DOCKER_REPO)/$(DOCKER_IMAGE_NAME)-linux-$*:$(DOCKER_IMAGE_TAG)" \
215 -f $(DOCKERFILE_PATH) \
214 --build-arg ARCH="$*" \ 216 --build-arg ARCH="$*" \
215 --build-arg OS="linux" \ 217 --build-arg OS="linux" \
216 $(DOCKERFILE_PATH) 218 $(DOCKERBUILD_CONTEXT)
217 219
218.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS) 220.PHONY: common-docker-publish $(PUBLISH_DOCKER_ARCHS)
219common-docker-publish: $(PUBLISH_DOCKER_ARCHS) 221common-docker-publish: $(PUBLISH_DOCKER_ARCHS)
diff --git a/vendor/github.com/prometheus/procfs/crypto.go b/vendor/github.com/prometheus/procfs/crypto.go
index 19d4041..a958933 100644
--- a/vendor/github.com/prometheus/procfs/crypto.go
+++ b/vendor/github.com/prometheus/procfs/crypto.go
@@ -14,10 +14,10 @@
14package procfs 14package procfs
15 15
16import ( 16import (
17 "bufio"
17 "bytes" 18 "bytes"
18 "fmt" 19 "fmt"
19 "io/ioutil" 20 "io"
20 "strconv"
21 "strings" 21 "strings"
22 22
23 "github.com/prometheus/procfs/internal/util" 23 "github.com/prometheus/procfs/internal/util"
@@ -52,80 +52,102 @@ type Crypto struct {
52// structs containing the relevant info. More information available here: 52// structs containing the relevant info. More information available here:
53// https://kernel.readthedocs.io/en/sphinx-samples/crypto-API.html 53// https://kernel.readthedocs.io/en/sphinx-samples/crypto-API.html
54func (fs FS) Crypto() ([]Crypto, error) { 54func (fs FS) Crypto() ([]Crypto, error) {
55 data, err := ioutil.ReadFile(fs.proc.Path("crypto")) 55 path := fs.proc.Path("crypto")
56 b, err := util.ReadFileNoStat(path)
56 if err != nil { 57 if err != nil {
57 return nil, fmt.Errorf("error parsing crypto %s: %s", fs.proc.Path("crypto"), err) 58 return nil, fmt.Errorf("error reading crypto %s: %s", path, err)
58 } 59 }
59 crypto, err := parseCrypto(data) 60
61 crypto, err := parseCrypto(bytes.NewReader(b))
60 if err != nil { 62 if err != nil {
61 return nil, fmt.Errorf("error parsing crypto %s: %s", fs.proc.Path("crypto"), err) 63 return nil, fmt.Errorf("error parsing crypto %s: %s", path, err)
62 } 64 }
65
63 return crypto, nil 66 return crypto, nil
64} 67}
65 68
66func parseCrypto(cryptoData []byte) ([]Crypto, error) { 69// parseCrypto parses a /proc/crypto stream into Crypto elements.
67 crypto := []Crypto{} 70func parseCrypto(r io.Reader) ([]Crypto, error) {
68 71 var out []Crypto
69 cryptoBlocks := bytes.Split(cryptoData, []byte("\n\n")) 72
70 73 s := bufio.NewScanner(r)
71 for _, block := range cryptoBlocks { 74 for s.Scan() {
72 var newCryptoElem Crypto 75 text := s.Text()
73 76 switch {
74 lines := strings.Split(string(block), "\n") 77 case strings.HasPrefix(text, "name"):
75 for _, line := range lines { 78 // Each crypto element begins with its name.
76 if strings.TrimSpace(line) == "" || line[0] == ' ' { 79 out = append(out, Crypto{})
77 continue 80 case text == "":
78 } 81 continue
79 fields := strings.Split(line, ":") 82 }
80 key := strings.TrimSpace(fields[0]) 83
81 value := strings.TrimSpace(fields[1]) 84 kv := strings.Split(text, ":")
82 vp := util.NewValueParser(value) 85 if len(kv) != 2 {
83 86 return nil, fmt.Errorf("malformed crypto line: %q", text)
84 switch strings.TrimSpace(key) { 87 }
85 case "async": 88
86 b, err := strconv.ParseBool(value) 89 k := strings.TrimSpace(kv[0])
87 if err == nil { 90 v := strings.TrimSpace(kv[1])
88 newCryptoElem.Async = b 91
89 } 92 // Parse the key/value pair into the currently focused element.
90 case "blocksize": 93 c := &out[len(out)-1]
91 newCryptoElem.Blocksize = vp.PUInt64() 94 if err := c.parseKV(k, v); err != nil {
92 case "chunksize": 95 return nil, err
93 newCryptoElem.Chunksize = vp.PUInt64()
94 case "digestsize":
95 newCryptoElem.Digestsize = vp.PUInt64()
96 case "driver":
97 newCryptoElem.Driver = value
98 case "geniv":
99 newCryptoElem.Geniv = value
100 case "internal":
101 newCryptoElem.Internal = value
102 case "ivsize":
103 newCryptoElem.Ivsize = vp.PUInt64()
104 case "maxauthsize":
105 newCryptoElem.Maxauthsize = vp.PUInt64()
106 case "max keysize":
107 newCryptoElem.MaxKeysize = vp.PUInt64()
108 case "min keysize":
109 newCryptoElem.MinKeysize = vp.PUInt64()
110 case "module":
111 newCryptoElem.Module = value
112 case "name":
113 newCryptoElem.Name = value
114 case "priority":
115 newCryptoElem.Priority = vp.PInt64()
116 case "refcnt":
117 newCryptoElem.Refcnt = vp.PInt64()
118 case "seedsize":
119 newCryptoElem.Seedsize = vp.PUInt64()
120 case "selftest":
121 newCryptoElem.Selftest = value
122 case "type":
123 newCryptoElem.Type = value
124 case "walksize":
125 newCryptoElem.Walksize = vp.PUInt64()
126 }
127 } 96 }
128 crypto = append(crypto, newCryptoElem)
129 } 97 }
130 return crypto, nil 98
99 if err := s.Err(); err != nil {
100 return nil, err
101 }
102
103 return out, nil
104}
105
106// parseKV parses a key/value pair into the appropriate field of c.
107func (c *Crypto) parseKV(k, v string) error {
108 vp := util.NewValueParser(v)
109
110 switch k {
111 case "async":
112 // Interpret literal yes as true.
113 c.Async = v == "yes"
114 case "blocksize":
115 c.Blocksize = vp.PUInt64()
116 case "chunksize":
117 c.Chunksize = vp.PUInt64()
118 case "digestsize":
119 c.Digestsize = vp.PUInt64()
120 case "driver":
121 c.Driver = v
122 case "geniv":
123 c.Geniv = v
124 case "internal":
125 c.Internal = v
126 case "ivsize":
127 c.Ivsize = vp.PUInt64()
128 case "maxauthsize":
129 c.Maxauthsize = vp.PUInt64()
130 case "max keysize":
131 c.MaxKeysize = vp.PUInt64()
132 case "min keysize":
133 c.MinKeysize = vp.PUInt64()
134 case "module":
135 c.Module = v
136 case "name":
137 c.Name = v
138 case "priority":
139 c.Priority = vp.PInt64()
140 case "refcnt":
141 c.Refcnt = vp.PInt64()
142 case "seedsize":
143 c.Seedsize = vp.PUInt64()
144 case "selftest":
145 c.Selftest = v
146 case "type":
147 c.Type = v
148 case "walksize":
149 c.Walksize = vp.PUInt64()
150 }
151
152 return vp.Err()
131} 153}
diff --git a/vendor/github.com/prometheus/procfs/fixtures.ttar b/vendor/github.com/prometheus/procfs/fixtures.ttar
index c50a18a..a21ccad 100644
--- a/vendor/github.com/prometheus/procfs/fixtures.ttar
+++ b/vendor/github.com/prometheus/procfs/fixtures.ttar
@@ -189,7 +189,7 @@ Ngid: 0
189Pid: 26231 189Pid: 26231
190PPid: 1 190PPid: 1
191TracerPid: 0 191TracerPid: 0
192Uid: 0 0 0 0 192Uid: 1000 1000 1000 0
193Gid: 0 0 0 0 193Gid: 0 0 0 0
194FDSize: 128 194FDSize: 128
195Groups: 195Groups:
@@ -554,7 +554,7 @@ power management:
554Mode: 444 554Mode: 444
555# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 555# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
556Path: fixtures/proc/crypto 556Path: fixtures/proc/crypto
557Lines: 971 557Lines: 972
558name : ccm(aes) 558name : ccm(aes)
559driver : ccm_base(ctr(aes-aesni),cbcmac(aes-aesni)) 559driver : ccm_base(ctr(aes-aesni),cbcmac(aes-aesni))
560module : ccm 560module : ccm
@@ -588,6 +588,7 @@ refcnt : 1
588selftest : passed 588selftest : passed
589internal : no 589internal : no
590type : kpp 590type : kpp
591async : yes
591 592
592name : ecb(arc4) 593name : ecb(arc4)
593driver : ecb(arc4)-generic 594driver : ecb(arc4)-generic
@@ -1528,6 +1529,11 @@ max keysize : 32
1528 1529
1529Mode: 444 1530Mode: 444
1530# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1531# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1532Path: fixtures/proc/loadavg
1533Lines: 1
15340.02 0.04 0.05 1/497 11947
1535Mode: 444
1536# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1531Path: fixtures/proc/diskstats 1537Path: fixtures/proc/diskstats
1532Lines: 49 1538Lines: 49
1533 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0 1539 1 0 ram0 0 0 0 0 0 0 0 0 0 0 0
@@ -1825,6 +1831,27 @@ Lines: 1
182500015c73 00020e76 F0000769 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 183100015c73 00020e76 F0000769 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
1826Mode: 644 1832Mode: 644
1827# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1833# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1834Path: fixtures/proc/net/udp
1835Lines: 4
1836 sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
1837 0: 0A000005:0016 00000000:0000 0A 00000000:00000001 00:00000000 00000000 0 0 2740 1 ffff88003d3af3c0 100 0 0 10 0
1838 1: 00000000:0016 00000000:0000 0A 00000001:00000000 00:00000000 00000000 0 0 2740 1 ffff88003d3af3c0 100 0 0 10 0
1839 2: 00000000:0016 00000000:0000 0A 00000001:00000001 00:00000000 00000000 0 0 2740 1 ffff88003d3af3c0 100 0 0 10 0
1840Mode: 644
1841# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1842Path: fixtures/proc/net/udp6
1843Lines: 3
1844 sl local_address remote_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode ref pointer drops
1845 1315: 00000000000000000000000000000000:14EB 00000000000000000000000000000000:0000 07 00000000:00000000 00:00000000 00000000 981 0 21040 2 0000000013726323 0
1846 6073: 000080FE00000000FFADE15609667CFE:C781 00000000000000000000000000000000:0000 07 00000000:00000000 00:00000000 00000000 1000 0 11337031 2 00000000b9256fdd 0
1847Mode: 644
1848# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1849Path: fixtures/proc/net/udp_broken
1850Lines: 2
1851 sl local_address rem_address st
1852 1: 00000000:0016 00000000:0000 0A
1853Mode: 644
1854# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1828Path: fixtures/proc/net/unix 1855Path: fixtures/proc/net/unix
1829Lines: 6 1856Lines: 6
1830Num RefCount Protocol Flags Type St Inode Path 1857Num RefCount Protocol Flags Type St Inode Path
@@ -1930,6 +1957,12 @@ procs_blocked 1
1930softirq 5057579 250191 1481983 1647 211099 186066 0 1783454 622196 12499 508444 1957softirq 5057579 250191 1481983 1647 211099 186066 0 1783454 622196 12499 508444
1931Mode: 644 1958Mode: 644
1932# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1959# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1960Path: fixtures/proc/swaps
1961Lines: 2
1962Filename Type Size Used Priority
1963/dev/dm-2 partition 131068 176 -2
1964Mode: 444
1965# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1933Directory: fixtures/proc/symlinktargets 1966Directory: fixtures/proc/symlinktargets
1934Mode: 755 1967Mode: 755
1935# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1968# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/vendor/github.com/prometheus/procfs/loadavg.go b/vendor/github.com/prometheus/procfs/loadavg.go
new file mode 100644
index 0000000..00bbe14
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/loadavg.go
@@ -0,0 +1,62 @@
1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17 "fmt"
18 "strconv"
19 "strings"
20
21 "github.com/prometheus/procfs/internal/util"
22)
23
24// LoadAvg represents an entry in /proc/loadavg
25type LoadAvg struct {
26 Load1 float64
27 Load5 float64
28 Load15 float64
29}
30
31// LoadAvg returns loadavg from /proc.
32func (fs FS) LoadAvg() (*LoadAvg, error) {
33 path := fs.proc.Path("loadavg")
34
35 data, err := util.ReadFileNoStat(path)
36 if err != nil {
37 return nil, err
38 }
39 return parseLoad(data)
40}
41
42// Parse /proc loadavg and return 1m, 5m and 15m.
43func parseLoad(loadavgBytes []byte) (*LoadAvg, error) {
44 loads := make([]float64, 3)
45 parts := strings.Fields(string(loadavgBytes))
46 if len(parts) < 3 {
47 return nil, fmt.Errorf("malformed loadavg line: too few fields in loadavg string: %s", string(loadavgBytes))
48 }
49
50 var err error
51 for i, load := range parts[0:3] {
52 loads[i], err = strconv.ParseFloat(load, 64)
53 if err != nil {
54 return nil, fmt.Errorf("could not parse load '%s': %s", load, err)
55 }
56 }
57 return &LoadAvg{
58 Load1: loads[0],
59 Load5: loads[1],
60 Load15: loads[2],
61 }, nil
62}
diff --git a/vendor/github.com/prometheus/procfs/net_conntrackstat.go b/vendor/github.com/prometheus/procfs/net_conntrackstat.go
new file mode 100644
index 0000000..1e27c83
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/net_conntrackstat.go
@@ -0,0 +1,153 @@
1// Copyright 2020 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17 "bufio"
18 "bytes"
19 "fmt"
20 "io"
21 "strconv"
22 "strings"
23
24 "github.com/prometheus/procfs/internal/util"
25)
26
27// A ConntrackStatEntry represents one line from net/stat/nf_conntrack
28// and contains netfilter conntrack statistics at one CPU core
29type ConntrackStatEntry struct {
30 Entries uint64
31 Found uint64
32 Invalid uint64
33 Ignore uint64
34 Insert uint64
35 InsertFailed uint64
36 Drop uint64
37 EarlyDrop uint64
38 SearchRestart uint64
39}
40
41// Retrieves netfilter's conntrack statistics, split by CPU cores
42func (fs FS) ConntrackStat() ([]ConntrackStatEntry, error) {
43 return readConntrackStat(fs.proc.Path("net", "stat", "nf_conntrack"))
44}
45
46// Parses a slice of ConntrackStatEntries from the given filepath
47func readConntrackStat(path string) ([]ConntrackStatEntry, error) {
48 // This file is small and can be read with one syscall.
49 b, err := util.ReadFileNoStat(path)
50 if err != nil {
51 // Do not wrap this error so the caller can detect os.IsNotExist and
52 // similar conditions.
53 return nil, err
54 }
55
56 stat, err := parseConntrackStat(bytes.NewReader(b))
57 if err != nil {
58 return nil, fmt.Errorf("failed to read conntrack stats from %q: %v", path, err)
59 }
60
61 return stat, nil
62}
63
64// Reads the contents of a conntrack statistics file and parses a slice of ConntrackStatEntries
65func parseConntrackStat(r io.Reader) ([]ConntrackStatEntry, error) {
66 var entries []ConntrackStatEntry
67
68 scanner := bufio.NewScanner(r)
69 scanner.Scan()
70 for scanner.Scan() {
71 fields := strings.Fields(scanner.Text())
72 conntrackEntry, err := parseConntrackStatEntry(fields)
73 if err != nil {
74 return nil, err
75 }
76 entries = append(entries, *conntrackEntry)
77 }
78
79 return entries, nil
80}
81
82// Parses a ConntrackStatEntry from given array of fields
83func parseConntrackStatEntry(fields []string) (*ConntrackStatEntry, error) {
84 if len(fields) != 17 {
85 return nil, fmt.Errorf("invalid conntrackstat entry, missing fields")
86 }
87 entry := &ConntrackStatEntry{}
88
89 entries, err := parseConntrackStatField(fields[0])
90 if err != nil {
91 return nil, err
92 }
93 entry.Entries = entries
94
95 found, err := parseConntrackStatField(fields[2])
96 if err != nil {
97 return nil, err
98 }
99 entry.Found = found
100
101 invalid, err := parseConntrackStatField(fields[4])
102 if err != nil {
103 return nil, err
104 }
105 entry.Invalid = invalid
106
107 ignore, err := parseConntrackStatField(fields[5])
108 if err != nil {
109 return nil, err
110 }
111 entry.Ignore = ignore
112
113 insert, err := parseConntrackStatField(fields[8])
114 if err != nil {
115 return nil, err
116 }
117 entry.Insert = insert
118
119 insertFailed, err := parseConntrackStatField(fields[9])
120 if err != nil {
121 return nil, err
122 }
123 entry.InsertFailed = insertFailed
124
125 drop, err := parseConntrackStatField(fields[10])
126 if err != nil {
127 return nil, err
128 }
129 entry.Drop = drop
130
131 earlyDrop, err := parseConntrackStatField(fields[11])
132 if err != nil {
133 return nil, err
134 }
135 entry.EarlyDrop = earlyDrop
136
137 searchRestart, err := parseConntrackStatField(fields[16])
138 if err != nil {
139 return nil, err
140 }
141 entry.SearchRestart = searchRestart
142
143 return entry, nil
144}
145
146// Parses a uint64 from given hex in string
147func parseConntrackStatField(field string) (uint64, error) {
148 val, err := strconv.ParseUint(field, 16, 64)
149 if err != nil {
150 return 0, fmt.Errorf("couldn't parse \"%s\" field: %s", field, err)
151 }
152 return val, err
153}
diff --git a/vendor/github.com/prometheus/procfs/net_softnet.go b/vendor/github.com/prometheus/procfs/net_softnet.go
index 6fcad20..2a65cf1 100644
--- a/vendor/github.com/prometheus/procfs/net_softnet.go
+++ b/vendor/github.com/prometheus/procfs/net_softnet.go
@@ -14,78 +14,85 @@
14package procfs 14package procfs
15 15
16import ( 16import (
17 "bufio"
18 "bytes"
17 "fmt" 19 "fmt"
18 "io/ioutil" 20 "io"
19 "strconv" 21 "strconv"
20 "strings" 22 "strings"
23
24 "github.com/prometheus/procfs/internal/util"
21) 25)
22 26
23// For the proc file format details, 27// For the proc file format details,
24// see https://elixir.bootlin.com/linux/v4.17/source/net/core/net-procfs.c#L162 28// see https://elixir.bootlin.com/linux/v4.17/source/net/core/net-procfs.c#L162
25// and https://elixir.bootlin.com/linux/v4.17/source/include/linux/netdevice.h#L2810. 29// and https://elixir.bootlin.com/linux/v4.17/source/include/linux/netdevice.h#L2810.
26 30
27// SoftnetEntry contains a single row of data from /proc/net/softnet_stat 31// SoftnetStat contains a single row of data from /proc/net/softnet_stat
28type SoftnetEntry struct { 32type SoftnetStat struct {
29 // Number of processed packets 33 // Number of processed packets
30 Processed uint 34 Processed uint32
31 // Number of dropped packets 35 // Number of dropped packets
32 Dropped uint 36 Dropped uint32
33 // Number of times processing packets ran out of quota 37 // Number of times processing packets ran out of quota
34 TimeSqueezed uint 38 TimeSqueezed uint32
35} 39}
36 40
37// GatherSoftnetStats reads /proc/net/softnet_stat, parse the relevant columns, 41// NetSoftnetStat reads data from /proc/net/softnet_stat.
38// and then return a slice of SoftnetEntry's. 42func (fs FS) NetSoftnetStat() ([]SoftnetStat, error) {
39func (fs FS) GatherSoftnetStats() ([]SoftnetEntry, error) { 43 b, err := util.ReadFileNoStat(fs.proc.Path("net/softnet_stat"))
40 data, err := ioutil.ReadFile(fs.proc.Path("net/softnet_stat"))
41 if err != nil { 44 if err != nil {
42 return nil, fmt.Errorf("error reading softnet %s: %s", fs.proc.Path("net/softnet_stat"), err) 45 return nil, err
43 } 46 }
44 47
45 return parseSoftnetEntries(data) 48 entries, err := parseSoftnet(bytes.NewReader(b))
49 if err != nil {
50 return nil, fmt.Errorf("failed to parse /proc/net/softnet_stat: %v", err)
51 }
52
53 return entries, nil
46} 54}
47 55
48func parseSoftnetEntries(data []byte) ([]SoftnetEntry, error) { 56func parseSoftnet(r io.Reader) ([]SoftnetStat, error) {
49 lines := strings.Split(string(data), "\n") 57 const expectedColumns = 11
50 entries := make([]SoftnetEntry, 0) 58
51 var err error 59 s := bufio.NewScanner(r)
52 const ( 60
53 expectedColumns = 11 61 var stats []SoftnetStat
54 ) 62 for s.Scan() {
55 for _, line := range lines { 63 columns := strings.Fields(s.Text())
56 columns := strings.Fields(line)
57 width := len(columns) 64 width := len(columns)
58 if width == 0 { 65
59 continue 66 if width != 11 {
60 } 67 return nil, fmt.Errorf("%d columns were detected, but %d were expected", width, expectedColumns)
61 if width != expectedColumns {
62 return []SoftnetEntry{}, fmt.Errorf("%d columns were detected, but %d were expected", width, expectedColumns)
63 } 68 }
64 var entry SoftnetEntry 69
65 if entry, err = parseSoftnetEntry(columns); err != nil { 70 // We only parse the first three columns at the moment.
66 return []SoftnetEntry{}, err 71 us, err := parseHexUint32s(columns[0:3])
72 if err != nil {
73 return nil, err
67 } 74 }
68 entries = append(entries, entry) 75
76 stats = append(stats, SoftnetStat{
77 Processed: us[0],
78 Dropped: us[1],
79 TimeSqueezed: us[2],
80 })
69 } 81 }
70 82
71 return entries, nil 83 return stats, nil
72} 84}
73 85
74func parseSoftnetEntry(columns []string) (SoftnetEntry, error) { 86func parseHexUint32s(ss []string) ([]uint32, error) {
75 var err error 87 us := make([]uint32, 0, len(ss))
76 var processed, dropped, timeSqueezed uint64 88 for _, s := range ss {
77 if processed, err = strconv.ParseUint(columns[0], 16, 32); err != nil { 89 u, err := strconv.ParseUint(s, 16, 32)
78 return SoftnetEntry{}, fmt.Errorf("Unable to parse column 0: %s", err) 90 if err != nil {
79 } 91 return nil, err
80 if dropped, err = strconv.ParseUint(columns[1], 16, 32); err != nil { 92 }
81 return SoftnetEntry{}, fmt.Errorf("Unable to parse column 1: %s", err) 93
82 } 94 us = append(us, uint32(u))
83 if timeSqueezed, err = strconv.ParseUint(columns[2], 16, 32); err != nil {
84 return SoftnetEntry{}, fmt.Errorf("Unable to parse column 2: %s", err)
85 } 95 }
86 return SoftnetEntry{ 96
87 Processed: uint(processed), 97 return us, nil
88 Dropped: uint(dropped),
89 TimeSqueezed: uint(timeSqueezed),
90 }, nil
91} 98}
diff --git a/vendor/github.com/prometheus/procfs/net_udp.go b/vendor/github.com/prometheus/procfs/net_udp.go
new file mode 100644
index 0000000..d017e3f
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/net_udp.go
@@ -0,0 +1,229 @@
1// Copyright 2020 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17 "bufio"
18 "encoding/hex"
19 "fmt"
20 "io"
21 "net"
22 "os"
23 "strconv"
24 "strings"
25)
26
27const (
28 // readLimit is used by io.LimitReader while reading the content of the
29 // /proc/net/udp{,6} files. The number of lines inside such a file is dynamic
30 // as each line represents a single used socket.
31 // In theory, the number of available sockets is 65535 (2^16 - 1) per IP.
32 // With e.g. 150 Byte per line and the maximum number of 65535,
33 // the reader needs to handle 150 Byte * 65535 =~ 10 MB for a single IP.
34 readLimit = 4294967296 // Byte -> 4 GiB
35)
36
37type (
38 // NetUDP represents the contents of /proc/net/udp{,6} file without the header.
39 NetUDP []*netUDPLine
40
41 // NetUDPSummary provides already computed values like the total queue lengths or
42 // the total number of used sockets. In contrast to NetUDP it does not collect
43 // the parsed lines into a slice.
44 NetUDPSummary struct {
45 // TxQueueLength shows the total queue length of all parsed tx_queue lengths.
46 TxQueueLength uint64
47 // RxQueueLength shows the total queue length of all parsed rx_queue lengths.
48 RxQueueLength uint64
49 // UsedSockets shows the total number of parsed lines representing the
50 // number of used sockets.
51 UsedSockets uint64
52 }
53
54 // netUDPLine represents the fields parsed from a single line
55 // in /proc/net/udp{,6}. Fields which are not used by UDP are skipped.
56 // For the proc file format details, see https://linux.die.net/man/5/proc.
57 netUDPLine struct {
58 Sl uint64
59 LocalAddr net.IP
60 LocalPort uint64
61 RemAddr net.IP
62 RemPort uint64
63 St uint64
64 TxQueue uint64
65 RxQueue uint64
66 UID uint64
67 }
68)
69
70// NetUDP returns the IPv4 kernel/networking statistics for UDP datagrams
71// read from /proc/net/udp.
72func (fs FS) NetUDP() (NetUDP, error) {
73 return newNetUDP(fs.proc.Path("net/udp"))
74}
75
76// NetUDP6 returns the IPv6 kernel/networking statistics for UDP datagrams
77// read from /proc/net/udp6.
78func (fs FS) NetUDP6() (NetUDP, error) {
79 return newNetUDP(fs.proc.Path("net/udp6"))
80}
81
82// NetUDPSummary returns already computed statistics like the total queue lengths
83// for UDP datagrams read from /proc/net/udp.
84func (fs FS) NetUDPSummary() (*NetUDPSummary, error) {
85 return newNetUDPSummary(fs.proc.Path("net/udp"))
86}
87
88// NetUDP6Summary returns already computed statistics like the total queue lengths
89// for UDP datagrams read from /proc/net/udp6.
90func (fs FS) NetUDP6Summary() (*NetUDPSummary, error) {
91 return newNetUDPSummary(fs.proc.Path("net/udp6"))
92}
93
94// newNetUDP creates a new NetUDP{,6} from the contents of the given file.
95func newNetUDP(file string) (NetUDP, error) {
96 f, err := os.Open(file)
97 if err != nil {
98 return nil, err
99 }
100 defer f.Close()
101
102 netUDP := NetUDP{}
103
104 lr := io.LimitReader(f, readLimit)
105 s := bufio.NewScanner(lr)
106 s.Scan() // skip first line with headers
107 for s.Scan() {
108 fields := strings.Fields(s.Text())
109 line, err := parseNetUDPLine(fields)
110 if err != nil {
111 return nil, err
112 }
113 netUDP = append(netUDP, line)
114 }
115 if err := s.Err(); err != nil {
116 return nil, err
117 }
118 return netUDP, nil
119}
120
121// newNetUDPSummary creates a new NetUDP{,6} from the contents of the given file.
122func newNetUDPSummary(file string) (*NetUDPSummary, error) {
123 f, err := os.Open(file)
124 if err != nil {
125 return nil, err
126 }
127 defer f.Close()
128
129 netUDPSummary := &NetUDPSummary{}
130
131 lr := io.LimitReader(f, readLimit)
132 s := bufio.NewScanner(lr)
133 s.Scan() // skip first line with headers
134 for s.Scan() {
135 fields := strings.Fields(s.Text())
136 line, err := parseNetUDPLine(fields)
137 if err != nil {
138 return nil, err
139 }
140 netUDPSummary.TxQueueLength += line.TxQueue
141 netUDPSummary.RxQueueLength += line.RxQueue
142 netUDPSummary.UsedSockets++
143 }
144 if err := s.Err(); err != nil {
145 return nil, err
146 }
147 return netUDPSummary, nil
148}
149
150// parseNetUDPLine parses a single line, represented by a list of fields.
151func parseNetUDPLine(fields []string) (*netUDPLine, error) {
152 line := &netUDPLine{}
153 if len(fields) < 8 {
154 return nil, fmt.Errorf(
155 "cannot parse net udp socket line as it has less then 8 columns: %s",
156 strings.Join(fields, " "),
157 )
158 }
159 var err error // parse error
160
161 // sl
162 s := strings.Split(fields[0], ":")
163 if len(s) != 2 {
164 return nil, fmt.Errorf(
165 "cannot parse sl field in udp socket line: %s", fields[0])
166 }
167
168 if line.Sl, err = strconv.ParseUint(s[0], 0, 64); err != nil {
169 return nil, fmt.Errorf("cannot parse sl value in udp socket line: %s", err)
170 }
171 // local_address
172 l := strings.Split(fields[1], ":")
173 if len(l) != 2 {
174 return nil, fmt.Errorf(
175 "cannot parse local_address field in udp socket line: %s", fields[1])
176 }
177 if line.LocalAddr, err = hex.DecodeString(l[0]); err != nil {
178 return nil, fmt.Errorf(
179 "cannot parse local_address value in udp socket line: %s", err)
180 }
181 if line.LocalPort, err = strconv.ParseUint(l[1], 16, 64); err != nil {
182 return nil, fmt.Errorf(
183 "cannot parse local_address port value in udp socket line: %s", err)
184 }
185
186 // remote_address
187 r := strings.Split(fields[2], ":")
188 if len(r) != 2 {
189 return nil, fmt.Errorf(
190 "cannot parse rem_address field in udp socket line: %s", fields[1])
191 }
192 if line.RemAddr, err = hex.DecodeString(r[0]); err != nil {
193 return nil, fmt.Errorf(
194 "cannot parse rem_address value in udp socket line: %s", err)
195 }
196 if line.RemPort, err = strconv.ParseUint(r[1], 16, 64); err != nil {
197 return nil, fmt.Errorf(
198 "cannot parse rem_address port value in udp socket line: %s", err)
199 }
200
201 // st
202 if line.St, err = strconv.ParseUint(fields[3], 16, 64); err != nil {
203 return nil, fmt.Errorf(
204 "cannot parse st value in udp socket line: %s", err)
205 }
206
207 // tx_queue and rx_queue
208 q := strings.Split(fields[4], ":")
209 if len(q) != 2 {
210 return nil, fmt.Errorf(
211 "cannot parse tx/rx queues in udp socket line as it has a missing colon: %s",
212 fields[4],
213 )
214 }
215 if line.TxQueue, err = strconv.ParseUint(q[0], 16, 64); err != nil {
216 return nil, fmt.Errorf("cannot parse tx_queue value in udp socket line: %s", err)
217 }
218 if line.RxQueue, err = strconv.ParseUint(q[1], 16, 64); err != nil {
219 return nil, fmt.Errorf("cannot parse rx_queue value in udp socket line: %s", err)
220 }
221
222 // uid
223 if line.UID, err = strconv.ParseUint(fields[7], 0, 64); err != nil {
224 return nil, fmt.Errorf(
225 "cannot parse uid value in udp socket line: %s", err)
226 }
227
228 return line, nil
229}
diff --git a/vendor/github.com/prometheus/procfs/net_unix.go b/vendor/github.com/prometheus/procfs/net_unix.go
index 93bd58f..c55b4b1 100644
--- a/vendor/github.com/prometheus/procfs/net_unix.go
+++ b/vendor/github.com/prometheus/procfs/net_unix.go
@@ -15,7 +15,6 @@ package procfs
15 15
16import ( 16import (
17 "bufio" 17 "bufio"
18 "errors"
19 "fmt" 18 "fmt"
20 "io" 19 "io"
21 "os" 20 "os"
@@ -27,25 +26,15 @@ import (
27// see https://elixir.bootlin.com/linux/v4.17/source/net/unix/af_unix.c#L2815 26// see https://elixir.bootlin.com/linux/v4.17/source/net/unix/af_unix.c#L2815
28// and https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/net.h#L48. 27// and https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/net.h#L48.
29 28
30const ( 29// Constants for the various /proc/net/unix enumerations.
31 netUnixKernelPtrIdx = iota 30// TODO: match against x/sys/unix or similar?
32 netUnixRefCountIdx
33 _
34 netUnixFlagsIdx
35 netUnixTypeIdx
36 netUnixStateIdx
37 netUnixInodeIdx
38
39 // Inode and Path are optional.
40 netUnixStaticFieldsCnt = 6
41)
42
43const ( 31const (
44 netUnixTypeStream = 1 32 netUnixTypeStream = 1
45 netUnixTypeDgram = 2 33 netUnixTypeDgram = 2
46 netUnixTypeSeqpacket = 5 34 netUnixTypeSeqpacket = 5
47 35
48 netUnixFlagListen = 1 << 16 36 netUnixFlagDefault = 0
37 netUnixFlagListen = 1 << 16
49 38
50 netUnixStateUnconnected = 1 39 netUnixStateUnconnected = 1
51 netUnixStateConnecting = 2 40 netUnixStateConnecting = 2
@@ -53,129 +42,127 @@ const (
53 netUnixStateDisconnected = 4 42 netUnixStateDisconnected = 4
54) 43)
55 44
56var errInvalidKernelPtrFmt = errors.New("Invalid Num(the kernel table slot number) format") 45// NetUNIXType is the type of the type field.
46type NetUNIXType uint64
57 47
58// NetUnixType is the type of the type field. 48// NetUNIXFlags is the type of the flags field.
59type NetUnixType uint64 49type NetUNIXFlags uint64
60 50
61// NetUnixFlags is the type of the flags field. 51// NetUNIXState is the type of the state field.
62type NetUnixFlags uint64 52type NetUNIXState uint64
63 53
64// NetUnixState is the type of the state field. 54// NetUNIXLine represents a line of /proc/net/unix.
65type NetUnixState uint64 55type NetUNIXLine struct {
66
67// NetUnixLine represents a line of /proc/net/unix.
68type NetUnixLine struct {
69 KernelPtr string 56 KernelPtr string
70 RefCount uint64 57 RefCount uint64
71 Protocol uint64 58 Protocol uint64
72 Flags NetUnixFlags 59 Flags NetUNIXFlags
73 Type NetUnixType 60 Type NetUNIXType
74 State NetUnixState 61 State NetUNIXState
75 Inode uint64 62 Inode uint64
76 Path string 63 Path string
77} 64}
78 65
79// NetUnix holds the data read from /proc/net/unix. 66// NetUNIX holds the data read from /proc/net/unix.
80type NetUnix struct { 67type NetUNIX struct {
81 Rows []*NetUnixLine 68 Rows []*NetUNIXLine
82} 69}
83 70
84// NewNetUnix returns data read from /proc/net/unix. 71// NetUNIX returns data read from /proc/net/unix.
85func NewNetUnix() (*NetUnix, error) { 72func (fs FS) NetUNIX() (*NetUNIX, error) {
86 fs, err := NewFS(DefaultMountPoint) 73 return readNetUNIX(fs.proc.Path("net/unix"))
87 if err != nil {
88 return nil, err
89 }
90
91 return fs.NewNetUnix()
92} 74}
93 75
94// NewNetUnix returns data read from /proc/net/unix. 76// readNetUNIX reads data in /proc/net/unix format from the specified file.
95func (fs FS) NewNetUnix() (*NetUnix, error) { 77func readNetUNIX(file string) (*NetUNIX, error) {
96 return NewNetUnixByPath(fs.proc.Path("net/unix")) 78 // This file could be quite large and a streaming read is desirable versus
97} 79 // reading the entire contents at once.
98 80 f, err := os.Open(file)
99// NewNetUnixByPath returns data read from /proc/net/unix by file path.
100// It might returns an error with partial parsed data, if an error occur after some data parsed.
101func NewNetUnixByPath(path string) (*NetUnix, error) {
102 f, err := os.Open(path)
103 if err != nil { 81 if err != nil {
104 return nil, err 82 return nil, err
105 } 83 }
106 defer f.Close() 84 defer f.Close()
107 return NewNetUnixByReader(f) 85
86 return parseNetUNIX(f)
108} 87}
109 88
110// NewNetUnixByReader returns data read from /proc/net/unix by a reader. 89// parseNetUNIX creates a NetUnix structure from the incoming stream.
111// It might returns an error with partial parsed data, if an error occur after some data parsed. 90func parseNetUNIX(r io.Reader) (*NetUNIX, error) {
112func NewNetUnixByReader(reader io.Reader) (*NetUnix, error) { 91 // Begin scanning by checking for the existence of Inode.
113 nu := &NetUnix{ 92 s := bufio.NewScanner(r)
114 Rows: make([]*NetUnixLine, 0, 32), 93 s.Scan()
115 } 94
116 scanner := bufio.NewScanner(reader)
117 // Omit the header line.
118 scanner.Scan()
119 header := scanner.Text()
120 // From the man page of proc(5), it does not contain an Inode field, 95 // From the man page of proc(5), it does not contain an Inode field,
121 // but in actually it exists. 96 // but in actually it exists. This code works for both cases.
122 // This code works for both cases. 97 hasInode := strings.Contains(s.Text(), "Inode")
123 hasInode := strings.Contains(header, "Inode")
124 98
125 minFieldsCnt := netUnixStaticFieldsCnt 99 // Expect a minimum number of fields, but Inode and Path are optional:
100 // Num RefCount Protocol Flags Type St Inode Path
101 minFields := 6
126 if hasInode { 102 if hasInode {
127 minFieldsCnt++ 103 minFields++
128 } 104 }
129 for scanner.Scan() { 105
130 line := scanner.Text() 106 var nu NetUNIX
131 item, err := nu.parseLine(line, hasInode, minFieldsCnt) 107 for s.Scan() {
108 line := s.Text()
109 item, err := nu.parseLine(line, hasInode, minFields)
132 if err != nil { 110 if err != nil {
133 return nu, err 111 return nil, fmt.Errorf("failed to parse /proc/net/unix data %q: %v", line, err)
134 } 112 }
113
135 nu.Rows = append(nu.Rows, item) 114 nu.Rows = append(nu.Rows, item)
136 } 115 }
137 116
138 return nu, scanner.Err() 117 if err := s.Err(); err != nil {
118 return nil, fmt.Errorf("failed to scan /proc/net/unix data: %v", err)
119 }
120
121 return &nu, nil
139} 122}
140 123
141func (u *NetUnix) parseLine(line string, hasInode bool, minFieldsCnt int) (*NetUnixLine, error) { 124func (u *NetUNIX) parseLine(line string, hasInode bool, min int) (*NetUNIXLine, error) {
142 fields := strings.Fields(line) 125 fields := strings.Fields(line)
143 fieldsLen := len(fields) 126
144 if fieldsLen < minFieldsCnt { 127 l := len(fields)
145 return nil, fmt.Errorf( 128 if l < min {
146 "Parse Unix domain failed: expect at least %d fields but got %d", 129 return nil, fmt.Errorf("expected at least %d fields but got %d", min, l)
147 minFieldsCnt, fieldsLen)
148 }
149 kernelPtr, err := u.parseKernelPtr(fields[netUnixKernelPtrIdx])
150 if err != nil {
151 return nil, fmt.Errorf("Parse Unix domain num(%s) failed: %s", fields[netUnixKernelPtrIdx], err)
152 } 130 }
153 users, err := u.parseUsers(fields[netUnixRefCountIdx]) 131
132 // Field offsets are as follows:
133 // Num RefCount Protocol Flags Type St Inode Path
134
135 kernelPtr := strings.TrimSuffix(fields[0], ":")
136
137 users, err := u.parseUsers(fields[1])
154 if err != nil { 138 if err != nil {
155 return nil, fmt.Errorf("Parse Unix domain ref count(%s) failed: %s", fields[netUnixRefCountIdx], err) 139 return nil, fmt.Errorf("failed to parse ref count(%s): %v", fields[1], err)
156 } 140 }
157 flags, err := u.parseFlags(fields[netUnixFlagsIdx]) 141
142 flags, err := u.parseFlags(fields[3])
158 if err != nil { 143 if err != nil {
159 return nil, fmt.Errorf("Parse Unix domain flags(%s) failed: %s", fields[netUnixFlagsIdx], err) 144 return nil, fmt.Errorf("failed to parse flags(%s): %v", fields[3], err)
160 } 145 }
161 typ, err := u.parseType(fields[netUnixTypeIdx]) 146
147 typ, err := u.parseType(fields[4])
162 if err != nil { 148 if err != nil {
163 return nil, fmt.Errorf("Parse Unix domain type(%s) failed: %s", fields[netUnixTypeIdx], err) 149 return nil, fmt.Errorf("failed to parse type(%s): %v", fields[4], err)
164 } 150 }
165 state, err := u.parseState(fields[netUnixStateIdx]) 151
152 state, err := u.parseState(fields[5])
166 if err != nil { 153 if err != nil {
167 return nil, fmt.Errorf("Parse Unix domain state(%s) failed: %s", fields[netUnixStateIdx], err) 154 return nil, fmt.Errorf("failed to parse state(%s): %v", fields[5], err)
168 } 155 }
156
169 var inode uint64 157 var inode uint64
170 if hasInode { 158 if hasInode {
171 inodeStr := fields[netUnixInodeIdx] 159 inode, err = u.parseInode(fields[6])
172 inode, err = u.parseInode(inodeStr)
173 if err != nil { 160 if err != nil {
174 return nil, fmt.Errorf("Parse Unix domain inode(%s) failed: %s", inodeStr, err) 161 return nil, fmt.Errorf("failed to parse inode(%s): %v", fields[6], err)
175 } 162 }
176 } 163 }
177 164
178 nuLine := &NetUnixLine{ 165 n := &NetUNIXLine{
179 KernelPtr: kernelPtr, 166 KernelPtr: kernelPtr,
180 RefCount: users, 167 RefCount: users,
181 Type: typ, 168 Type: typ,
@@ -185,57 +172,56 @@ func (u *NetUnix) parseLine(line string, hasInode bool, minFieldsCnt int) (*NetU
185 } 172 }
186 173
187 // Path field is optional. 174 // Path field is optional.
188 if fieldsLen > minFieldsCnt { 175 if l > min {
189 pathIdx := netUnixInodeIdx + 1 176 // Path occurs at either index 6 or 7 depending on whether inode is
177 // already present.
178 pathIdx := 7
190 if !hasInode { 179 if !hasInode {
191 pathIdx-- 180 pathIdx--
192 } 181 }
193 nuLine.Path = fields[pathIdx]
194 }
195
196 return nuLine, nil
197}
198 182
199func (u NetUnix) parseKernelPtr(str string) (string, error) { 183 n.Path = fields[pathIdx]
200 if !strings.HasSuffix(str, ":") {
201 return "", errInvalidKernelPtrFmt
202 } 184 }
203 return str[:len(str)-1], nil 185
186 return n, nil
204} 187}
205 188
206func (u NetUnix) parseUsers(hexStr string) (uint64, error) { 189func (u NetUNIX) parseUsers(s string) (uint64, error) {
207 return strconv.ParseUint(hexStr, 16, 32) 190 return strconv.ParseUint(s, 16, 32)
208} 191}
209 192
210func (u NetUnix) parseType(hexStr string) (NetUnixType, error) { 193func (u NetUNIX) parseType(s string) (NetUNIXType, error) {
211 typ, err := strconv.ParseUint(hexStr, 16, 16) 194 typ, err := strconv.ParseUint(s, 16, 16)
212 if err != nil { 195 if err != nil {
213 return 0, err 196 return 0, err
214 } 197 }
215 return NetUnixType(typ), nil 198
199 return NetUNIXType(typ), nil
216} 200}
217 201
218func (u NetUnix) parseFlags(hexStr string) (NetUnixFlags, error) { 202func (u NetUNIX) parseFlags(s string) (NetUNIXFlags, error) {
219 flags, err := strconv.ParseUint(hexStr, 16, 32) 203 flags, err := strconv.ParseUint(s, 16, 32)
220 if err != nil { 204 if err != nil {
221 return 0, err 205 return 0, err
222 } 206 }
223 return NetUnixFlags(flags), nil 207
208 return NetUNIXFlags(flags), nil
224} 209}
225 210
226func (u NetUnix) parseState(hexStr string) (NetUnixState, error) { 211func (u NetUNIX) parseState(s string) (NetUNIXState, error) {
227 st, err := strconv.ParseInt(hexStr, 16, 8) 212 st, err := strconv.ParseInt(s, 16, 8)
228 if err != nil { 213 if err != nil {
229 return 0, err 214 return 0, err
230 } 215 }
231 return NetUnixState(st), nil 216
217 return NetUNIXState(st), nil
232} 218}
233 219
234func (u NetUnix) parseInode(inodeStr string) (uint64, error) { 220func (u NetUNIX) parseInode(s string) (uint64, error) {
235 return strconv.ParseUint(inodeStr, 10, 64) 221 return strconv.ParseUint(s, 10, 64)
236} 222}
237 223
238func (t NetUnixType) String() string { 224func (t NetUNIXType) String() string {
239 switch t { 225 switch t {
240 case netUnixTypeStream: 226 case netUnixTypeStream:
241 return "stream" 227 return "stream"
@@ -247,7 +233,7 @@ func (t NetUnixType) String() string {
247 return "unknown" 233 return "unknown"
248} 234}
249 235
250func (f NetUnixFlags) String() string { 236func (f NetUNIXFlags) String() string {
251 switch f { 237 switch f {
252 case netUnixFlagListen: 238 case netUnixFlagListen:
253 return "listen" 239 return "listen"
@@ -256,7 +242,7 @@ func (f NetUnixFlags) String() string {
256 } 242 }
257} 243}
258 244
259func (s NetUnixState) String() string { 245func (s NetUNIXState) String() string {
260 switch s { 246 switch s {
261 case netUnixStateUnconnected: 247 case netUnixStateUnconnected:
262 return "unconnected" 248 return "unconnected"
diff --git a/vendor/github.com/prometheus/procfs/proc_status.go b/vendor/github.com/prometheus/procfs/proc_status.go
index e30c2b8..17b4516 100644
--- a/vendor/github.com/prometheus/procfs/proc_status.go
+++ b/vendor/github.com/prometheus/procfs/proc_status.go
@@ -71,6 +71,9 @@ type ProcStatus struct {
71 VoluntaryCtxtSwitches uint64 71 VoluntaryCtxtSwitches uint64
72 // Number of involuntary context switches. 72 // Number of involuntary context switches.
73 NonVoluntaryCtxtSwitches uint64 73 NonVoluntaryCtxtSwitches uint64
74
75 // UIDs of the process (Real, effective, saved set, and filesystem UIDs (GIDs))
76 UIDs [4]string
74} 77}
75 78
76// NewStatus returns the current status information of the process. 79// NewStatus returns the current status information of the process.
@@ -114,6 +117,8 @@ func (s *ProcStatus) fillStatus(k string, vString string, vUint uint64, vUintByt
114 s.TGID = int(vUint) 117 s.TGID = int(vUint)
115 case "Name": 118 case "Name":
116 s.Name = vString 119 s.Name = vString
120 case "Uid":
121 copy(s.UIDs[:], strings.Split(vString, "\t"))
117 case "VmPeak": 122 case "VmPeak":
118 s.VmPeak = vUintBytes 123 s.VmPeak = vUintBytes
119 case "VmSize": 124 case "VmSize":
diff --git a/vendor/github.com/prometheus/procfs/swaps.go b/vendor/github.com/prometheus/procfs/swaps.go
new file mode 100644
index 0000000..15edc22
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/swaps.go
@@ -0,0 +1,89 @@
1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17 "bufio"
18 "bytes"
19 "fmt"
20 "strconv"
21 "strings"
22
23 "github.com/prometheus/procfs/internal/util"
24)
25
26// Swap represents an entry in /proc/swaps.
27type Swap struct {
28 Filename string
29 Type string
30 Size int
31 Used int
32 Priority int
33}
34
35// Swaps returns a slice of all configured swap devices on the system.
36func (fs FS) Swaps() ([]*Swap, error) {
37 data, err := util.ReadFileNoStat(fs.proc.Path("swaps"))
38 if err != nil {
39 return nil, err
40 }
41 return parseSwaps(data)
42}
43
44func parseSwaps(info []byte) ([]*Swap, error) {
45 swaps := []*Swap{}
46 scanner := bufio.NewScanner(bytes.NewReader(info))
47 scanner.Scan() // ignore header line
48 for scanner.Scan() {
49 swapString := scanner.Text()
50 parsedSwap, err := parseSwapString(swapString)
51 if err != nil {
52 return nil, err
53 }
54 swaps = append(swaps, parsedSwap)
55 }
56
57 err := scanner.Err()
58 return swaps, err
59}
60
61func parseSwapString(swapString string) (*Swap, error) {
62 var err error
63
64 swapFields := strings.Fields(swapString)
65 swapLength := len(swapFields)
66 if swapLength < 5 {
67 return nil, fmt.Errorf("too few fields in swap string: %s", swapString)
68 }
69
70 swap := &Swap{
71 Filename: swapFields[0],
72 Type: swapFields[1],
73 }
74
75 swap.Size, err = strconv.Atoi(swapFields[2])
76 if err != nil {
77 return nil, fmt.Errorf("invalid swap size: %s", swapFields[2])
78 }
79 swap.Used, err = strconv.Atoi(swapFields[3])
80 if err != nil {
81 return nil, fmt.Errorf("invalid swap used: %s", swapFields[3])
82 }
83 swap.Priority, err = strconv.Atoi(swapFields[4])
84 if err != nil {
85 return nil, fmt.Errorf("invalid swap priority: %s", swapFields[4])
86 }
87
88 return swap, nil
89}
diff --git a/vendor/github.com/prometheus/procfs/sysfs/class_infiniband.go b/vendor/github.com/prometheus/procfs/sysfs/class_infiniband.go
index 9156474..0eab1eb 100644
--- a/vendor/github.com/prometheus/procfs/sysfs/class_infiniband.go
+++ b/vendor/github.com/prometheus/procfs/sysfs/class_infiniband.go
@@ -97,7 +97,7 @@ func (fs FS) InfiniBandClass() (InfiniBandClass, error) {
97 97
98 dirs, err := ioutil.ReadDir(path) 98 dirs, err := ioutil.ReadDir(path)
99 if err != nil { 99 if err != nil {
100 return nil, fmt.Errorf("failed to list InfiniBand devices at %q: %v", path, err) 100 return nil, err
101 } 101 }
102 102
103 ibc := make(InfiniBandClass, len(dirs)) 103 ibc := make(InfiniBandClass, len(dirs))
diff --git a/vendor/github.com/prometheus/procfs/xfs/parse.go b/vendor/github.com/prometheus/procfs/xfs/parse.go
index 9781446..ba3afea 100644
--- a/vendor/github.com/prometheus/procfs/xfs/parse.go
+++ b/vendor/github.com/prometheus/procfs/xfs/parse.go
@@ -381,11 +381,15 @@ func extendedPrecisionStats(us []uint64) (ExtendedPrecisionStats, error) {
381} 381}
382 382
383func quotaManagerStats(us []uint32) (QuotaManagerStats, error) { 383func quotaManagerStats(us []uint32) (QuotaManagerStats, error) {
384 if l := len(us); l != 8 { 384 // The "Unused" attribute first appears in Linux 4.20
385 // As a result either 8 or 9 elements may appear in this slice depending on
386 // the kernel version.
387 l := len(us)
388 if l != 8 && l != 9 {
385 return QuotaManagerStats{}, fmt.Errorf("incorrect number of values for XFS quota stats: %d", l) 389 return QuotaManagerStats{}, fmt.Errorf("incorrect number of values for XFS quota stats: %d", l)
386 } 390 }
387 391
388 return QuotaManagerStats{ 392 s := QuotaManagerStats{
389 Reclaims: us[0], 393 Reclaims: us[0],
390 ReclaimMisses: us[1], 394 ReclaimMisses: us[1],
391 DquoteDups: us[2], 395 DquoteDups: us[2],
@@ -394,7 +398,13 @@ func quotaManagerStats(us []uint32) (QuotaManagerStats, error) {
394 Wants: us[5], 398 Wants: us[5],
395 ShakeReclaims: us[6], 399 ShakeReclaims: us[6],
396 InactReclaims: us[7], 400 InactReclaims: us[7],
397 }, nil 401 }
402
403 if l > 8 {
404 s.Unused = us[8]
405 }
406
407 return s, nil
398} 408}
399 409
400func debugStats(us []uint32) (DebugStats, error) { 410func debugStats(us []uint32) (DebugStats, error) {
diff --git a/vendor/github.com/prometheus/procfs/xfs/xfs.go b/vendor/github.com/prometheus/procfs/xfs/xfs.go
index 018a0b8..cc8b36b 100644
--- a/vendor/github.com/prometheus/procfs/xfs/xfs.go
+++ b/vendor/github.com/prometheus/procfs/xfs/xfs.go
@@ -202,6 +202,7 @@ type QuotaManagerStats struct {
202 Wants uint32 202 Wants uint32
203 ShakeReclaims uint32 203 ShakeReclaims uint32
204 InactReclaims uint32 204 InactReclaims uint32
205 Unused uint32
205} 206}
206 207
207// XstratStats contains statistics regarding bytes processed by the XFS daemon. 208// XstratStats contains statistics regarding bytes processed by the XFS daemon.
diff --git a/vendor/modules.txt b/vendor/modules.txt
index b81ffcb..760eaac 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -53,7 +53,7 @@ github.com/prometheus/common/model
53github.com/prometheus/common/promlog 53github.com/prometheus/common/promlog
54github.com/prometheus/common/promlog/flag 54github.com/prometheus/common/promlog/flag
55github.com/prometheus/common/version 55github.com/prometheus/common/version
56# github.com/prometheus/procfs v0.0.8 56# github.com/prometheus/procfs v0.0.10
57github.com/prometheus/procfs 57github.com/prometheus/procfs
58github.com/prometheus/procfs/bcache 58github.com/prometheus/procfs/bcache
59github.com/prometheus/procfs/internal/fs 59github.com/prometheus/procfs/internal/fs