Update dependencies

This commit is contained in:
Zlatko Čalušić 2018-01-21 19:43:52 +01:00
parent 0a5606e954
commit 9ef84dcdea
27 changed files with 507 additions and 51 deletions

40
Gopkg.lock generated
View file

@ -11,14 +11,14 @@
branch = "master"
name = "github.com/golang/protobuf"
packages = ["proto"]
revision = "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
revision = "1e59b77b52bf8e4b449a57e6f79f21226d571845"
[[projects]]
name = "github.com/gorilla/handlers"
packages = ["."]
revision = "a4043c62cc2329bacda331d33fc908ab11ef0ec3"
revision = "90663712d74cb411cbef281bc1e08c19d1a76145"
source = "https://github.com/gorilla/handlers"
version = "v1.2.1"
version = "v1.3.0"
[[projects]]
name = "github.com/inconshreveable/mousetrap"
@ -36,11 +36,14 @@
branch = "master"
name = "github.com/miolini/datacounter"
packages = ["."]
revision = "2fb1a1d5c3907155bbff63ad8b8a146ced61eba6"
revision = "fd4e42a1d5e0d2714f16caf92f9c64215bf957ce"
[[projects]]
name = "github.com/prometheus/client_golang"
packages = ["prometheus","prometheus/promhttp"]
packages = [
"prometheus",
"prometheus/promhttp"
]
revision = "c5b7fccd204277076155f10851dad72b76a49317"
version = "v0.8.0"
@ -48,25 +51,32 @@
branch = "master"
name = "github.com/prometheus/client_model"
packages = ["go"]
revision = "6f3806018612930941127f2a7c6c453ba2c527d2"
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
[[projects]]
branch = "master"
name = "github.com/prometheus/common"
packages = ["expfmt","internal/bitbucket.org/ww/goautoneg","model"]
revision = "1bab55dd05dbff384524a6a1c99006d9eb5f139b"
packages = [
"expfmt",
"internal/bitbucket.org/ww/goautoneg",
"model"
]
revision = "89604d197083d4781071d3c65855d24ecfb0a563"
[[projects]]
branch = "master"
name = "github.com/prometheus/procfs"
packages = [".","xfs"]
revision = "a6e9df898b1336106c743392c48ee0b71f5c4efa"
packages = [
".",
"xfs"
]
revision = "b15cd069a83443be3154b719d0cc9fe8117f09fb"
[[projects]]
branch = "master"
name = "github.com/spf13/cobra"
packages = ["."]
revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b"
version = "v0.0.1"
[[projects]]
name = "github.com/spf13/pflag"
@ -76,7 +86,13 @@
[[projects]]
name = "goji.io"
packages = [".","internal","middleware","pat","pattern"]
packages = [
".",
"internal",
"middleware",
"pat",
"pattern"
]
revision = "0d89ff54b2c18c9c4ba530e32496aef902d3c6cd"
source = "https://github.com/goji/goji"
version = "v2.0"

View file

@ -193,8 +193,7 @@ func (m *Marshaler) marshalObject(out *errWriter, v proto.Message, indent, typeU
// "Generated output always contains 3, 6, or 9 fractional digits,
// depending on required precision."
s, ns := s.Field(0).Int(), s.Field(1).Int()
d := time.Duration(s)*time.Second + time.Duration(ns)*time.Nanosecond
x := fmt.Sprintf("%.9f", d.Seconds())
x := fmt.Sprintf("%d.%09d", s, ns)
x = strings.TrimSuffix(x, "000")
x = strings.TrimSuffix(x, "000")
out.write(`"`)

View file

@ -407,6 +407,7 @@ var marshalingTests = []struct {
{"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON},
{"Any with WKT and indent", marshalerAllOptions, anyWellKnown, anyWellKnownPrettyJSON},
{"Duration", marshaler, &pb.KnownTypes{Dur: &durpb.Duration{Seconds: 3}}, `{"dur":"3.000s"}`},
{"Duration", marshaler, &pb.KnownTypes{Dur: &durpb.Duration{Seconds: 100000000, Nanos: 1}}, `{"dur":"100000000.000000001s"}`},
{"Struct", marshaler, &pb.KnownTypes{St: &stpb.Struct{
Fields: map[string]*stpb.Value{
"one": {Kind: &stpb.Value_StringValue{"loneliest number"}},

View file

@ -7,6 +7,7 @@ matrix:
- go: 1.5
- go: 1.6
- go: 1.7
- go: 1.8
- go: tip
allow_failures:
- go: tip
@ -16,3 +17,4 @@ script:
- diff -u <(echo -n) <(gofmt -d .)
- go vet $(go list ./... | grep -v /vendor/)
- go test -v -race ./...

View file

@ -110,7 +110,17 @@ func (ch *cors) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.Header().Set(corsVaryHeader, corsOriginHeader)
}
w.Header().Set(corsAllowOriginHeader, origin)
returnOrigin := origin
for _, o := range ch.allowedOrigins {
// A configuration of * is different than explicitly setting an allowed
// origin. Returning arbitrary origin headers an an access control allow
// origin header is unsafe and is not required by any use case.
if o == corsOriginMatchAll {
returnOrigin = "*"
break
}
}
w.Header().Set(corsAllowOriginHeader, returnOrigin)
if r.Method == corsOptionMethod {
return

View file

@ -327,10 +327,45 @@ func TestCORSHandlerWithCustomValidator(t *testing.T) {
return false
}
CORS(AllowedOriginValidator(originValidator))(testHandler).ServeHTTP(rr, r)
// Specially craft a CORS object.
handleFunc := func(h http.Handler) http.Handler {
c := &cors{
allowedMethods: defaultCorsMethods,
allowedHeaders: defaultCorsHeaders,
allowedOrigins: []string{"http://a.example.com"},
h: h,
}
AllowedOriginValidator(originValidator)(c)
return c
}
handleFunc(testHandler).ServeHTTP(rr, r)
header := rr.HeaderMap.Get(corsAllowOriginHeader)
if header != r.URL.String() {
t.Fatalf("bad header: expected %s to be %s, got %s.", corsAllowOriginHeader, r.URL.String(), header)
}
}
func TestCORSAllowStar(t *testing.T) {
r := newRequest("GET", "http://a.example.com")
r.Header.Set("Origin", r.URL.String())
rr := httptest.NewRecorder()
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {})
originValidator := func(origin string) bool {
if strings.HasSuffix(origin, ".example.com") {
return true
}
return false
}
CORS(AllowedOriginValidator(originValidator))(testHandler).ServeHTTP(rr, r)
header := rr.HeaderMap.Get(corsAllowOriginHeader)
// Because * is the default CORS policy (which is safe), we should be
// expect a * returned here as the Access Control Allow Origin header
if header != "*" {
t.Fatalf("bad header: expected %s to be %s, got %s.", corsAllowOriginHeader, r.URL.String(), header)
}
}

View file

@ -2,15 +2,18 @@ package datacounter
import (
"bufio"
"fmt"
"net"
"net/http"
"sync/atomic"
"time"
)
// ResponseWriterCounter is counter for http.ResponseWriter
type ResponseWriterCounter struct {
http.ResponseWriter
count uint64
started time.Time
writer http.ResponseWriter
}
@ -18,6 +21,7 @@ type ResponseWriterCounter struct {
func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
return &ResponseWriterCounter{
writer: rw,
started: time.Now(),
}
}
@ -32,6 +36,7 @@ func (counter *ResponseWriterCounter) Header() http.Header {
}
func (counter *ResponseWriterCounter) WriteHeader(statusCode int) {
counter.Header().Set("X-Runtime", fmt.Sprintf("%.6f", time.Since(counter.started).Seconds()))
counter.writer.WriteHeader(statusCode)
}
@ -43,3 +48,7 @@ func (counter *ResponseWriterCounter) Hijack() (net.Conn, *bufio.ReadWriter, err
func (counter *ResponseWriterCounter) Count() uint64 {
return atomic.LoadUint64(&counter.count)
}
func (counter *ResponseWriterCounter) Started() time.Time {
return counter.started
}

View file

@ -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:

View file

@ -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")
}

View file

@ -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)
}

View file

@ -56,11 +56,11 @@ func (s *loggerSettings) apply(ctx *kingpin.ParseContext) error {
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine)
func AddFlags(a *kingpin.Application) {
s := loggerSettings{}
kingpin.Flag("log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]").
a.Flag("log.level", "Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal]").
Default(origLogger.Level.String()).
StringVar(&s.level)
defaultFormat := url.URL{Scheme: "logger", Opaque: "stderr"}
kingpin.Flag("log.format", `Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"`).
a.Flag("log.format", `Set the log target and format. Example: "logger:syslog?appname=bob&local=7" or "logger:stdout?json=true"`).
Default(defaultFormat.String()).
StringVar(&s.format)
a.Action(s.apply)

View file

@ -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,

View file

@ -91,6 +91,9 @@ func TestParseDuration(t *testing.T) {
out time.Duration
}{
{
in: "0s",
out: 0,
}, {
in: "324ms",
out: 324 * time.Millisecond,
}, {

View file

@ -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

View file

@ -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,7 +139,7 @@ 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

View file

@ -14,8 +14,8 @@
package bcache
import (
"testing"
"math"
"testing"
)
func TestDehumanizeTests(t *testing.T) {
@ -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)
}
}
@ -103,12 +103,12 @@ func TestPriorityStats(t *testing.T) {
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)
}
}

View file

@ -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")

View file

@ -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

View file

@ -0,0 +1 @@
mnt:[4026531840]

View file

@ -0,0 +1 @@
net:[4026531993]

6
vendor/github.com/prometheus/procfs/fixtures/net/dev generated vendored Normal file
View file

@ -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

View file

@ -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
}

203
vendor/github.com/prometheus/procfs/net_dev.go generated vendored Normal file
View file

@ -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
}

73
vendor/github.com/prometheus/procfs/net_dev_test.go generated vendored Normal file
View file

@ -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)
}
}
}

View file

@ -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
}

55
vendor/github.com/prometheus/procfs/proc_ns.go generated vendored Normal file
View file

@ -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
}

31
vendor/github.com/prometheus/procfs/proc_ns_test.go generated vendored Normal file
View file

@ -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)
}
}
}