mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 15:43:21 +00:00
Update dependencies
This commit is contained in:
parent
0a5606e954
commit
9ef84dcdea
27 changed files with 507 additions and 51 deletions
40
Gopkg.lock
generated
40
Gopkg.lock
generated
|
@ -11,14 +11,14 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/golang/protobuf"
|
name = "github.com/golang/protobuf"
|
||||||
packages = ["proto"]
|
packages = ["proto"]
|
||||||
revision = "1643683e1b54a9e88ad26d98f81400c8c9d9f4f9"
|
revision = "1e59b77b52bf8e4b449a57e6f79f21226d571845"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/gorilla/handlers"
|
name = "github.com/gorilla/handlers"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "a4043c62cc2329bacda331d33fc908ab11ef0ec3"
|
revision = "90663712d74cb411cbef281bc1e08c19d1a76145"
|
||||||
source = "https://github.com/gorilla/handlers"
|
source = "https://github.com/gorilla/handlers"
|
||||||
version = "v1.2.1"
|
version = "v1.3.0"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/inconshreveable/mousetrap"
|
name = "github.com/inconshreveable/mousetrap"
|
||||||
|
@ -36,11 +36,14 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/miolini/datacounter"
|
name = "github.com/miolini/datacounter"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "2fb1a1d5c3907155bbff63ad8b8a146ced61eba6"
|
revision = "fd4e42a1d5e0d2714f16caf92f9c64215bf957ce"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/prometheus/client_golang"
|
name = "github.com/prometheus/client_golang"
|
||||||
packages = ["prometheus","prometheus/promhttp"]
|
packages = [
|
||||||
|
"prometheus",
|
||||||
|
"prometheus/promhttp"
|
||||||
|
]
|
||||||
revision = "c5b7fccd204277076155f10851dad72b76a49317"
|
revision = "c5b7fccd204277076155f10851dad72b76a49317"
|
||||||
version = "v0.8.0"
|
version = "v0.8.0"
|
||||||
|
|
||||||
|
@ -48,25 +51,32 @@
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/prometheus/client_model"
|
name = "github.com/prometheus/client_model"
|
||||||
packages = ["go"]
|
packages = ["go"]
|
||||||
revision = "6f3806018612930941127f2a7c6c453ba2c527d2"
|
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/prometheus/common"
|
name = "github.com/prometheus/common"
|
||||||
packages = ["expfmt","internal/bitbucket.org/ww/goautoneg","model"]
|
packages = [
|
||||||
revision = "1bab55dd05dbff384524a6a1c99006d9eb5f139b"
|
"expfmt",
|
||||||
|
"internal/bitbucket.org/ww/goautoneg",
|
||||||
|
"model"
|
||||||
|
]
|
||||||
|
revision = "89604d197083d4781071d3c65855d24ecfb0a563"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
branch = "master"
|
||||||
name = "github.com/prometheus/procfs"
|
name = "github.com/prometheus/procfs"
|
||||||
packages = [".","xfs"]
|
packages = [
|
||||||
revision = "a6e9df898b1336106c743392c48ee0b71f5c4efa"
|
".",
|
||||||
|
"xfs"
|
||||||
|
]
|
||||||
|
revision = "b15cd069a83443be3154b719d0cc9fe8117f09fb"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
branch = "master"
|
|
||||||
name = "github.com/spf13/cobra"
|
name = "github.com/spf13/cobra"
|
||||||
packages = ["."]
|
packages = ["."]
|
||||||
revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b"
|
revision = "7b2c5ac9fc04fc5efafb60700713d4fa609b777b"
|
||||||
|
version = "v0.0.1"
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "github.com/spf13/pflag"
|
name = "github.com/spf13/pflag"
|
||||||
|
@ -76,7 +86,13 @@
|
||||||
|
|
||||||
[[projects]]
|
[[projects]]
|
||||||
name = "goji.io"
|
name = "goji.io"
|
||||||
packages = [".","internal","middleware","pat","pattern"]
|
packages = [
|
||||||
|
".",
|
||||||
|
"internal",
|
||||||
|
"middleware",
|
||||||
|
"pat",
|
||||||
|
"pattern"
|
||||||
|
]
|
||||||
revision = "0d89ff54b2c18c9c4ba530e32496aef902d3c6cd"
|
revision = "0d89ff54b2c18c9c4ba530e32496aef902d3c6cd"
|
||||||
source = "https://github.com/goji/goji"
|
source = "https://github.com/goji/goji"
|
||||||
version = "v2.0"
|
version = "v2.0"
|
||||||
|
|
3
vendor/github.com/golang/protobuf/jsonpb/jsonpb.go
generated
vendored
3
vendor/github.com/golang/protobuf/jsonpb/jsonpb.go
generated
vendored
|
@ -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,
|
// "Generated output always contains 3, 6, or 9 fractional digits,
|
||||||
// depending on required precision."
|
// depending on required precision."
|
||||||
s, ns := s.Field(0).Int(), s.Field(1).Int()
|
s, ns := s.Field(0).Int(), s.Field(1).Int()
|
||||||
d := time.Duration(s)*time.Second + time.Duration(ns)*time.Nanosecond
|
x := fmt.Sprintf("%d.%09d", s, ns)
|
||||||
x := fmt.Sprintf("%.9f", d.Seconds())
|
|
||||||
x = strings.TrimSuffix(x, "000")
|
x = strings.TrimSuffix(x, "000")
|
||||||
x = strings.TrimSuffix(x, "000")
|
x = strings.TrimSuffix(x, "000")
|
||||||
out.write(`"`)
|
out.write(`"`)
|
||||||
|
|
1
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go
generated
vendored
1
vendor/github.com/golang/protobuf/jsonpb/jsonpb_test.go
generated
vendored
|
@ -407,6 +407,7 @@ var marshalingTests = []struct {
|
||||||
{"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON},
|
{"Any with WKT", marshaler, anyWellKnown, anyWellKnownJSON},
|
||||||
{"Any with WKT and indent", marshalerAllOptions, anyWellKnown, anyWellKnownPrettyJSON},
|
{"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: 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{
|
{"Struct", marshaler, &pb.KnownTypes{St: &stpb.Struct{
|
||||||
Fields: map[string]*stpb.Value{
|
Fields: map[string]*stpb.Value{
|
||||||
"one": {Kind: &stpb.Value_StringValue{"loneliest number"}},
|
"one": {Kind: &stpb.Value_StringValue{"loneliest number"}},
|
||||||
|
|
2
vendor/github.com/gorilla/handlers/.travis.yml
generated
vendored
2
vendor/github.com/gorilla/handlers/.travis.yml
generated
vendored
|
@ -7,6 +7,7 @@ matrix:
|
||||||
- go: 1.5
|
- go: 1.5
|
||||||
- go: 1.6
|
- go: 1.6
|
||||||
- go: 1.7
|
- go: 1.7
|
||||||
|
- go: 1.8
|
||||||
- go: tip
|
- go: tip
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- go: tip
|
- go: tip
|
||||||
|
@ -16,3 +17,4 @@ script:
|
||||||
- diff -u <(echo -n) <(gofmt -d .)
|
- diff -u <(echo -n) <(gofmt -d .)
|
||||||
- go vet $(go list ./... | grep -v /vendor/)
|
- go vet $(go list ./... | grep -v /vendor/)
|
||||||
- go test -v -race ./...
|
- go test -v -race ./...
|
||||||
|
|
||||||
|
|
12
vendor/github.com/gorilla/handlers/cors.go
generated
vendored
12
vendor/github.com/gorilla/handlers/cors.go
generated
vendored
|
@ -110,7 +110,17 @@ func (ch *cors) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Header().Set(corsVaryHeader, corsOriginHeader)
|
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 {
|
if r.Method == corsOptionMethod {
|
||||||
return
|
return
|
||||||
|
|
37
vendor/github.com/gorilla/handlers/cors_test.go
generated
vendored
37
vendor/github.com/gorilla/handlers/cors_test.go
generated
vendored
|
@ -327,10 +327,45 @@ func TestCORSHandlerWithCustomValidator(t *testing.T) {
|
||||||
return false
|
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)
|
header := rr.HeaderMap.Get(corsAllowOriginHeader)
|
||||||
if header != r.URL.String() {
|
if header != r.URL.String() {
|
||||||
t.Fatalf("bad header: expected %s to be %s, got %s.", corsAllowOriginHeader, r.URL.String(), header)
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
9
vendor/github.com/miolini/datacounter/response_writer.go
generated
vendored
9
vendor/github.com/miolini/datacounter/response_writer.go
generated
vendored
|
@ -2,15 +2,18 @@ package datacounter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResponseWriterCounter is counter for http.ResponseWriter
|
// ResponseWriterCounter is counter for http.ResponseWriter
|
||||||
type ResponseWriterCounter struct {
|
type ResponseWriterCounter struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
count uint64
|
count uint64
|
||||||
|
started time.Time
|
||||||
writer http.ResponseWriter
|
writer http.ResponseWriter
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +21,7 @@ type ResponseWriterCounter struct {
|
||||||
func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
|
func NewResponseWriterCounter(rw http.ResponseWriter) *ResponseWriterCounter {
|
||||||
return &ResponseWriterCounter{
|
return &ResponseWriterCounter{
|
||||||
writer: rw,
|
writer: rw,
|
||||||
|
started: time.Now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +36,7 @@ func (counter *ResponseWriterCounter) Header() http.Header {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (counter *ResponseWriterCounter) WriteHeader(statusCode int) {
|
func (counter *ResponseWriterCounter) WriteHeader(statusCode int) {
|
||||||
|
counter.Header().Set("X-Runtime", fmt.Sprintf("%.6f", time.Since(counter.started).Seconds()))
|
||||||
counter.writer.WriteHeader(statusCode)
|
counter.writer.WriteHeader(statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,3 +48,7 @@ func (counter *ResponseWriterCounter) Hijack() (net.Conn, *bufio.ReadWriter, err
|
||||||
func (counter *ResponseWriterCounter) Count() uint64 {
|
func (counter *ResponseWriterCounter) Count() uint64 {
|
||||||
return atomic.LoadUint64(&counter.count)
|
return atomic.LoadUint64(&counter.count)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (counter *ResponseWriterCounter) Started() time.Time {
|
||||||
|
return counter.started
|
||||||
|
}
|
||||||
|
|
1
vendor/github.com/prometheus/client_model/Makefile
generated
vendored
1
vendor/github.com/prometheus/client_model/Makefile
generated
vendored
|
@ -39,6 +39,7 @@ src/main/java/io/prometheus/client/Metrics.java: metrics.proto
|
||||||
python: python/prometheus/client/model/metrics_pb2.py
|
python: python/prometheus/client/model/metrics_pb2.py
|
||||||
|
|
||||||
python/prometheus/client/model/metrics_pb2.py: metrics.proto
|
python/prometheus/client/model/metrics_pb2.py: metrics.proto
|
||||||
|
mkdir -p python/prometheus/client/model
|
||||||
protoc $< --python_out=python/prometheus/client/model
|
protoc $< --python_out=python/prometheus/client/model
|
||||||
|
|
||||||
ruby:
|
ruby:
|
||||||
|
|
10
vendor/github.com/prometheus/common/config/http_config.go
generated
vendored
10
vendor/github.com/prometheus/common/config/http_config.go
generated
vendored
|
@ -22,7 +22,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BasicAuth contains basic HTTP authentication credentials.
|
// BasicAuth contains basic HTTP authentication credentials.
|
||||||
|
@ -79,7 +79,9 @@ type HTTPClientConfig struct {
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
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 {
|
if len(c.BearerToken) > 0 && len(c.BearerTokenFile) > 0 {
|
||||||
return fmt.Errorf("at most one of bearer_token & bearer_token_file must be configured")
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = c.validate()
|
err = c.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.validate()
|
return c.Validate()
|
||||||
}
|
}
|
||||||
return checkOverflow(c.XXX, "http_client_config")
|
return checkOverflow(c.XXX, "http_client_config")
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/prometheus/common/config/http_config_test.go
generated
vendored
2
vendor/github.com/prometheus/common/config/http_config_test.go
generated
vendored
|
@ -114,7 +114,7 @@ func TestValidateHTTPConfig(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Error loading HTTP client config: %v", err)
|
t.Errorf("Error loading HTTP client config: %v", err)
|
||||||
}
|
}
|
||||||
err = cfg.validate()
|
err = cfg.Validate()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Error validating %s: %s", "testdata/http.conf.good.yml", err)
|
t.Fatalf("Error validating %s: %s", "testdata/http.conf.good.yml", err)
|
||||||
}
|
}
|
||||||
|
|
4
vendor/github.com/prometheus/common/log/log.go
generated
vendored
4
vendor/github.com/prometheus/common/log/log.go
generated
vendored
|
@ -56,11 +56,11 @@ func (s *loggerSettings) apply(ctx *kingpin.ParseContext) error {
|
||||||
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine)
|
// To use the default Kingpin application, call AddFlags(kingpin.CommandLine)
|
||||||
func AddFlags(a *kingpin.Application) {
|
func AddFlags(a *kingpin.Application) {
|
||||||
s := loggerSettings{}
|
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()).
|
Default(origLogger.Level.String()).
|
||||||
StringVar(&s.level)
|
StringVar(&s.level)
|
||||||
defaultFormat := url.URL{Scheme: "logger", Opaque: "stderr"}
|
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()).
|
Default(defaultFormat.String()).
|
||||||
StringVar(&s.format)
|
StringVar(&s.format)
|
||||||
a.Action(s.apply)
|
a.Action(s.apply)
|
||||||
|
|
3
vendor/github.com/prometheus/common/model/time.go
generated
vendored
3
vendor/github.com/prometheus/common/model/time.go
generated
vendored
|
@ -214,6 +214,9 @@ func (d Duration) String() string {
|
||||||
ms = int64(time.Duration(d) / time.Millisecond)
|
ms = int64(time.Duration(d) / time.Millisecond)
|
||||||
unit = "ms"
|
unit = "ms"
|
||||||
)
|
)
|
||||||
|
if ms == 0 {
|
||||||
|
return "0s"
|
||||||
|
}
|
||||||
factors := map[string]int64{
|
factors := map[string]int64{
|
||||||
"y": 1000 * 60 * 60 * 24 * 365,
|
"y": 1000 * 60 * 60 * 24 * 365,
|
||||||
"w": 1000 * 60 * 60 * 24 * 7,
|
"w": 1000 * 60 * 60 * 24 * 7,
|
||||||
|
|
3
vendor/github.com/prometheus/common/model/time_test.go
generated
vendored
3
vendor/github.com/prometheus/common/model/time_test.go
generated
vendored
|
@ -91,6 +91,9 @@ func TestParseDuration(t *testing.T) {
|
||||||
out time.Duration
|
out time.Duration
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
in: "0s",
|
||||||
|
out: 0,
|
||||||
|
}, {
|
||||||
in: "324ms",
|
in: "324ms",
|
||||||
out: 324 * time.Millisecond,
|
out: 324 * time.Millisecond,
|
||||||
}, {
|
}, {
|
||||||
|
|
8
vendor/github.com/prometheus/procfs/.travis.yml
generated
vendored
8
vendor/github.com/prometheus/procfs/.travis.yml
generated
vendored
|
@ -1,5 +1,9 @@
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
language: go
|
language: go
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.7.6
|
- 1.9.x
|
||||||
- 1.8.3
|
- 1.x
|
||||||
|
|
||||||
|
go_import_path: github.com/prometheus/procfs
|
||||||
|
|
4
vendor/github.com/prometheus/procfs/bcache/get.go
generated
vendored
4
vendor/github.com/prometheus/procfs/bcache/get.go
generated
vendored
|
@ -93,7 +93,7 @@ func dehumanize(hbytes []byte) (uint64, error) {
|
||||||
'Z': ZiB,
|
'Z': ZiB,
|
||||||
'Y': YiB,
|
'Y': YiB,
|
||||||
}
|
}
|
||||||
mul = float64(multipliers[rune(lastByte)])
|
mul = multipliers[rune(lastByte)]
|
||||||
mant, err = parsePseudoFloat(string(hbytes))
|
mant, err = parsePseudoFloat(string(hbytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
|
@ -139,7 +139,7 @@ func (p *parser) readValue(fileName string) uint64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParsePriorityStats parses lines from the priority_stats file.
|
// ParsePriorityStats parses lines from the priority_stats file.
|
||||||
func parsePriorityStats(line string, ps *PriorityStats) (error) {
|
func parsePriorityStats(line string, ps *PriorityStats) error {
|
||||||
var (
|
var (
|
||||||
value uint64
|
value uint64
|
||||||
err error
|
err error
|
||||||
|
|
10
vendor/github.com/prometheus/procfs/bcache/get_test.go
generated
vendored
10
vendor/github.com/prometheus/procfs/bcache/get_test.go
generated
vendored
|
@ -14,8 +14,8 @@
|
||||||
package bcache
|
package bcache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"math"
|
"math"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDehumanizeTests(t *testing.T) {
|
func TestDehumanizeTests(t *testing.T) {
|
||||||
|
@ -59,7 +59,7 @@ func TestDehumanizeTests(t *testing.T) {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
if got != tst.out {
|
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 {
|
for _, tst := range parsePseudoFloatTests {
|
||||||
got, err := parsePseudoFloat(tst.in)
|
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)
|
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%"
|
in = "Metadata: 5%"
|
||||||
gotErr = parsePriorityStats(in, &got)
|
gotErr = parsePriorityStats(in, &got)
|
||||||
if gotErr != nil || got.MetadataPercent != want.MetadataPercent {
|
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%"
|
in = "Unused: 99%"
|
||||||
gotErr = parsePriorityStats(in, &got)
|
gotErr = parsePriorityStats(in, &got)
|
||||||
if gotErr != nil || got.UnusedPercent != want.UnusedPercent {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
2
vendor/github.com/prometheus/procfs/buddyinfo.go
generated
vendored
|
@ -62,7 +62,7 @@ func parseBuddyInfo(r io.Reader) ([]BuddyInfo, error) {
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
var err error
|
var err error
|
||||||
line := scanner.Text()
|
line := scanner.Text()
|
||||||
parts := strings.Fields(string(line))
|
parts := strings.Fields(line)
|
||||||
|
|
||||||
if len(parts) < 4 {
|
if len(parts) < 4 {
|
||||||
return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo")
|
return nil, fmt.Errorf("invalid number of fields when parsing buddyinfo")
|
||||||
|
|
4
vendor/github.com/prometheus/procfs/fixtures/26231/net/dev
generated
vendored
Normal file
4
vendor/github.com/prometheus/procfs/fixtures/26231/net/dev
generated
vendored
Normal 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
|
1
vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt
generated
vendored
Symbolic link
1
vendor/github.com/prometheus/procfs/fixtures/26231/ns/mnt
generated
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
mnt:[4026531840]
|
1
vendor/github.com/prometheus/procfs/fixtures/26231/ns/net
generated
vendored
Symbolic link
1
vendor/github.com/prometheus/procfs/fixtures/26231/ns/net
generated
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
net:[4026531993]
|
6
vendor/github.com/prometheus/procfs/fixtures/net/dev
generated
vendored
Normal file
6
vendor/github.com/prometheus/procfs/fixtures/net/dev
generated
vendored
Normal 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
|
10
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
10
vendor/github.com/prometheus/procfs/ipvs.go
generated
vendored
|
@ -31,16 +31,16 @@ type IPVSStats struct {
|
||||||
type IPVSBackendStatus struct {
|
type IPVSBackendStatus struct {
|
||||||
// The local (virtual) IP address.
|
// The local (virtual) IP address.
|
||||||
LocalAddress net.IP
|
LocalAddress net.IP
|
||||||
|
// The remote (real) IP address.
|
||||||
|
RemoteAddress net.IP
|
||||||
// The local (virtual) port.
|
// The local (virtual) port.
|
||||||
LocalPort uint16
|
LocalPort uint16
|
||||||
|
// The remote (real) port.
|
||||||
|
RemotePort uint16
|
||||||
// The local firewall mark
|
// The local firewall mark
|
||||||
LocalMark string
|
LocalMark string
|
||||||
// The transport protocol (TCP, UDP).
|
// The transport protocol (TCP, UDP).
|
||||||
Proto string
|
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.
|
// The current number of active connections for this virtual/real address pair.
|
||||||
ActiveConn uint64
|
ActiveConn uint64
|
||||||
// The current number of inactive connections for this virtual/real address pair.
|
// 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() {
|
for scanner.Scan() {
|
||||||
fields := strings.Fields(string(scanner.Text()))
|
fields := strings.Fields(scanner.Text())
|
||||||
if len(fields) == 0 {
|
if len(fields) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
203
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
Normal file
203
vendor/github.com/prometheus/procfs/net_dev.go
generated
vendored
Normal 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
73
vendor/github.com/prometheus/procfs/net_dev_test.go
generated
vendored
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
5
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
5
vendor/github.com/prometheus/procfs/proc_io.go
generated
vendored
|
@ -47,9 +47,6 @@ func (p Proc) NewIO() (ProcIO, error) {
|
||||||
|
|
||||||
_, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR,
|
_, err = fmt.Sscanf(string(data), ioFormat, &pio.RChar, &pio.WChar, &pio.SyscR,
|
||||||
&pio.SyscW, &pio.ReadBytes, &pio.WriteBytes, &pio.CancelledWriteBytes)
|
&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
55
vendor/github.com/prometheus/procfs/proc_ns.go
generated
vendored
Normal 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
31
vendor/github.com/prometheus/procfs/proc_ns_test.go
generated
vendored
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue