From 9ef84dcdea1e597e3a15daa457467931387511ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zlatko=20=C4=8Calu=C5=A1i=C4=87?= Date: Sun, 21 Jan 2018 19:43:52 +0100 Subject: [PATCH] Update dependencies --- Gopkg.lock | 40 ++-- .../golang/protobuf/jsonpb/jsonpb.go | 3 +- .../golang/protobuf/jsonpb/jsonpb_test.go | 1 + .../github.com/gorilla/handlers/.travis.yml | 2 + vendor/github.com/gorilla/handlers/cors.go | 12 +- .../github.com/gorilla/handlers/cors_test.go | 37 +++- .../miolini/datacounter/response_writer.go | 13 +- .../prometheus/client_model/Makefile | 1 + .../prometheus/common/config/http_config.go | 10 +- .../common/config/http_config_test.go | 2 +- .../github.com/prometheus/common/log/log.go | 4 +- .../prometheus/common/model/time.go | 3 + .../prometheus/common/model/time_test.go | 3 + .../github.com/prometheus/procfs/.travis.yml | 8 +- .../prometheus/procfs/bcache/get.go | 8 +- .../prometheus/procfs/bcache/get_test.go | 20 +- .../github.com/prometheus/procfs/buddyinfo.go | 2 +- .../prometheus/procfs/fixtures/26231/net/dev | 4 + .../prometheus/procfs/fixtures/26231/ns/mnt | 1 + .../prometheus/procfs/fixtures/26231/ns/net | 1 + .../prometheus/procfs/fixtures/net/dev | 6 + vendor/github.com/prometheus/procfs/ipvs.go | 10 +- .../github.com/prometheus/procfs/net_dev.go | 203 ++++++++++++++++++ .../prometheus/procfs/net_dev_test.go | 73 +++++++ .../github.com/prometheus/procfs/proc_io.go | 5 +- .../github.com/prometheus/procfs/proc_ns.go | 55 +++++ .../prometheus/procfs/proc_ns_test.go | 31 +++ 27 files changed, 507 insertions(+), 51 deletions(-) create mode 100644 vendor/github.com/prometheus/procfs/fixtures/26231/net/dev create mode 120000 vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt create mode 120000 vendor/github.com/prometheus/procfs/fixtures/26231/ns/net create mode 100644 vendor/github.com/prometheus/procfs/fixtures/net/dev create mode 100644 vendor/github.com/prometheus/procfs/net_dev.go create mode 100644 vendor/github.com/prometheus/procfs/net_dev_test.go create mode 100644 vendor/github.com/prometheus/procfs/proc_ns.go create mode 100644 vendor/github.com/prometheus/procfs/proc_ns_test.go diff --git a/Gopkg.lock b/Gopkg.lock index b2df5e8..edf3c0c 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -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" diff --git a/vendor/github.com/golang/protobuf/jsonpb/jsonpb.go b/vendor/github.com/golang/protobuf/jsonpb/jsonpb.go index 110ae13..dfdfc5b 100644 --- a/vendor/github.com/golang/protobuf/jsonpb/jsonpb.go +++ b/vendor/github.com/golang/protobuf/jsonpb/jsonpb.go @@ -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(`"`) diff --git a/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go b/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go index 2428d05..4fdbde1 100644 --- a/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go +++ b/vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go @@ -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"}}, diff --git a/vendor/github.com/gorilla/handlers/.travis.yml b/vendor/github.com/gorilla/handlers/.travis.yml index 4ea1e7a..1ba74af 100644 --- a/vendor/github.com/gorilla/handlers/.travis.yml +++ b/vendor/github.com/gorilla/handlers/.travis.yml @@ -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 ./... + diff --git a/vendor/github.com/gorilla/handlers/cors.go b/vendor/github.com/gorilla/handlers/cors.go index 1f92d1a..1cf7581 100644 --- a/vendor/github.com/gorilla/handlers/cors.go +++ b/vendor/github.com/gorilla/handlers/cors.go @@ -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 diff --git a/vendor/github.com/gorilla/handlers/cors_test.go b/vendor/github.com/gorilla/handlers/cors_test.go index c63913e..61eb18f 100644 --- a/vendor/github.com/gorilla/handlers/cors_test.go +++ b/vendor/github.com/gorilla/handlers/cors_test.go @@ -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) + } + +} diff --git a/vendor/github.com/miolini/datacounter/response_writer.go b/vendor/github.com/miolini/datacounter/response_writer.go index ab6efc7..13a3699 100644 --- a/vendor/github.com/miolini/datacounter/response_writer.go +++ b/vendor/github.com/miolini/datacounter/response_writer.go @@ -2,22 +2,26 @@ package datacounter import ( "bufio" + "fmt" "net" "net/http" "sync/atomic" + "time" ) // ResponseWriterCounter is counter for http.ResponseWriter type ResponseWriterCounter struct { http.ResponseWriter - count uint64 - writer http.ResponseWriter + count uint64 + started time.Time + writer http.ResponseWriter } // NewResponseWriterCounter function create new ResponseWriterCounter 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 +} diff --git a/vendor/github.com/prometheus/client_model/Makefile b/vendor/github.com/prometheus/client_model/Makefile index 9cc23b3..e147c69 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 ff5837f..ea231bf 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 1e2490b..4b13e10 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/log/log.go b/vendor/github.com/prometheus/common/log/log.go index c167fff..1088302 100644 --- a/vendor/github.com/prometheus/common/log/log.go +++ b/vendor/github.com/prometheus/common/log/log.go @@ -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) diff --git a/vendor/github.com/prometheus/common/model/time.go b/vendor/github.com/prometheus/common/model/time.go index 7e87f1a..74ed5a9 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 45ffd87..3efdd65 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 ee09bb7..0dc4212 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 4d56f3d..b6d97de 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 38c3df5..1d41a5a 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 680a984..d3a8268 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 0000000..f108955 --- /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 0000000..9c52ca2 --- /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 0000000..1f0f795 --- /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 0000000..2df786f --- /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 696d114..5761b45 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 0000000..f8c184e --- /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 0000000..a69d8b9 --- /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 b4e31d7..e7f6674 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 0000000..befdd26 --- /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 0000000..aea3f6a --- /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) + } + } +}