summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/prometheus
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/prometheus')
-rw-r--r--vendor/github.com/prometheus/client_model/Makefile1
-rw-r--r--vendor/github.com/prometheus/common/config/http_config.go10
-rw-r--r--vendor/github.com/prometheus/common/config/http_config_test.go2
-rw-r--r--vendor/github.com/prometheus/common/model/time.go3
-rw-r--r--vendor/github.com/prometheus/common/model/time_test.go3
-rw-r--r--vendor/github.com/prometheus/procfs/.travis.yml8
-rw-r--r--vendor/github.com/prometheus/procfs/bcache/get.go8
-rw-r--r--vendor/github.com/prometheus/procfs/bcache/get_test.go20
-rw-r--r--vendor/github.com/prometheus/procfs/buddyinfo.go2
-rw-r--r--vendor/github.com/prometheus/procfs/fixtures/26231/net/dev4
l---------vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt1
l---------vendor/github.com/prometheus/procfs/fixtures/26231/ns/net1
-rw-r--r--vendor/github.com/prometheus/procfs/fixtures/net/dev6
-rw-r--r--vendor/github.com/prometheus/procfs/ipvs.go10
-rw-r--r--vendor/github.com/prometheus/procfs/net_dev.go203
-rw-r--r--vendor/github.com/prometheus/procfs/net_dev_test.go73
-rw-r--r--vendor/github.com/prometheus/procfs/proc_io.go5
-rw-r--r--vendor/github.com/prometheus/procfs/proc_ns.go55
-rw-r--r--vendor/github.com/prometheus/procfs/proc_ns_test.go31
19 files changed, 415 insertions, 31 deletions
diff --git a/vendor/github.com/prometheus/client_model/Makefile b/vendor/github.com/prometheus/client_model/Makefile
index 9cc23b340..e147c69da 100644
--- a/vendor/github.com/prometheus/client_model/Makefile
+++ b/vendor/github.com/prometheus/client_model/Makefile
@@ -39,6 +39,7 @@ src/main/java/io/prometheus/client/Metrics.java: metrics.proto
python: python/prometheus/client/model/metrics_pb2.py
python/prometheus/client/model/metrics_pb2.py: metrics.proto
+ mkdir -p python/prometheus/client/model
protoc $< --python_out=python/prometheus/client/model
ruby:
diff --git a/vendor/github.com/prometheus/common/config/http_config.go b/vendor/github.com/prometheus/common/config/http_config.go
index ff5837fa5..ea231bf8d 100644
--- a/vendor/github.com/prometheus/common/config/http_config.go
+++ b/vendor/github.com/prometheus/common/config/http_config.go
@@ -22,7 +22,7 @@ import (
"net/url"
"strings"
- yaml "gopkg.in/yaml.v2"
+ "gopkg.in/yaml.v2"
)
// BasicAuth contains basic HTTP authentication credentials.
@@ -79,7 +79,9 @@ type HTTPClientConfig struct {
XXX map[string]interface{} `yaml:",inline"`
}
-func (c *HTTPClientConfig) validate() error {
+// Validate validates the HTTPClientConfig to check only one of BearerToken,
+// BasicAuth and BearerTokenFile is configured.
+func (c *HTTPClientConfig) Validate() error {
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")
}
@@ -96,9 +98,9 @@ func (c *HTTPClientConfig) UnmarshalYAML(unmarshal func(interface{}) error) erro
if err != nil {
return err
}
- err = c.validate()
+ err = c.Validate()
if err != nil {
- return c.validate()
+ return c.Validate()
}
return checkOverflow(c.XXX, "http_client_config")
}
diff --git a/vendor/github.com/prometheus/common/config/http_config_test.go b/vendor/github.com/prometheus/common/config/http_config_test.go
index 1e2490bbb..4b13e101b 100644
--- a/vendor/github.com/prometheus/common/config/http_config_test.go
+++ b/vendor/github.com/prometheus/common/config/http_config_test.go
@@ -114,7 +114,7 @@ func TestValidateHTTPConfig(t *testing.T) {
if err != nil {
t.Errorf("Error loading HTTP client config: %v", err)
}
- err = cfg.validate()
+ err = cfg.Validate()
if err != nil {
t.Fatalf("Error validating %s: %s", "testdata/http.conf.good.yml", err)
}
diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go
index 7e87f1ac6..74ed5a9f7 100644
--- a/vendor/github.com/prometheus/common/model/time.go
+++ b/vendor/github.com/prometheus/common/model/time.go
@@ -214,6 +214,9 @@ func (d Duration) String() string {
ms = int64(time.Duration(d) / time.Millisecond)
unit = "ms"
)
+ if ms == 0 {
+ return "0s"
+ }
factors := map[string]int64{
"y": 1000 * 60 * 60 * 24 * 365,
"w": 1000 * 60 * 60 * 24 * 7,
diff --git a/vendor/github.com/prometheus/common/model/time_test.go b/vendor/github.com/prometheus/common/model/time_test.go
index 45ffd872d..3efdd65ff 100644
--- a/vendor/github.com/prometheus/common/model/time_test.go
+++ b/vendor/github.com/prometheus/common/model/time_test.go
@@ -91,6 +91,9 @@ func TestParseDuration(t *testing.T) {
out time.Duration
}{
{
+ in: "0s",
+ out: 0,
+ }, {
in: "324ms",
out: 324 * time.Millisecond,
}, {
diff --git a/vendor/github.com/prometheus/procfs/.travis.yml b/vendor/github.com/prometheus/procfs/.travis.yml
index ee09bb733..0dc42122b 100644
--- a/vendor/github.com/prometheus/procfs/.travis.yml
+++ b/vendor/github.com/prometheus/procfs/.travis.yml
@@ -1,5 +1,9 @@
sudo: false
+
language: go
+
go:
- - 1.7.6
- - 1.8.3
+- 1.9.x
+- 1.x
+
+go_import_path: github.com/prometheus/procfs
diff --git a/vendor/github.com/prometheus/procfs/bcache/get.go b/vendor/github.com/prometheus/procfs/bcache/get.go
index 4d56f3d98..b6d97de15 100644
--- a/vendor/github.com/prometheus/procfs/bcache/get.go
+++ b/vendor/github.com/prometheus/procfs/bcache/get.go
@@ -61,7 +61,7 @@ func dehumanize(hbytes []byte) (uint64, error) {
mul := float64(1)
var (
mant float64
- err error
+ err error
)
// If lastByte is beyond the range of ASCII digits, it must be a
// multiplier.
@@ -93,7 +93,7 @@ func dehumanize(hbytes []byte) (uint64, error) {
'Z': ZiB,
'Y': YiB,
}
- mul = float64(multipliers[rune(lastByte)])
+ mul = multipliers[rune(lastByte)]
mant, err = parsePseudoFloat(string(hbytes))
if err != nil {
return 0, err
@@ -139,10 +139,10 @@ func (p *parser) readValue(fileName string) uint64 {
}
// ParsePriorityStats parses lines from the priority_stats file.
-func parsePriorityStats(line string, ps *PriorityStats) (error) {
+func parsePriorityStats(line string, ps *PriorityStats) error {
var (
value uint64
- err error
+ err error
)
switch {
case strings.HasPrefix(line, "Unused:"):
diff --git a/vendor/github.com/prometheus/procfs/bcache/get_test.go b/vendor/github.com/prometheus/procfs/bcache/get_test.go
index 38c3df573..1d41a5ad3 100644
--- a/vendor/github.com/prometheus/procfs/bcache/get_test.go
+++ b/vendor/github.com/prometheus/procfs/bcache/get_test.go
@@ -14,8 +14,8 @@
package bcache
import (
- "testing"
"math"
+ "testing"
)
func TestDehumanizeTests(t *testing.T) {
@@ -45,8 +45,8 @@ func TestDehumanizeTests(t *testing.T) {
out: 2024,
},
{
- in: []byte(""),
- out: 0,
+ in: []byte(""),
+ out: 0,
invalid: true,
},
}
@@ -59,7 +59,7 @@ func TestDehumanizeTests(t *testing.T) {
t.Errorf("unexpected error: %v", err)
}
if got != tst.out {
- t.Errorf("dehumanize: '%s', want %f, got %f", tst.in, tst.out, got)
+ t.Errorf("dehumanize: '%s', want %d, got %d", tst.in, tst.out, got)
}
}
}
@@ -84,7 +84,7 @@ func TestParsePseudoFloatTests(t *testing.T) {
}
for _, tst := range parsePseudoFloatTests {
got, err := parsePseudoFloat(tst.in)
- if err != nil || math.Abs(got - tst.out) > 0.0001 {
+ if err != nil || math.Abs(got-tst.out) > 0.0001 {
t.Errorf("parsePseudoFloat: %s, want %f, got %f", tst.in, tst.out, got)
}
}
@@ -92,23 +92,23 @@ func TestParsePseudoFloatTests(t *testing.T) {
func TestPriorityStats(t *testing.T) {
var want = PriorityStats{
- UnusedPercent: 99,
+ UnusedPercent: 99,
MetadataPercent: 5,
}
var (
- in string
+ in string
gotErr error
- got PriorityStats
+ got PriorityStats
)
in = "Metadata: 5%"
gotErr = parsePriorityStats(in, &got)
if gotErr != nil || got.MetadataPercent != want.MetadataPercent {
- t.Errorf("parsePriorityStats: '%s', want %f, got %f", in, want.MetadataPercent, got.MetadataPercent)
+ t.Errorf("parsePriorityStats: '%s', want %d, got %d", in, want.MetadataPercent, got.MetadataPercent)
}
in = "Unused: 99%"
gotErr = parsePriorityStats(in, &got)
if gotErr != nil || got.UnusedPercent != want.UnusedPercent {
- t.Errorf("parsePriorityStats: '%s', want %f, got %f", in, want.UnusedPercent, got.UnusedPercent)
+ t.Errorf("parsePriorityStats: '%s', want %d, got %d", in, want.UnusedPercent, got.UnusedPercent)
}
}
diff --git a/vendor/github.com/prometheus/procfs/buddyinfo.go b/vendor/github.com/prometheus/procfs/buddyinfo.go
index 680a9842a..d3a826807 100644
--- a/vendor/github.com/prometheus/procfs/buddyinfo.go
+++ b/vendor/github.com/prometheus/procfs/buddyinfo.go
@@ -62,7 +62,7 @@ func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) {
for scanner.Scan() {
var err error
line := scanner.Text()
- parts := strings.Fields(string(line))
+ parts := strings.Fields(line)
if len(parts) < 4 {
return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo")
diff --git a/vendor/github.com/prometheus/procfs/fixtures/26231/net/dev b/vendor/github.com/prometheus/procfs/fixtures/26231/net/dev
new file mode 100644
index 000000000..f10895560
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/fixtures/26231/net/dev
@@ -0,0 +1,4 @@
+Inter-| Receive | Transmit
+ face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
+ lo: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ eth0: 438 5 0 0 0 0 0 0 648 8 0 0 0 0 0 0
diff --git a/vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt b/vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt
new file mode 120000
index 000000000..9c52ca211
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt
@@ -0,0 +1 @@
+mnt:[4026531840] \ No newline at end of file
diff --git a/vendor/github.com/prometheus/procfs/fixtures/26231/ns/net b/vendor/github.com/prometheus/procfs/fixtures/26231/ns/net
new file mode 120000
index 000000000..1f0f79594
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/fixtures/26231/ns/net
@@ -0,0 +1 @@
+net:[4026531993] \ No newline at end of file
diff --git a/vendor/github.com/prometheus/procfs/fixtures/net/dev b/vendor/github.com/prometheus/procfs/fixtures/net/dev
new file mode 100644
index 000000000..2df786fa5
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/fixtures/net/dev
@@ -0,0 +1,6 @@
+Inter-| Receive | Transmit
+ face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
+vethf345468: 648 8 0 0 0 0 0 0 438 5 0 0 0 0 0 0
+ lo: 1664039048 1566805 0 0 0 0 0 0 1664039048 1566805 0 0 0 0 0 0
+docker0: 2568 38 0 0 0 0 0 0 438 5 0 0 0 0 0 0
+ eth0: 874354587 1036395 0 0 0 0 0 0 563352563 732147 0 0 0 0 0 0
diff --git a/vendor/github.com/prometheus/procfs/ipvs.go b/vendor/github.com/prometheus/procfs/ipvs.go
index 696d114e7..5761b4570 100644
--- a/vendor/github.com/prometheus/procfs/ipvs.go
+++ b/vendor/github.com/prometheus/procfs/ipvs.go
@@ -31,16 +31,16 @@ type IPVSStats struct {
type IPVSBackendStatus struct {
// The local (virtual) IP address.
LocalAddress net.IP
+ // The remote (real) IP address.
+ RemoteAddress net.IP
// The local (virtual) port.
LocalPort uint16
+ // The remote (real) port.
+ RemotePort uint16
// The local firewall mark
LocalMark string
// The transport protocol (TCP, UDP).
Proto string
- // The remote (real) IP address.
- RemoteAddress net.IP
- // The remote (real) port.
- RemotePort uint16
// The current number of active connections for this virtual/real address pair.
ActiveConn uint64
// The current number of inactive connections for this virtual/real address pair.
@@ -151,7 +151,7 @@ func parseIPVSBackendStatus(file io.Reader) ([]IPVSBackendStatus, error) {
)
for scanner.Scan() {
- fields := strings.Fields(string(scanner.Text()))
+ fields := strings.Fields(scanner.Text())
if len(fields) == 0 {
continue
}
diff --git a/vendor/github.com/prometheus/procfs/net_dev.go b/vendor/github.com/prometheus/procfs/net_dev.go
new file mode 100644
index 000000000..f8c184efe
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/net_dev.go
@@ -0,0 +1,203 @@
+package procfs
+
+import (
+ "bufio"
+ "errors"
+ "os"
+ "sort"
+ "strconv"
+ "strings"
+)
+
+// NetDevLine is single line parsed from /proc/net/dev or /proc/[pid]/net/dev.
+type NetDevLine struct {
+ Name string `json:"name"` // The name of the interface.
+ RxBytes uint64 `json:"rx_bytes"` // Cumulative count of bytes received.
+ RxPackets uint64 `json:"rx_packets"` // Cumulative count of packets received.
+ RxErrors uint64 `json:"rx_errors"` // Cumulative count of receive errors encountered.
+ RxDropped uint64 `json:"rx_dropped"` // Cumulative count of packets dropped while receiving.
+ RxFIFO uint64 `json:"rx_fifo"` // Cumulative count of FIFO buffer errors.
+ RxFrame uint64 `json:"rx_frame"` // Cumulative count of packet framing errors.
+ RxCompressed uint64 `json:"rx_compressed"` // Cumulative count of compressed packets received by the device driver.
+ RxMulticast uint64 `json:"rx_multicast"` // Cumulative count of multicast frames received by the device driver.
+ TxBytes uint64 `json:"tx_bytes"` // Cumulative count of bytes transmitted.
+ TxPackets uint64 `json:"tx_packets"` // Cumulative count of packets transmitted.
+ TxErrors uint64 `json:"tx_errors"` // Cumulative count of transmit errors encountered.
+ TxDropped uint64 `json:"tx_dropped"` // Cumulative count of packets dropped while transmitting.
+ TxFIFO uint64 `json:"tx_fifo"` // Cumulative count of FIFO buffer errors.
+ TxCollisions uint64 `json:"tx_collisions"` // Cumulative count of collisions detected on the interface.
+ TxCarrier uint64 `json:"tx_carrier"` // Cumulative count of carrier losses detected by the device driver.
+ TxCompressed uint64 `json:"tx_compressed"` // Cumulative count of compressed packets transmitted by the device driver.
+}
+
+// NetDev is parsed from /proc/net/dev or /proc/[pid]/net/dev. The map keys
+// are interface names.
+type NetDev map[string]NetDevLine
+
+// NewNetDev returns kernel/system statistics read from /proc/net/dev.
+func NewNetDev() (NetDev, error) {
+ fs, err := NewFS(DefaultMountPoint)
+ if err != nil {
+ return nil, err
+ }
+
+ return fs.NewNetDev()
+}
+
+// NewNetDev returns kernel/system statistics read from /proc/net/dev.
+func (fs FS) NewNetDev() (NetDev, error) {
+ return newNetDev(fs.Path("net/dev"))
+}
+
+// NewNetDev returns kernel/system statistics read from /proc/[pid]/net/dev.
+func (p Proc) NewNetDev() (NetDev, error) {
+ return newNetDev(p.path("net/dev"))
+}
+
+// newNetDev creates a new NetDev from the contents of the given file.
+func newNetDev(file string) (NetDev, error) {
+ f, err := os.Open(file)
+ if err != nil {
+ return NetDev{}, err
+ }
+ defer f.Close()
+
+ nd := NetDev{}
+ s := bufio.NewScanner(f)
+ for n := 0; s.Scan(); n++ {
+ // Skip the 2 header lines.
+ if n < 2 {
+ continue
+ }
+
+ line, err := nd.parseLine(s.Text())
+ if err != nil {
+ return nd, err
+ }
+
+ nd[line.Name] = *line
+ }
+
+ return nd, s.Err()
+}
+
+// parseLine parses a single line from the /proc/net/dev file. Header lines
+// must be filtered prior to calling this method.
+func (nd NetDev) parseLine(rawLine string) (*NetDevLine, error) {
+ parts := strings.SplitN(rawLine, ":", 2)
+ if len(parts) != 2 {
+ return nil, errors.New("invalid net/dev line, missing colon")
+ }
+ fields := strings.Fields(strings.TrimSpace(parts[1]))
+
+ var err error
+ line := &NetDevLine{}
+
+ // Interface Name
+ line.Name = strings.TrimSpace(parts[0])
+ if line.Name == "" {
+ return nil, errors.New("invalid net/dev line, empty interface name")
+ }
+
+ // RX
+ line.RxBytes, err = strconv.ParseUint(fields[0], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxPackets, err = strconv.ParseUint(fields[1], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxErrors, err = strconv.ParseUint(fields[2], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxDropped, err = strconv.ParseUint(fields[3], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxFIFO, err = strconv.ParseUint(fields[4], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxFrame, err = strconv.ParseUint(fields[5], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxCompressed, err = strconv.ParseUint(fields[6], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.RxMulticast, err = strconv.ParseUint(fields[7], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+
+ // TX
+ line.TxBytes, err = strconv.ParseUint(fields[8], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxPackets, err = strconv.ParseUint(fields[9], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxErrors, err = strconv.ParseUint(fields[10], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxDropped, err = strconv.ParseUint(fields[11], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxFIFO, err = strconv.ParseUint(fields[12], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxCollisions, err = strconv.ParseUint(fields[13], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxCarrier, err = strconv.ParseUint(fields[14], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+ line.TxCompressed, err = strconv.ParseUint(fields[15], 10, 64)
+ if err != nil {
+ return nil, err
+ }
+
+ return line, nil
+}
+
+// Total aggregates the values across interfaces and returns a new NetDevLine.
+// The Name field will be a sorted comma seperated list of interface names.
+func (nd NetDev) Total() NetDevLine {
+ total := NetDevLine{}
+
+ names := make([]string, 0, len(nd))
+ for _, ifc := range nd {
+ names = append(names, ifc.Name)
+ total.RxBytes += ifc.RxBytes
+ total.RxPackets += ifc.RxPackets
+ total.RxPackets += ifc.RxPackets
+ total.RxErrors += ifc.RxErrors
+ total.RxDropped += ifc.RxDropped
+ total.RxFIFO += ifc.RxFIFO
+ total.RxFrame += ifc.RxFrame
+ total.RxCompressed += ifc.RxCompressed
+ total.RxMulticast += ifc.RxMulticast
+ total.TxBytes += ifc.TxBytes
+ total.TxPackets += ifc.TxPackets
+ total.TxErrors += ifc.TxErrors
+ total.TxDropped += ifc.TxDropped
+ total.TxFIFO += ifc.TxFIFO
+ total.TxCollisions += ifc.TxCollisions
+ total.TxCarrier += ifc.TxCarrier
+ total.TxCompressed += ifc.TxCompressed
+ }
+ sort.Strings(names)
+ total.Name = strings.Join(names, ", ")
+
+ return total
+}
diff --git a/vendor/github.com/prometheus/procfs/net_dev_test.go b/vendor/github.com/prometheus/procfs/net_dev_test.go
new file mode 100644
index 000000000..a69d8b9b8
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/net_dev_test.go
@@ -0,0 +1,73 @@
+package procfs
+
+import (
+ "testing"
+)
+
+func TestNetDevParseLine(t *testing.T) {
+ const rawLine = ` eth0: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16`
+
+ have, err := NetDev{}.parseLine(rawLine)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ want := NetDevLine{"eth0", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
+ if want != *have {
+ t.Errorf("want %v, have %v", want, have)
+ }
+}
+
+func TestNewNetDev(t *testing.T) {
+ fs, err := NewFS("fixtures")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ nd, err := fs.NewNetDev()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ lines := map[string]NetDevLine{
+ "vethf345468": {Name: "vethf345468", RxBytes: 648, RxPackets: 8, TxBytes: 438, TxPackets: 5},
+ "lo": {Name: "lo", RxBytes: 1664039048, RxPackets: 1566805, TxBytes: 1664039048, TxPackets: 1566805},
+ "docker0": {Name: "docker0", RxBytes: 2568, RxPackets: 38, TxBytes: 438, TxPackets: 5},
+ "eth0": {Name: "eth0", RxBytes: 874354587, RxPackets: 1036395, TxBytes: 563352563, TxPackets: 732147},
+ }
+
+ if want, have := len(lines), len(nd); want != have {
+ t.Errorf("want %d parsed net/dev lines, have %d", want, have)
+ }
+ for _, line := range nd {
+ if want, have := lines[line.Name], line; want != have {
+ t.Errorf("%s: want %v, have %v", line.Name, want, have)
+ }
+ }
+}
+
+func TestProcNewNetDev(t *testing.T) {
+ p, err := FS("fixtures").NewProc(26231)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ nd, err := p.NewNetDev()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ lines := map[string]NetDevLine{
+ "lo": {Name: "lo"},
+ "eth0": {Name: "eth0", RxBytes: 438, RxPackets: 5, TxBytes: 648, TxPackets: 8},
+ }
+
+ if want, have := len(lines), len(nd); want != have {
+ t.Errorf("want %d parsed net/dev lines, have %d", want, have)
+ }
+ for _, line := range nd {
+ if want, have := lines[line.Name], line; want != have {
+ t.Errorf("%s: want %v, have %v", line.Name, want, have)
+ }
+ }
+}
diff --git a/vendor/github.com/prometheus/procfs/proc_io.go b/vendor/github.com/prometheus/procfs/proc_io.go
index b4e31d7ba..e7f6674d0 100644
--- a/vendor/github.com/prometheus/procfs/proc_io.go
+++ b/vendor/github.com/prometheus/procfs/proc_io.go
@@ -47,9 +47,6 @@ func (p Proc) NewIO() (ProcIO, error) {
_, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR,
&pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes)
- if err != nil {
- return pio, err
- }
- return pio, nil
+ return pio, err
}
diff --git a/vendor/github.com/prometheus/procfs/proc_ns.go b/vendor/github.com/prometheus/procfs/proc_ns.go
new file mode 100644
index 000000000..befdd2690
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/proc_ns.go
@@ -0,0 +1,55 @@
+package procfs
+
+import (
+ "fmt"
+ "os"
+ "strconv"
+ "strings"
+)
+
+// Namespace represents a single namespace of a process.
+type Namespace struct {
+ Type string // Namespace type.
+ Inode uint32 // Inode number of the namespace. If two processes are in the same namespace their inodes will match.
+}
+
+// Namespaces contains all of the namespaces that the process is contained in.
+type Namespaces map[string]Namespace
+
+// NewNamespaces reads from /proc/[pid/ns/* to get the namespaces of which the
+// process is a member.
+func (p Proc) NewNamespaces() (Namespaces, error) {
+ d, err := os.Open(p.path("ns"))
+ if err != nil {
+ return nil, err
+ }
+ defer d.Close()
+
+ names, err := d.Readdirnames(-1)
+ if err != nil {
+ return nil, fmt.Errorf("failed to read contents of ns dir: %v", err)
+ }
+
+ ns := make(Namespaces, len(names))
+ for _, name := range names {
+ target, err := os.Readlink(p.path("ns", name))
+ if err != nil {
+ return nil, err
+ }
+
+ fields := strings.SplitN(target, ":", 2)
+ if len(fields) != 2 {
+ return nil, fmt.Errorf("failed to parse namespace type and inode from '%v'", target)
+ }
+
+ typ := fields[0]
+ inode, err := strconv.ParseUint(strings.Trim(fields[1], "[]"), 10, 32)
+ if err != nil {
+ return nil, fmt.Errorf("failed to parse inode from '%v': %v", fields[1], err)
+ }
+
+ ns[name] = Namespace{typ, uint32(inode)}
+ }
+
+ return ns, nil
+}
diff --git a/vendor/github.com/prometheus/procfs/proc_ns_test.go b/vendor/github.com/prometheus/procfs/proc_ns_test.go
new file mode 100644
index 000000000..aea3f6a6c
--- /dev/null
+++ b/vendor/github.com/prometheus/procfs/proc_ns_test.go
@@ -0,0 +1,31 @@
+package procfs
+
+import (
+ "testing"
+)
+
+func TestNewNamespaces(t *testing.T) {
+ p, err := FS("fixtures").NewProc(26231)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ namespaces, err := p.NewNamespaces()
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ expectedNamespaces := map[string]Namespace{
+ "mnt": {"mnt", 4026531840},
+ "net": {"net", 4026531993},
+ }
+
+ if want, have := len(expectedNamespaces), len(namespaces); want != have {
+ t.Errorf("want %d parsed namespaces, have %d", want, have)
+ }
+ for _, ns := range namespaces {
+ if want, have := expectedNamespaces[ns.Type], ns; want != have {
+ t.Errorf("%s: want %v, have %v", ns.Type, want, have)
+ }
+ }
+}