Update vendoring (#1105)
* Update vendor github.com/sirupsen/logrus@v1.1.1 * Update vendor github.com/coreos/go-systemd/dbus@v17 * Update vendor github.com/golang/protobuf/proto@v1.2.0 * Update vendor github.com/konsorten/go-windows-terminal-sequences@v1.0.1 * Update vendor github.com/mdlayher/... * Update vendor github.com/prometheus/procfs/... * Update vendor golang.org/x/... Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
f0d2a06b11
commit
9cf508e673
279 changed files with 54502 additions and 15108 deletions
1
vendor/github.com/prometheus/procfs/.gitignore
generated
vendored
1
vendor/github.com/prometheus/procfs/.gitignore
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
/fixtures/
|
||||
15
vendor/github.com/prometheus/procfs/.travis.yml
generated
vendored
15
vendor/github.com/prometheus/procfs/.travis.yml
generated
vendored
|
|
@ -1,15 +0,0 @@
|
|||
sudo: false
|
||||
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.x
|
||||
|
||||
go_import_path: github.com/prometheus/procfs
|
||||
|
||||
script:
|
||||
- make style check_license vet test staticcheck
|
||||
114
vendor/github.com/prometheus/procfs/bcache/get_test.go
generated
vendored
114
vendor/github.com/prometheus/procfs/bcache/get_test.go
generated
vendored
|
|
@ -1,114 +0,0 @@
|
|||
// Copyright 2017 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package bcache
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestDehumanizeTests(t *testing.T) {
|
||||
dehumanizeTests := []struct {
|
||||
in []byte
|
||||
out uint64
|
||||
invalid bool
|
||||
}{
|
||||
{
|
||||
in: []byte("542k"),
|
||||
out: 555008,
|
||||
},
|
||||
{
|
||||
in: []byte("322M"),
|
||||
out: 337641472,
|
||||
},
|
||||
{
|
||||
in: []byte("1.1k"),
|
||||
out: 1124,
|
||||
},
|
||||
{
|
||||
in: []byte("1.9k"),
|
||||
out: 1924,
|
||||
},
|
||||
{
|
||||
in: []byte("1.10k"),
|
||||
out: 2024,
|
||||
},
|
||||
{
|
||||
in: []byte(""),
|
||||
out: 0,
|
||||
invalid: true,
|
||||
},
|
||||
}
|
||||
for _, tst := range dehumanizeTests {
|
||||
got, err := dehumanize(tst.in)
|
||||
if tst.invalid && err == nil {
|
||||
t.Error("expected an error, but none occurred")
|
||||
}
|
||||
if !tst.invalid && err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
if got != tst.out {
|
||||
t.Errorf("dehumanize: '%s', want %d, got %d", tst.in, tst.out, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParsePseudoFloatTests(t *testing.T) {
|
||||
parsePseudoFloatTests := []struct {
|
||||
in string
|
||||
out float64
|
||||
}{
|
||||
{
|
||||
in: "1.1",
|
||||
out: float64(1.097656),
|
||||
},
|
||||
{
|
||||
in: "1.9",
|
||||
out: float64(1.878906),
|
||||
},
|
||||
{
|
||||
in: "1.10",
|
||||
out: float64(1.976562),
|
||||
},
|
||||
}
|
||||
for _, tst := range parsePseudoFloatTests {
|
||||
got, err := parsePseudoFloat(tst.in)
|
||||
if err != nil || math.Abs(got-tst.out) > 0.0001 {
|
||||
t.Errorf("parsePseudoFloat: %s, want %f, got %f", tst.in, tst.out, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPriorityStats(t *testing.T) {
|
||||
var want = PriorityStats{
|
||||
UnusedPercent: 99,
|
||||
MetadataPercent: 5,
|
||||
}
|
||||
var (
|
||||
in string
|
||||
gotErr error
|
||||
got PriorityStats
|
||||
)
|
||||
in = "Metadata: 5%"
|
||||
gotErr = parsePriorityStats(in, &got)
|
||||
if gotErr != nil || got.MetadataPercent != want.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 %d, got %d", in, want.UnusedPercent, got.UnusedPercent)
|
||||
}
|
||||
}
|
||||
64
vendor/github.com/prometheus/procfs/buddyinfo_test.go
generated
vendored
64
vendor/github.com/prometheus/procfs/buddyinfo_test.go
generated
vendored
|
|
@ -1,64 +0,0 @@
|
|||
// Copyright 2017 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBuddyInfo(t *testing.T) {
|
||||
buddyInfo, err := FS("fixtures/buddyinfo/valid").NewBuddyInfo()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if want, got := "DMA", buddyInfo[0].Zone; want != got {
|
||||
t.Errorf("want Node 0, Zone %s, got %s", want, got)
|
||||
}
|
||||
|
||||
if want, got := "Normal", buddyInfo[2].Zone; want != got {
|
||||
t.Errorf("want Node 0, Zone %s, got %s", want, got)
|
||||
}
|
||||
|
||||
if want, got := 4381.0, buddyInfo[2].Sizes[0]; want != got {
|
||||
t.Errorf("want Node 0, Zone Normal %f, got %f", want, got)
|
||||
}
|
||||
|
||||
if want, got := 572.0, buddyInfo[1].Sizes[1]; want != got {
|
||||
t.Errorf("want Node 0, Zone DMA32 %f, got %f", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuddyInfoShort(t *testing.T) {
|
||||
_, err := FS("fixtures/buddyinfo/short").NewBuddyInfo()
|
||||
if err == nil {
|
||||
t.Errorf("expected error, but none occurred")
|
||||
}
|
||||
|
||||
if want, got := "invalid number of fields when parsing buddyinfo", err.Error(); want != got {
|
||||
t.Errorf("wrong error returned, wanted %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuddyInfoSizeMismatch(t *testing.T) {
|
||||
_, err := FS("fixtures/buddyinfo/sizemismatch").NewBuddyInfo()
|
||||
if err == nil {
|
||||
t.Errorf("expected error, but none occurred")
|
||||
}
|
||||
|
||||
if want, got := "mismatch in number of buddyinfo buckets", err.Error(); !strings.HasPrefix(got, want) {
|
||||
t.Errorf("wrong error returned, wanted prefix %q, got %q", want, got)
|
||||
}
|
||||
}
|
||||
16
vendor/github.com/prometheus/procfs/fixtures.ttar
generated
vendored
16
vendor/github.com/prometheus/procfs/fixtures.ttar
generated
vendored
|
|
@ -15,6 +15,9 @@ Lines: 1
|
|||
vim
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26231/cwd
|
||||
SymlinkTo: /usr/bin
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26231/exe
|
||||
SymlinkTo: /usr/bin/vim
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
@ -111,6 +114,9 @@ SymlinkTo: mnt:[4026531840]
|
|||
Path: fixtures/26231/ns/net
|
||||
SymlinkTo: net:[4026531993]
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26231/root
|
||||
SymlinkTo: /
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26231/stat
|
||||
Lines: 1
|
||||
26231 (vim) R 5392 7446 5392 34835 7446 4218880 32533 309516 26 82 1677 44 158 99 20 0 1 0 82375 56274944 1981 18446744073709551615 4194304 6294284 140736914091744 140736914087944 139965136429984 0 0 12288 1870679807 0 0 0 17 0 0 0 31 0 0 8391624 8481048 16420864 140736914093252 140736914093279 140736914093279 140736914096107 0
|
||||
|
|
@ -128,6 +134,9 @@ Lines: 1
|
|||
ata_sff
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26232/cwd
|
||||
SymlinkTo: /does/not/exist
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/26232/fd
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
@ -167,6 +176,9 @@ Max realtime priority 0 0
|
|||
Max realtime timeout unlimited unlimited us
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26232/root
|
||||
SymlinkTo: /does/not/exist
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/26232/stat
|
||||
Lines: 1
|
||||
33 (ata_sff) S 2 0 0 0 -1 69238880 0 0 0 0 0 0 0 0 0 -20 1 0 5 0 0 18446744073709551615 0 0 0 0 0 0 0 2147483647 0 18446744073709551615 0 0 17 1 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
|
|
@ -444,3 +456,7 @@ Path: fixtures/symlinktargets/xyz
|
|||
Lines: 0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/.unpacked
|
||||
Lines: 0
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
|||
39
vendor/github.com/prometheus/procfs/fs_test.go
generated
vendored
39
vendor/github.com/prometheus/procfs/fs_test.go
generated
vendored
|
|
@ -1,39 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewFS(t *testing.T) {
|
||||
if _, err := NewFS("foobar"); err == nil {
|
||||
t.Error("want NewFS to fail for non-existing mount point")
|
||||
}
|
||||
|
||||
if _, err := NewFS("procfs.go"); err == nil {
|
||||
t.Error("want NewFS to fail if mount point is not a directory")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSXFSStats(t *testing.T) {
|
||||
stats, err := FS("fixtures").XFSStats()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse XFS stats: %v", err)
|
||||
}
|
||||
|
||||
// Very lightweight test just to sanity check the path used
|
||||
// to open XFS stats. Heavier tests in package xfs.
|
||||
if want, got := uint32(92447), stats.ExtentAllocation.ExtentsAllocated; want != got {
|
||||
t.Errorf("unexpected extents allocated:\nwant: %d\nhave: %d", want, got)
|
||||
}
|
||||
}
|
||||
15
vendor/github.com/prometheus/procfs/internal/util/parse.go
generated
vendored
15
vendor/github.com/prometheus/procfs/internal/util/parse.go
generated
vendored
|
|
@ -13,7 +13,11 @@
|
|||
|
||||
package util
|
||||
|
||||
import "strconv"
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ParseUint32s parses a slice of strings into a slice of uint32s.
|
||||
func ParseUint32s(ss []string) ([]uint32, error) {
|
||||
|
|
@ -44,3 +48,12 @@ func ParseUint64s(ss []string) ([]uint64, error) {
|
|||
|
||||
return us, nil
|
||||
}
|
||||
|
||||
// ReadUintFromFile reads a file and attempts to parse a uint64 from it.
|
||||
func ReadUintFromFile(path string) (uint64, error) {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return strconv.ParseUint(strings.TrimSpace(string(data)), 10, 64)
|
||||
}
|
||||
|
|
|
|||
45
vendor/github.com/prometheus/procfs/internal/util/sysreadfile_linux.go
generated
vendored
Normal file
45
vendor/github.com/prometheus/procfs/internal/util/sysreadfile_linux.go
generated
vendored
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// SysReadFile is a simplified ioutil.ReadFile that invokes syscall.Read directly.
|
||||
// https://github.com/prometheus/node_exporter/pull/728/files
|
||||
func SysReadFile(file string) (string, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// On some machines, hwmon drivers are broken and return EAGAIN. This causes
|
||||
// Go's ioutil.ReadFile implementation to poll forever.
|
||||
//
|
||||
// Since we either want to read data or bail immediately, do the simplest
|
||||
// possible read using syscall directly.
|
||||
b := make([]byte, 128)
|
||||
n, err := syscall.Read(int(f.Fd()), b)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(bytes.TrimSpace(b[:n])), nil
|
||||
}
|
||||
250
vendor/github.com/prometheus/procfs/ipvs_test.go
generated
vendored
250
vendor/github.com/prometheus/procfs/ipvs_test.go
generated
vendored
|
|
@ -1,250 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var (
|
||||
expectedIPVSStats = IPVSStats{
|
||||
Connections: 23765872,
|
||||
IncomingPackets: 3811989221,
|
||||
OutgoingPackets: 0,
|
||||
IncomingBytes: 89991519156915,
|
||||
OutgoingBytes: 0,
|
||||
}
|
||||
expectedIPVSBackendStatuses = []IPVSBackendStatus{
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.22"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.82.22"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 248,
|
||||
InactConn: 2,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.22"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.83.24"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 248,
|
||||
InactConn: 2,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.22"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.83.21"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 248,
|
||||
InactConn: 1,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.57"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.84.22"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 0,
|
||||
ActiveConn: 0,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.57"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.82.21"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 1499,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.57"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.50.21"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 1498,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.55"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.50.26"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 0,
|
||||
ActiveConn: 0,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("192.168.0.55"),
|
||||
LocalPort: 3306,
|
||||
RemoteAddress: net.ParseIP("192.168.49.32"),
|
||||
RemotePort: 3306,
|
||||
Proto: "TCP",
|
||||
Weight: 100,
|
||||
ActiveConn: 0,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("2620::1"),
|
||||
LocalPort: 80,
|
||||
RemoteAddress: net.ParseIP("2620::2"),
|
||||
RemotePort: 80,
|
||||
Proto: "TCP",
|
||||
Weight: 1,
|
||||
ActiveConn: 0,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("2620::1"),
|
||||
LocalPort: 80,
|
||||
RemoteAddress: net.ParseIP("2620::3"),
|
||||
RemotePort: 80,
|
||||
Proto: "TCP",
|
||||
Weight: 1,
|
||||
ActiveConn: 0,
|
||||
InactConn: 0,
|
||||
},
|
||||
{
|
||||
LocalAddress: net.ParseIP("2620::1"),
|
||||
LocalPort: 80,
|
||||
RemoteAddress: net.ParseIP("2620::4"),
|
||||
RemotePort: 80,
|
||||
Proto: "TCP",
|
||||
Weight: 1,
|
||||
ActiveConn: 1,
|
||||
InactConn: 1,
|
||||
},
|
||||
{
|
||||
LocalMark: "10001000",
|
||||
RemoteAddress: net.ParseIP("192.168.50.26"),
|
||||
RemotePort: 3306,
|
||||
Proto: "FWM",
|
||||
Weight: 0,
|
||||
ActiveConn: 0,
|
||||
InactConn: 1,
|
||||
},
|
||||
{
|
||||
LocalMark: "10001000",
|
||||
RemoteAddress: net.ParseIP("192.168.50.21"),
|
||||
RemotePort: 3306,
|
||||
Proto: "FWM",
|
||||
Weight: 0,
|
||||
ActiveConn: 0,
|
||||
InactConn: 2,
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func TestIPVSStats(t *testing.T) {
|
||||
stats, err := FS("fixtures").NewIPVSStats()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if stats != expectedIPVSStats {
|
||||
t.Errorf("want %+v, have %+v", expectedIPVSStats, stats)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseIPPort(t *testing.T) {
|
||||
ip := net.ParseIP("192.168.0.22")
|
||||
port := uint16(3306)
|
||||
|
||||
gotIP, gotPort, err := parseIPPort("C0A80016:0CEA")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !(gotIP.Equal(ip) && port == gotPort) {
|
||||
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseIPPortInvalid(t *testing.T) {
|
||||
testcases := []string{
|
||||
"",
|
||||
"C0A80016",
|
||||
"C0A800:1234",
|
||||
"FOOBARBA:1234",
|
||||
"C0A80016:0CEA:1234",
|
||||
}
|
||||
|
||||
for _, s := range testcases {
|
||||
ip, port, err := parseIPPort(s)
|
||||
if ip != nil || port != uint16(0) || err == nil {
|
||||
t.Errorf("Expected error for input %s, have ip = %s, port = %v, err = %v", s, ip, port, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseIPPortIPv6(t *testing.T) {
|
||||
ip := net.ParseIP("dead:beef::1")
|
||||
port := uint16(8080)
|
||||
|
||||
gotIP, gotPort, err := parseIPPort("[DEAD:BEEF:0000:0000:0000:0000:0000:0001]:1F90")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !(gotIP.Equal(ip) && port == gotPort) {
|
||||
t.Errorf("want %s:%d, have %s:%d", ip, port, gotIP, gotPort)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIPVSBackendStatus(t *testing.T) {
|
||||
backendStats, err := FS("fixtures").NewIPVSBackendStatus()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := len(expectedIPVSBackendStatuses), len(backendStats); want != have {
|
||||
t.Fatalf("want %d backend statuses, have %d", want, have)
|
||||
}
|
||||
|
||||
for idx, expect := range expectedIPVSBackendStatuses {
|
||||
if !backendStats[idx].LocalAddress.Equal(expect.LocalAddress) {
|
||||
t.Errorf("want LocalAddress %s, have %s", expect.LocalAddress, backendStats[idx].LocalAddress)
|
||||
}
|
||||
if backendStats[idx].LocalPort != expect.LocalPort {
|
||||
t.Errorf("want LocalPort %d, have %d", expect.LocalPort, backendStats[idx].LocalPort)
|
||||
}
|
||||
if !backendStats[idx].RemoteAddress.Equal(expect.RemoteAddress) {
|
||||
t.Errorf("want RemoteAddress %s, have %s", expect.RemoteAddress, backendStats[idx].RemoteAddress)
|
||||
}
|
||||
if backendStats[idx].RemotePort != expect.RemotePort {
|
||||
t.Errorf("want RemotePort %d, have %d", expect.RemotePort, backendStats[idx].RemotePort)
|
||||
}
|
||||
if backendStats[idx].Proto != expect.Proto {
|
||||
t.Errorf("want Proto %s, have %s", expect.Proto, backendStats[idx].Proto)
|
||||
}
|
||||
if backendStats[idx].Weight != expect.Weight {
|
||||
t.Errorf("want Weight %d, have %d", expect.Weight, backendStats[idx].Weight)
|
||||
}
|
||||
if backendStats[idx].ActiveConn != expect.ActiveConn {
|
||||
t.Errorf("want ActiveConn %d, have %d", expect.ActiveConn, backendStats[idx].ActiveConn)
|
||||
}
|
||||
if backendStats[idx].InactConn != expect.InactConn {
|
||||
t.Errorf("want InactConn %d, have %d", expect.InactConn, backendStats[idx].InactConn)
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/github.com/prometheus/procfs/mdstat_test.go
generated
vendored
44
vendor/github.com/prometheus/procfs/mdstat_test.go
generated
vendored
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMDStat(t *testing.T) {
|
||||
mdStates, err := FS("fixtures").ParseMDStat()
|
||||
if err != nil {
|
||||
t.Fatalf("parsing of reference-file failed entirely: %s", err)
|
||||
}
|
||||
|
||||
refs := map[string]MDStat{
|
||||
"md3": {"md3", "active", 8, 8, 5853468288, 5853468288},
|
||||
"md127": {"md127", "active", 2, 2, 312319552, 312319552},
|
||||
"md0": {"md0", "active", 2, 2, 248896, 248896},
|
||||
"md4": {"md4", "inactive", 2, 2, 4883648, 4883648},
|
||||
"md6": {"md6", "active", 1, 2, 195310144, 16775552},
|
||||
"md8": {"md8", "active", 2, 2, 195310144, 16775552},
|
||||
"md7": {"md7", "active", 3, 4, 7813735424, 7813735424},
|
||||
}
|
||||
|
||||
if want, have := len(refs), len(mdStates); want != have {
|
||||
t.Errorf("want %d parsed md-devices, have %d", want, have)
|
||||
}
|
||||
for _, md := range mdStates {
|
||||
if want, have := refs[md.Name], md; want != have {
|
||||
t.Errorf("%s: want %v, have %v", md.Name, want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
380
vendor/github.com/prometheus/procfs/mountstats_test.go
generated
vendored
380
vendor/github.com/prometheus/procfs/mountstats_test.go
generated
vendored
|
|
@ -1,380 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMountStats(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s string
|
||||
mounts []*Mount
|
||||
invalid bool
|
||||
}{
|
||||
{
|
||||
name: "no devices",
|
||||
s: `hello`,
|
||||
},
|
||||
{
|
||||
name: "device has too few fields",
|
||||
s: `device foo`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "device incorrect format",
|
||||
s: `device rootfs BAD on / with fstype rootfs`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "device incorrect format",
|
||||
s: `device rootfs mounted BAD / with fstype rootfs`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "device incorrect format",
|
||||
s: `device rootfs mounted on / BAD fstype rootfs`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "device incorrect format",
|
||||
s: `device rootfs mounted on / with BAD rootfs`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "device rootfs cannot have stats",
|
||||
s: `device rootfs mounted on / with fstype rootfs stats`,
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with too little info",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nhello",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad bytes",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nbytes: 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad events",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nevents: 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad per-op stats",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nper-op statistics\nFOO 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad transport stats",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nxprt: tcp",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad transport version",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=foo\nxprt: tcp 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad transport stats version 1.0",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.0\nxprt: tcp 0 0 0 0 0 0 0 0 0 0 0 0 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv4 device with bad transport stats version 1.1",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nxprt: tcp 0 0 0 0 0 0 0 0 0 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device with bad transport protocol",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs4 statvers=1.1\nxprt: tcpx 0 0 0 0 0 0 0 0 0 0",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device using TCP with transport stats version 1.0 OK",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs statvers=1.0\nxprt: tcp 1 2 3 4 5 6 7 8 9 10",
|
||||
mounts: []*Mount{{
|
||||
Device: "192.168.1.1:/srv",
|
||||
Mount: "/mnt/nfs",
|
||||
Type: "nfs",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.0",
|
||||
Transport: NFSTransportStats{
|
||||
Protocol: "tcp",
|
||||
Port: 1,
|
||||
Bind: 2,
|
||||
Connect: 3,
|
||||
ConnectIdleTime: 4,
|
||||
IdleTime: 5 * time.Second,
|
||||
Sends: 6,
|
||||
Receives: 7,
|
||||
BadTransactionIDs: 8,
|
||||
CumulativeActiveRequests: 9,
|
||||
CumulativeBacklog: 10,
|
||||
MaximumRPCSlotsUsed: 0, // these three are not
|
||||
CumulativeSendingQueue: 0, // present in statvers=1.0
|
||||
CumulativePendingQueue: 0, //
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device using UDP with transport stats version 1.0 OK",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs statvers=1.0\nxprt: udp 1 2 3 4 5 6 7",
|
||||
mounts: []*Mount{{
|
||||
Device: "192.168.1.1:/srv",
|
||||
Mount: "/mnt/nfs",
|
||||
Type: "nfs",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.0",
|
||||
Transport: NFSTransportStats{
|
||||
Protocol: "udp",
|
||||
Port: 1,
|
||||
Bind: 2,
|
||||
Connect: 0,
|
||||
ConnectIdleTime: 0,
|
||||
IdleTime: 0,
|
||||
Sends: 3,
|
||||
Receives: 4,
|
||||
BadTransactionIDs: 5,
|
||||
CumulativeActiveRequests: 6,
|
||||
CumulativeBacklog: 7,
|
||||
MaximumRPCSlotsUsed: 0, // these three are not
|
||||
CumulativeSendingQueue: 0, // present in statvers=1.0
|
||||
CumulativePendingQueue: 0, //
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device using TCP with transport stats version 1.1 OK",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs statvers=1.1\nxprt: tcp 1 2 3 4 5 6 7 8 9 10 11 12 13",
|
||||
mounts: []*Mount{{
|
||||
Device: "192.168.1.1:/srv",
|
||||
Mount: "/mnt/nfs",
|
||||
Type: "nfs",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.1",
|
||||
Transport: NFSTransportStats{
|
||||
Protocol: "tcp",
|
||||
Port: 1,
|
||||
Bind: 2,
|
||||
Connect: 3,
|
||||
ConnectIdleTime: 4,
|
||||
IdleTime: 5 * time.Second,
|
||||
Sends: 6,
|
||||
Receives: 7,
|
||||
BadTransactionIDs: 8,
|
||||
CumulativeActiveRequests: 9,
|
||||
CumulativeBacklog: 10,
|
||||
MaximumRPCSlotsUsed: 11,
|
||||
CumulativeSendingQueue: 12,
|
||||
CumulativePendingQueue: 13,
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device using UDP with transport stats version 1.1 OK",
|
||||
s: "device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs statvers=1.1\nxprt: udp 1 2 3 4 5 6 7 8 9 10",
|
||||
mounts: []*Mount{{
|
||||
Device: "192.168.1.1:/srv",
|
||||
Mount: "/mnt/nfs",
|
||||
Type: "nfs",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.1",
|
||||
Transport: NFSTransportStats{
|
||||
Protocol: "udp",
|
||||
Port: 1,
|
||||
Bind: 2,
|
||||
Connect: 0, // these three are not
|
||||
ConnectIdleTime: 0, // present for UDP
|
||||
IdleTime: 0, //
|
||||
Sends: 3,
|
||||
Receives: 4,
|
||||
BadTransactionIDs: 5,
|
||||
CumulativeActiveRequests: 6,
|
||||
CumulativeBacklog: 7,
|
||||
MaximumRPCSlotsUsed: 8,
|
||||
CumulativeSendingQueue: 9,
|
||||
CumulativePendingQueue: 10,
|
||||
},
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "device rootfs OK",
|
||||
s: `device rootfs mounted on / with fstype rootfs`,
|
||||
mounts: []*Mount{{
|
||||
Device: "rootfs",
|
||||
Mount: "/",
|
||||
Type: "rootfs",
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "NFSv3 device with minimal stats OK",
|
||||
s: `device 192.168.1.1:/srv mounted on /mnt/nfs with fstype nfs statvers=1.1`,
|
||||
mounts: []*Mount{{
|
||||
Device: "192.168.1.1:/srv",
|
||||
Mount: "/mnt/nfs",
|
||||
Type: "nfs",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.1",
|
||||
},
|
||||
}},
|
||||
},
|
||||
{
|
||||
name: "fixtures OK",
|
||||
mounts: []*Mount{
|
||||
{
|
||||
Device: "rootfs",
|
||||
Mount: "/",
|
||||
Type: "rootfs",
|
||||
},
|
||||
{
|
||||
Device: "sysfs",
|
||||
Mount: "/sys",
|
||||
Type: "sysfs",
|
||||
},
|
||||
{
|
||||
Device: "proc",
|
||||
Mount: "/proc",
|
||||
Type: "proc",
|
||||
},
|
||||
{
|
||||
Device: "/dev/sda1",
|
||||
Mount: "/",
|
||||
Type: "ext4",
|
||||
},
|
||||
{
|
||||
Device: "192.168.1.1:/srv/test",
|
||||
Mount: "/mnt/nfs/test",
|
||||
Type: "nfs4",
|
||||
Stats: &MountStatsNFS{
|
||||
StatVersion: "1.1",
|
||||
Age: 13968 * time.Second,
|
||||
Bytes: NFSBytesStats{
|
||||
Read: 1207640230,
|
||||
ReadTotal: 1210214218,
|
||||
ReadPages: 295483,
|
||||
},
|
||||
Events: NFSEventsStats{
|
||||
InodeRevalidate: 52,
|
||||
DnodeRevalidate: 226,
|
||||
VFSOpen: 1,
|
||||
VFSLookup: 13,
|
||||
VFSAccess: 398,
|
||||
VFSReadPages: 331,
|
||||
VFSWritePages: 47,
|
||||
VFSFlush: 77,
|
||||
VFSFileRelease: 77,
|
||||
},
|
||||
Operations: []NFSOperationStats{
|
||||
{
|
||||
Operation: "NULL",
|
||||
},
|
||||
{
|
||||
Operation: "READ",
|
||||
Requests: 1298,
|
||||
Transmissions: 1298,
|
||||
BytesSent: 207680,
|
||||
BytesReceived: 1210292152,
|
||||
CumulativeQueueTime: 6 * time.Millisecond,
|
||||
CumulativeTotalResponseTime: 79386 * time.Millisecond,
|
||||
CumulativeTotalRequestTime: 79407 * time.Millisecond,
|
||||
},
|
||||
{
|
||||
Operation: "WRITE",
|
||||
},
|
||||
},
|
||||
Transport: NFSTransportStats{
|
||||
Protocol: "tcp",
|
||||
Port: 832,
|
||||
Connect: 1,
|
||||
IdleTime: 11 * time.Second,
|
||||
Sends: 6428,
|
||||
Receives: 6428,
|
||||
CumulativeActiveRequests: 12154,
|
||||
MaximumRPCSlotsUsed: 24,
|
||||
CumulativeSendingQueue: 26,
|
||||
CumulativePendingQueue: 5726,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
t.Logf("[%02d] test %q", i, tt.name)
|
||||
|
||||
var mounts []*Mount
|
||||
var err error
|
||||
|
||||
if tt.s != "" {
|
||||
mounts, err = parseMountStats(strings.NewReader(tt.s))
|
||||
} else {
|
||||
proc, e := FS("fixtures").NewProc(26231)
|
||||
if e != nil {
|
||||
t.Fatalf("failed to create proc: %v", err)
|
||||
}
|
||||
|
||||
mounts, err = proc.MountStats()
|
||||
}
|
||||
|
||||
if tt.invalid && err == nil {
|
||||
t.Error("expected an error, but none occurred")
|
||||
}
|
||||
if !tt.invalid && err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if want, have := tt.mounts, mounts; !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("mounts:\nwant:\n%v\nhave:\n%v", mountsStr(want), mountsStr(have))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func mountsStr(mounts []*Mount) string {
|
||||
var out string
|
||||
for i, m := range mounts {
|
||||
out += fmt.Sprintf("[%d] %q on %q (%q)", i, m.Device, m.Mount, m.Type)
|
||||
|
||||
stats, ok := m.Stats.(*MountStatsNFS)
|
||||
if !ok {
|
||||
out += "\n"
|
||||
continue
|
||||
}
|
||||
|
||||
out += fmt.Sprintf("\n\t- v%s, age: %s", stats.StatVersion, stats.Age)
|
||||
out += fmt.Sprintf("\n\t- bytes: %v", stats.Bytes)
|
||||
out += fmt.Sprintf("\n\t- events: %v", stats.Events)
|
||||
out += fmt.Sprintf("\n\t- transport: %v", stats.Transport)
|
||||
out += fmt.Sprintf("\n\t- per-operation stats:")
|
||||
|
||||
for _, o := range stats.Operations {
|
||||
out += fmt.Sprintf("\n\t\t- %v", o)
|
||||
}
|
||||
|
||||
out += "\n"
|
||||
}
|
||||
|
||||
return out
|
||||
}
|
||||
86
vendor/github.com/prometheus/procfs/net_dev_test.go
generated
vendored
86
vendor/github.com/prometheus/procfs/net_dev_test.go
generated
vendored
|
|
@ -1,86 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
305
vendor/github.com/prometheus/procfs/nfs/parse_nfs_test.go
generated
vendored
305
vendor/github.com/prometheus/procfs/nfs/parse_nfs_test.go
generated
vendored
|
|
@ -1,305 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package nfs_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/procfs/nfs"
|
||||
)
|
||||
|
||||
func TestNewNFSClientRPCStats(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
stats *nfs.ClientRPCStats
|
||||
invalid bool
|
||||
}{
|
||||
{
|
||||
name: "invalid file",
|
||||
content: "invalid",
|
||||
invalid: true,
|
||||
}, {
|
||||
name: "good old kernel version file",
|
||||
content: `net 70 70 69 45
|
||||
rpc 1218785755 374636 1218815394
|
||||
proc2 18 16 57 74 52 71 73 45 86 0 52 83 61 17 53 50 23 70 82
|
||||
proc3 22 0 1061909262 48906 4077635 117661341 5 29391916 2570425 2993289 590 0 0 7815 15 1130 0 3983 92385 13332 2 1 23729
|
||||
proc4 48 98 51 54 83 85 23 24 1 28 73 68 83 12 84 39 68 59 58 88 29 74 69 96 21 84 15 53 86 54 66 56 97 36 49 32 85 81 11 58 32 67 13 28 35 90 1 26 1337
|
||||
`,
|
||||
stats: &nfs.ClientRPCStats{
|
||||
Network: nfs.Network{
|
||||
NetCount: 70,
|
||||
UDPCount: 70,
|
||||
TCPCount: 69,
|
||||
TCPConnect: 45,
|
||||
},
|
||||
ClientRPC: nfs.ClientRPC{
|
||||
RPCCount: 1218785755,
|
||||
Retransmissions: 374636,
|
||||
AuthRefreshes: 1218815394,
|
||||
},
|
||||
V2Stats: nfs.V2Stats{
|
||||
Null: 16,
|
||||
GetAttr: 57,
|
||||
SetAttr: 74,
|
||||
Root: 52,
|
||||
Lookup: 71,
|
||||
ReadLink: 73,
|
||||
Read: 45,
|
||||
WrCache: 86,
|
||||
Write: 0,
|
||||
Create: 52,
|
||||
Remove: 83,
|
||||
Rename: 61,
|
||||
Link: 17,
|
||||
SymLink: 53,
|
||||
MkDir: 50,
|
||||
RmDir: 23,
|
||||
ReadDir: 70,
|
||||
FsStat: 82,
|
||||
},
|
||||
V3Stats: nfs.V3Stats{
|
||||
Null: 0,
|
||||
GetAttr: 1061909262,
|
||||
SetAttr: 48906,
|
||||
Lookup: 4077635,
|
||||
Access: 117661341,
|
||||
ReadLink: 5,
|
||||
Read: 29391916,
|
||||
Write: 2570425,
|
||||
Create: 2993289,
|
||||
MkDir: 590,
|
||||
SymLink: 0,
|
||||
MkNod: 0,
|
||||
Remove: 7815,
|
||||
RmDir: 15,
|
||||
Rename: 1130,
|
||||
Link: 0,
|
||||
ReadDir: 3983,
|
||||
ReadDirPlus: 92385,
|
||||
FsStat: 13332,
|
||||
FsInfo: 2,
|
||||
PathConf: 1,
|
||||
Commit: 23729},
|
||||
ClientV4Stats: nfs.ClientV4Stats{
|
||||
Null: 98,
|
||||
Read: 51,
|
||||
Write: 54,
|
||||
Commit: 83,
|
||||
Open: 85,
|
||||
OpenConfirm: 23,
|
||||
OpenNoattr: 24,
|
||||
OpenDowngrade: 1,
|
||||
Close: 28,
|
||||
Setattr: 73,
|
||||
FsInfo: 68,
|
||||
Renew: 83,
|
||||
SetClientID: 12,
|
||||
SetClientIDConfirm: 84,
|
||||
Lock: 39,
|
||||
Lockt: 68,
|
||||
Locku: 59,
|
||||
Access: 58,
|
||||
Getattr: 88,
|
||||
Lookup: 29,
|
||||
LookupRoot: 74,
|
||||
Remove: 69,
|
||||
Rename: 96,
|
||||
Link: 21,
|
||||
Symlink: 84,
|
||||
Create: 15,
|
||||
Pathconf: 53,
|
||||
StatFs: 86,
|
||||
ReadLink: 54,
|
||||
ReadDir: 66,
|
||||
ServerCaps: 56,
|
||||
DelegReturn: 97,
|
||||
GetACL: 36,
|
||||
SetACL: 49,
|
||||
FsLocations: 32,
|
||||
ReleaseLockowner: 85,
|
||||
Secinfo: 81,
|
||||
FsidPresent: 11,
|
||||
ExchangeID: 58,
|
||||
CreateSession: 32,
|
||||
DestroySession: 67,
|
||||
Sequence: 13,
|
||||
GetLeaseTime: 28,
|
||||
ReclaimComplete: 35,
|
||||
LayoutGet: 90,
|
||||
GetDeviceInfo: 1,
|
||||
LayoutCommit: 26,
|
||||
LayoutReturn: 1337,
|
||||
SecinfoNoName: 0,
|
||||
TestStateID: 0,
|
||||
FreeStateID: 0,
|
||||
GetDeviceList: 0,
|
||||
BindConnToSession: 0,
|
||||
DestroyClientID: 0,
|
||||
Seek: 0,
|
||||
Allocate: 0,
|
||||
DeAllocate: 0,
|
||||
LayoutStats: 0,
|
||||
Clone: 0,
|
||||
},
|
||||
},
|
||||
}, {
|
||||
name: "good file",
|
||||
content: `net 18628 0 18628 6
|
||||
rpc 4329785 0 4338291
|
||||
proc2 18 2 69 0 0 4410 0 0 0 0 0 0 0 0 0 0 0 99 2
|
||||
proc3 22 1 4084749 29200 94754 32580 186 47747 7981 8639 0 6356 0 6962 0 7958 0 0 241 4 4 2 39
|
||||
proc4 61 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
`,
|
||||
stats: &nfs.ClientRPCStats{
|
||||
Network: nfs.Network{
|
||||
NetCount: 18628,
|
||||
UDPCount: 0,
|
||||
TCPCount: 18628,
|
||||
TCPConnect: 6,
|
||||
},
|
||||
ClientRPC: nfs.ClientRPC{
|
||||
RPCCount: 4329785,
|
||||
Retransmissions: 0,
|
||||
AuthRefreshes: 4338291,
|
||||
},
|
||||
V2Stats: nfs.V2Stats{
|
||||
Null: 2,
|
||||
GetAttr: 69,
|
||||
SetAttr: 0,
|
||||
Root: 0,
|
||||
Lookup: 4410,
|
||||
ReadLink: 0,
|
||||
Read: 0,
|
||||
WrCache: 0,
|
||||
Write: 0,
|
||||
Create: 0,
|
||||
Remove: 0,
|
||||
Rename: 0,
|
||||
Link: 0,
|
||||
SymLink: 0,
|
||||
MkDir: 0,
|
||||
RmDir: 0,
|
||||
ReadDir: 99,
|
||||
FsStat: 2,
|
||||
},
|
||||
V3Stats: nfs.V3Stats{
|
||||
Null: 1,
|
||||
GetAttr: 4084749,
|
||||
SetAttr: 29200,
|
||||
Lookup: 94754,
|
||||
Access: 32580,
|
||||
ReadLink: 186,
|
||||
Read: 47747,
|
||||
Write: 7981,
|
||||
Create: 8639,
|
||||
MkDir: 0,
|
||||
SymLink: 6356,
|
||||
MkNod: 0,
|
||||
Remove: 6962,
|
||||
RmDir: 0,
|
||||
Rename: 7958,
|
||||
Link: 0,
|
||||
ReadDir: 0,
|
||||
ReadDirPlus: 241,
|
||||
FsStat: 4,
|
||||
FsInfo: 4,
|
||||
PathConf: 2,
|
||||
Commit: 39,
|
||||
},
|
||||
ClientV4Stats: nfs.ClientV4Stats{
|
||||
Null: 1,
|
||||
Read: 0,
|
||||
Write: 0,
|
||||
Commit: 0,
|
||||
Open: 0,
|
||||
OpenConfirm: 0,
|
||||
OpenNoattr: 0,
|
||||
OpenDowngrade: 0,
|
||||
Close: 0,
|
||||
Setattr: 0,
|
||||
FsInfo: 0,
|
||||
Renew: 0,
|
||||
SetClientID: 1,
|
||||
SetClientIDConfirm: 1,
|
||||
Lock: 0,
|
||||
Lockt: 0,
|
||||
Locku: 0,
|
||||
Access: 0,
|
||||
Getattr: 0,
|
||||
Lookup: 0,
|
||||
LookupRoot: 0,
|
||||
Remove: 2,
|
||||
Rename: 0,
|
||||
Link: 0,
|
||||
Symlink: 0,
|
||||
Create: 0,
|
||||
Pathconf: 0,
|
||||
StatFs: 0,
|
||||
ReadLink: 0,
|
||||
ReadDir: 0,
|
||||
ServerCaps: 0,
|
||||
DelegReturn: 0,
|
||||
GetACL: 0,
|
||||
SetACL: 0,
|
||||
FsLocations: 0,
|
||||
ReleaseLockowner: 0,
|
||||
Secinfo: 0,
|
||||
FsidPresent: 0,
|
||||
ExchangeID: 0,
|
||||
CreateSession: 0,
|
||||
DestroySession: 0,
|
||||
Sequence: 0,
|
||||
GetLeaseTime: 0,
|
||||
ReclaimComplete: 0,
|
||||
LayoutGet: 0,
|
||||
GetDeviceInfo: 0,
|
||||
LayoutCommit: 0,
|
||||
LayoutReturn: 0,
|
||||
SecinfoNoName: 0,
|
||||
TestStateID: 0,
|
||||
FreeStateID: 0,
|
||||
GetDeviceList: 0,
|
||||
BindConnToSession: 0,
|
||||
DestroyClientID: 0,
|
||||
Seek: 0,
|
||||
Allocate: 0,
|
||||
DeAllocate: 0,
|
||||
LayoutStats: 0,
|
||||
Clone: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
stats, err := nfs.ParseClientRPCStats(strings.NewReader(tt.content))
|
||||
|
||||
if tt.invalid && err == nil {
|
||||
t.Fatal("expected an error, but none occurred")
|
||||
}
|
||||
if !tt.invalid && err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
|
||||
t.Fatalf("unexpected NFS stats:\nwant:\n%v\nhave:\n%v", want, have)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
196
vendor/github.com/prometheus/procfs/nfs/parse_nfsd_test.go
generated
vendored
196
vendor/github.com/prometheus/procfs/nfs/parse_nfsd_test.go
generated
vendored
|
|
@ -1,196 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package nfs_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/procfs/nfs"
|
||||
)
|
||||
|
||||
func TestNewNFSdServerRPCStats(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
content string
|
||||
stats *nfs.ServerRPCStats
|
||||
invalid bool
|
||||
}{
|
||||
{
|
||||
name: "invalid file",
|
||||
content: "invalid",
|
||||
invalid: true,
|
||||
}, {
|
||||
name: "good file",
|
||||
content: `rc 0 6 18622
|
||||
fh 0 0 0 0 0
|
||||
io 157286400 0
|
||||
th 8 0 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000 0.000
|
||||
ra 32 0 0 0 0 0 0 0 0 0 0 0
|
||||
net 18628 0 18628 6
|
||||
rpc 18628 0 0 0 0
|
||||
proc2 18 2 69 0 0 4410 0 0 0 0 0 0 0 0 0 0 0 99 2
|
||||
proc3 22 2 112 0 2719 111 0 0 0 0 0 0 0 0 0 0 0 27 216 0 2 1 0
|
||||
proc4 2 2 10853
|
||||
proc4ops 72 0 0 0 1098 2 0 0 0 0 8179 5896 0 0 0 0 5900 0 0 2 0 2 0 9609 0 2 150 1272 0 0 0 1236 0 0 0 0 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
`,
|
||||
stats: &nfs.ServerRPCStats{
|
||||
ReplyCache: nfs.ReplyCache{
|
||||
Hits: 0,
|
||||
Misses: 6,
|
||||
NoCache: 18622,
|
||||
},
|
||||
FileHandles: nfs.FileHandles{
|
||||
Stale: 0,
|
||||
TotalLookups: 0,
|
||||
AnonLookups: 0,
|
||||
DirNoCache: 0,
|
||||
NoDirNoCache: 0,
|
||||
},
|
||||
InputOutput: nfs.InputOutput{
|
||||
Read: 157286400,
|
||||
Write: 0,
|
||||
},
|
||||
Threads: nfs.Threads{
|
||||
Threads: 8,
|
||||
FullCnt: 0,
|
||||
},
|
||||
ReadAheadCache: nfs.ReadAheadCache{
|
||||
CacheSize: 32,
|
||||
CacheHistogram: []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
NotFound: 0,
|
||||
},
|
||||
Network: nfs.Network{
|
||||
NetCount: 18628,
|
||||
UDPCount: 0,
|
||||
TCPCount: 18628,
|
||||
TCPConnect: 6,
|
||||
},
|
||||
ServerRPC: nfs.ServerRPC{
|
||||
RPCCount: 18628,
|
||||
BadCnt: 0,
|
||||
BadFmt: 0,
|
||||
BadAuth: 0,
|
||||
BadcInt: 0,
|
||||
},
|
||||
V2Stats: nfs.V2Stats{
|
||||
Null: 2,
|
||||
GetAttr: 69,
|
||||
SetAttr: 0,
|
||||
Root: 0,
|
||||
Lookup: 4410,
|
||||
ReadLink: 0,
|
||||
Read: 0,
|
||||
WrCache: 0,
|
||||
Write: 0,
|
||||
Create: 0,
|
||||
Remove: 0,
|
||||
Rename: 0,
|
||||
Link: 0,
|
||||
SymLink: 0,
|
||||
MkDir: 0,
|
||||
RmDir: 0,
|
||||
ReadDir: 99,
|
||||
FsStat: 2,
|
||||
},
|
||||
V3Stats: nfs.V3Stats{
|
||||
Null: 2,
|
||||
GetAttr: 112,
|
||||
SetAttr: 0,
|
||||
Lookup: 2719,
|
||||
Access: 111,
|
||||
ReadLink: 0,
|
||||
Read: 0,
|
||||
Write: 0,
|
||||
Create: 0,
|
||||
MkDir: 0,
|
||||
SymLink: 0,
|
||||
MkNod: 0,
|
||||
Remove: 0,
|
||||
RmDir: 0,
|
||||
Rename: 0,
|
||||
Link: 0,
|
||||
ReadDir: 27,
|
||||
ReadDirPlus: 216,
|
||||
FsStat: 0,
|
||||
FsInfo: 2,
|
||||
PathConf: 1,
|
||||
Commit: 0,
|
||||
},
|
||||
ServerV4Stats: nfs.ServerV4Stats{
|
||||
Null: 2,
|
||||
Compound: 10853,
|
||||
},
|
||||
V4Ops: nfs.V4Ops{
|
||||
Op0Unused: 0,
|
||||
Op1Unused: 0,
|
||||
Op2Future: 0,
|
||||
Access: 1098,
|
||||
Close: 2,
|
||||
Commit: 0,
|
||||
Create: 0,
|
||||
DelegPurge: 0,
|
||||
DelegReturn: 0,
|
||||
GetAttr: 8179,
|
||||
GetFH: 5896,
|
||||
Link: 0,
|
||||
Lock: 0,
|
||||
Lockt: 0,
|
||||
Locku: 0,
|
||||
Lookup: 5900,
|
||||
LookupRoot: 0,
|
||||
Nverify: 0,
|
||||
Open: 2,
|
||||
OpenAttr: 0,
|
||||
OpenConfirm: 2,
|
||||
OpenDgrd: 0,
|
||||
PutFH: 9609,
|
||||
PutPubFH: 0,
|
||||
PutRootFH: 2,
|
||||
Read: 150,
|
||||
ReadDir: 1272,
|
||||
ReadLink: 0,
|
||||
Remove: 0,
|
||||
Rename: 0,
|
||||
Renew: 1236,
|
||||
RestoreFH: 0,
|
||||
SaveFH: 0,
|
||||
SecInfo: 0,
|
||||
SetAttr: 0,
|
||||
Verify: 3,
|
||||
Write: 3,
|
||||
RelLockOwner: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
stats, err := nfs.ParseServerRPCStats(strings.NewReader(tt.content))
|
||||
|
||||
if tt.invalid && err == nil {
|
||||
t.Fatal("expected an error, but none occurred")
|
||||
}
|
||||
if !tt.invalid && err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
|
||||
t.Fatalf("unexpected NFS stats:\nwant:\n%v\nhave:\n%v", want, have)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
20
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
20
vendor/github.com/prometheus/procfs/proc.go
generated
vendored
|
|
@ -156,6 +156,26 @@ func (p Proc) Executable() (string, error) {
|
|||
return exe, err
|
||||
}
|
||||
|
||||
// Cwd returns the absolute path to the current working directory of the process.
|
||||
func (p Proc) Cwd() (string, error) {
|
||||
wd, err := os.Readlink(p.path("cwd"))
|
||||
if os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return wd, err
|
||||
}
|
||||
|
||||
// RootDir returns the absolute path to the process's root directory (as set by chroot)
|
||||
func (p Proc) RootDir() (string, error) {
|
||||
rdir, err := os.Readlink(p.path("root"))
|
||||
if os.IsNotExist(err) {
|
||||
return "", nil
|
||||
}
|
||||
|
||||
return rdir, err
|
||||
}
|
||||
|
||||
// FileDescriptors returns the currently open file descriptors of a process.
|
||||
func (p Proc) FileDescriptors() ([]uintptr, error) {
|
||||
names, err := p.fileDescriptors()
|
||||
|
|
|
|||
46
vendor/github.com/prometheus/procfs/proc_io_test.go
generated
vendored
46
vendor/github.com/prometheus/procfs/proc_io_test.go
generated
vendored
|
|
@ -1,46 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestProcIO(t *testing.T) {
|
||||
p, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := p.NewIO()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
want int64
|
||||
have int64
|
||||
}{
|
||||
{name: "RChar", want: 750339, have: int64(s.RChar)},
|
||||
{name: "WChar", want: 818609, have: int64(s.WChar)},
|
||||
{name: "SyscR", want: 7405, have: int64(s.SyscR)},
|
||||
{name: "SyscW", want: 5245, have: int64(s.SyscW)},
|
||||
{name: "ReadBytes", want: 1024, have: int64(s.ReadBytes)},
|
||||
{name: "WriteBytes", want: 2048, have: int64(s.WriteBytes)},
|
||||
{name: "CancelledWriteBytes", want: -1024, have: s.CancelledWriteBytes},
|
||||
} {
|
||||
if test.want != test.have {
|
||||
t.Errorf("want %s %d, have %d", test.name, test.want, test.have)
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/github.com/prometheus/procfs/proc_limits_test.go
generated
vendored
44
vendor/github.com/prometheus/procfs/proc_limits_test.go
generated
vendored
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewLimits(t *testing.T) {
|
||||
p, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
l, err := p.NewLimits()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
want int64
|
||||
have int64
|
||||
}{
|
||||
{name: "cpu time", want: -1, have: l.CPUTime},
|
||||
{name: "open files", want: 2048, have: l.OpenFiles},
|
||||
{name: "msgqueue size", want: 819200, have: l.MsqqueueSize},
|
||||
{name: "nice priority", want: 0, have: l.NicePriority},
|
||||
{name: "address space", want: 8589934592, have: l.AddressSpace},
|
||||
} {
|
||||
if test.want != test.have {
|
||||
t.Errorf("want %s %d, have %d", test.name, test.want, test.have)
|
||||
}
|
||||
}
|
||||
}
|
||||
44
vendor/github.com/prometheus/procfs/proc_ns_test.go
generated
vendored
44
vendor/github.com/prometheus/procfs/proc_ns_test.go
generated
vendored
|
|
@ -1,44 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
123
vendor/github.com/prometheus/procfs/proc_stat_test.go
generated
vendored
123
vendor/github.com/prometheus/procfs/proc_stat_test.go
generated
vendored
|
|
@ -1,123 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestProcStat(t *testing.T) {
|
||||
p, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := p.NewStat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
want int
|
||||
have int
|
||||
}{
|
||||
{name: "pid", want: 26231, have: s.PID},
|
||||
{name: "user time", want: 1677, have: int(s.UTime)},
|
||||
{name: "system time", want: 44, have: int(s.STime)},
|
||||
{name: "start time", want: 82375, have: int(s.Starttime)},
|
||||
{name: "virtual memory size", want: 56274944, have: s.VSize},
|
||||
{name: "resident set size", want: 1981, have: s.RSS},
|
||||
} {
|
||||
if test.want != test.have {
|
||||
t.Errorf("want %s %d, have %d", test.name, test.want, test.have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcStatComm(t *testing.T) {
|
||||
s1, err := testProcStat(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := "vim", s1.Comm; want != have {
|
||||
t.Errorf("want comm %s, have %s", want, have)
|
||||
}
|
||||
|
||||
s2, err := testProcStat(584)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := "(a b ) ( c d) ", s2.Comm; want != have {
|
||||
t.Errorf("want comm %s, have %s", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcStatVirtualMemory(t *testing.T) {
|
||||
s, err := testProcStat(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if want, have := 56274944, s.VirtualMemory(); want != have {
|
||||
t.Errorf("want virtual memory %d, have %d", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcStatResidentMemory(t *testing.T) {
|
||||
s, err := testProcStat(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if want, have := 1981*os.Getpagesize(), s.ResidentMemory(); want != have {
|
||||
t.Errorf("want resident memory %d, have %d", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcStatStartTime(t *testing.T) {
|
||||
s, err := testProcStat(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
time, err := s.StartTime()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := 1418184099.75, time; want != have {
|
||||
t.Errorf("want start time %f, have %f", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProcStatCPUTime(t *testing.T) {
|
||||
s, err := testProcStat(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if want, have := 17.21, s.CPUTime(); want != have {
|
||||
t.Errorf("want cpu time %f, have %f", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
func testProcStat(pid int) (ProcStat, error) {
|
||||
p, err := FS("fixtures").NewProc(pid)
|
||||
if err != nil {
|
||||
return ProcStat{}, err
|
||||
}
|
||||
|
||||
return p.NewStat()
|
||||
}
|
||||
174
vendor/github.com/prometheus/procfs/proc_test.go
generated
vendored
174
vendor/github.com/prometheus/procfs/proc_test.go
generated
vendored
|
|
@ -1,174 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSelf(t *testing.T) {
|
||||
fs := FS("fixtures")
|
||||
|
||||
p1, err := fs.NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p2, err := fs.Self()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(p1, p2) {
|
||||
t.Errorf("want process %v, have %v", p1, p2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAllProcs(t *testing.T) {
|
||||
procs, err := FS("fixtures").AllProcs()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Sort(procs)
|
||||
for i, p := range []*Proc{{PID: 584}, {PID: 26231}} {
|
||||
if want, have := p.PID, procs[i].PID; want != have {
|
||||
t.Errorf("want processes %d, have %d", want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCmdLine(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
process int
|
||||
want []string
|
||||
}{
|
||||
{process: 26231, want: []string{"vim", "test.go", "+10"}},
|
||||
{process: 26232, want: []string{}},
|
||||
{process: 26233, want: []string{"com.github.uiautomator"}},
|
||||
} {
|
||||
p1, err := FS("fixtures").NewProc(tt.process)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c1, err := p1.CmdLine()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(tt.want, c1) {
|
||||
t.Errorf("want cmdline %v, have %v", tt.want, c1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestComm(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
process int
|
||||
want string
|
||||
}{
|
||||
{process: 26231, want: "vim"},
|
||||
{process: 26232, want: "ata_sff"},
|
||||
} {
|
||||
p1, err := FS("fixtures").NewProc(tt.process)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
c1, err := p1.Comm()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(tt.want, c1) {
|
||||
t.Errorf("want comm %v, have %v", tt.want, c1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestExecutable(t *testing.T) {
|
||||
for _, tt := range []struct {
|
||||
process int
|
||||
want string
|
||||
}{
|
||||
{process: 26231, want: "/usr/bin/vim"},
|
||||
{process: 26232, want: ""},
|
||||
} {
|
||||
p, err := FS("fixtures").NewProc(tt.process)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
exe, err := p.Executable()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(tt.want, exe) {
|
||||
t.Errorf("want absolute path to cmdline %v, have %v", tt.want, exe)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileDescriptors(t *testing.T) {
|
||||
p1, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fds, err := p1.FileDescriptors()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Sort(byUintptr(fds))
|
||||
if want := []uintptr{0, 1, 2, 3, 10}; !reflect.DeepEqual(want, fds) {
|
||||
t.Errorf("want fds %v, have %v", want, fds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileDescriptorTargets(t *testing.T) {
|
||||
p1, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fds, err := p1.FileDescriptorTargets()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sort.Strings(fds)
|
||||
var want = []string{
|
||||
"../../symlinktargets/abc",
|
||||
"../../symlinktargets/def",
|
||||
"../../symlinktargets/ghi",
|
||||
"../../symlinktargets/uvw",
|
||||
"../../symlinktargets/xyz",
|
||||
}
|
||||
if !reflect.DeepEqual(want, fds) {
|
||||
t.Errorf("want fds %v, have %v", want, fds)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFileDescriptorsLen(t *testing.T) {
|
||||
p1, err := FS("fixtures").NewProc(26231)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l, err := p1.FileDescriptorsLen()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if want, have := 5, l; want != have {
|
||||
t.Errorf("want fds %d, have %d", want, have)
|
||||
}
|
||||
}
|
||||
|
||||
type byUintptr []uintptr
|
||||
|
||||
func (a byUintptr) Len() int { return len(a) }
|
||||
func (a byUintptr) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a byUintptr) Less(i, j int) bool { return a[i] < a[j] }
|
||||
74
vendor/github.com/prometheus/procfs/stat_test.go
generated
vendored
74
vendor/github.com/prometheus/procfs/stat_test.go
generated
vendored
|
|
@ -1,74 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestStat(t *testing.T) {
|
||||
s, err := FS("fixtures").NewStat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// cpu
|
||||
if want, have := float64(301854)/userHZ, s.CPUTotal.User; want != have {
|
||||
t.Errorf("want cpu/user %v, have %v", want, have)
|
||||
}
|
||||
if want, have := float64(31)/userHZ, s.CPU[7].SoftIRQ; want != have {
|
||||
t.Errorf("want cpu7/softirq %v, have %v", want, have)
|
||||
}
|
||||
|
||||
// intr
|
||||
if want, have := uint64(8885917), s.IRQTotal; want != have {
|
||||
t.Errorf("want irq/total %d, have %d", want, have)
|
||||
}
|
||||
if want, have := uint64(1), s.IRQ[8]; want != have {
|
||||
t.Errorf("want irq8 %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// ctxt
|
||||
if want, have := uint64(38014093), s.ContextSwitches; want != have {
|
||||
t.Errorf("want context switches (ctxt) %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// btime
|
||||
if want, have := uint64(1418183276), s.BootTime; want != have {
|
||||
t.Errorf("want boot time (btime) %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// processes
|
||||
if want, have := uint64(26442), s.ProcessCreated; want != have {
|
||||
t.Errorf("want process created (processes) %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// procs_running
|
||||
if want, have := uint64(2), s.ProcessesRunning; want != have {
|
||||
t.Errorf("want processes running (procs_running) %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// procs_blocked
|
||||
if want, have := uint64(1), s.ProcessesBlocked; want != have {
|
||||
t.Errorf("want processes blocked (procs_blocked) %d, have %d", want, have)
|
||||
}
|
||||
|
||||
// softirq
|
||||
if want, have := uint64(5057579), s.SoftIRQTotal; want != have {
|
||||
t.Errorf("want softirq total %d, have %d", want, have)
|
||||
}
|
||||
|
||||
if want, have := uint64(508444), s.SoftIRQ.Rcu; want != have {
|
||||
t.Errorf("want softirq RCU %d, have %d", want, have)
|
||||
}
|
||||
|
||||
}
|
||||
1
vendor/github.com/prometheus/procfs/sysfs/.gitignore
generated
vendored
1
vendor/github.com/prometheus/procfs/sysfs/.gitignore
generated
vendored
|
|
@ -1 +0,0 @@
|
|||
fixtures/
|
||||
142
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
142
vendor/github.com/prometheus/procfs/sysfs/fixtures.ttar
generated
vendored
|
|
@ -389,6 +389,148 @@ Lines: 1
|
|||
0
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpu0
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu0/cpufreq
|
||||
SymlinkTo: ../cpufreq/policy0
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpu1
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpu1/cpufreq
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/cpuinfo_cur_freq
|
||||
Lines: 1
|
||||
1200195
|
||||
Mode: 400
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/cpuinfo_max_freq
|
||||
Lines: 1
|
||||
3300000
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/cpuinfo_min_freq
|
||||
Lines: 1
|
||||
1200000
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/cpuinfo_transition_latency
|
||||
Lines: 1
|
||||
4294967295
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/related_cpus
|
||||
Lines: 1
|
||||
1
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_available_governors
|
||||
Lines: 1
|
||||
performance powersave
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_driver
|
||||
Lines: 1
|
||||
intel_pstate
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_governor
|
||||
Lines: 1
|
||||
powersave
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
|
||||
Lines: 1
|
||||
3300000
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
|
||||
Lines: 1
|
||||
1200000
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpu1/cpufreq/scaling_setspeed
|
||||
Lines: 1
|
||||
<unsupported>
|
||||
Mode: 664
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpufreq
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpufreq/policy0
|
||||
Mode: 775
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/affected_cpus
|
||||
Lines: 1
|
||||
0
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/cpuinfo_max_freq
|
||||
Lines: 1
|
||||
2400000
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/cpuinfo_min_freq
|
||||
Lines: 1
|
||||
800000
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/cpuinfo_transition_latency
|
||||
Lines: 1
|
||||
0
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/related_cpus
|
||||
Lines: 1
|
||||
0
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_available_governors
|
||||
Lines: 1
|
||||
performance powersave
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_cur_freq
|
||||
Lines: 1
|
||||
1219917
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_driver
|
||||
Lines: 1
|
||||
intel_pstate
|
||||
Mode: 444
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_governor
|
||||
Lines: 1
|
||||
powersave
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_max_freq
|
||||
Lines: 1
|
||||
2400000
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_min_freq
|
||||
Lines: 1
|
||||
800000
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Path: fixtures/devices/system/cpu/cpufreq/policy0/scaling_setspeed
|
||||
Lines: 1
|
||||
<unsupported>
|
||||
Mode: 644
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/devices/system/cpu/cpufreq/policy1
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
Directory: fixtures/fs
|
||||
Mode: 755
|
||||
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
|||
108
vendor/github.com/prometheus/procfs/sysfs/fs_test.go
generated
vendored
108
vendor/github.com/prometheus/procfs/sysfs/fs_test.go
generated
vendored
|
|
@ -1,108 +0,0 @@
|
|||
// Copyright 2017 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sysfs
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNewFS(t *testing.T) {
|
||||
if _, err := NewFS("foobar"); err == nil {
|
||||
t.Error("want NewFS to fail for non-existing mount point")
|
||||
}
|
||||
|
||||
if _, err := NewFS("doc.go"); err == nil {
|
||||
t.Error("want NewFS to fail if mount point is not a directory")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSXFSStats(t *testing.T) {
|
||||
stats, err := FS("fixtures").XFSStats()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse XFS stats: %v", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
allocated uint32
|
||||
}{
|
||||
{
|
||||
name: "sda1",
|
||||
allocated: 1,
|
||||
},
|
||||
{
|
||||
name: "sdb1",
|
||||
allocated: 2,
|
||||
},
|
||||
}
|
||||
|
||||
const expect = 2
|
||||
|
||||
if l := len(stats); l != expect {
|
||||
t.Fatalf("unexpected number of XFS stats: %d", l)
|
||||
}
|
||||
if l := len(tests); l != expect {
|
||||
t.Fatalf("unexpected number of tests: %d", l)
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
if want, got := tt.name, stats[i].Name; want != got {
|
||||
t.Errorf("unexpected stats name:\nwant: %q\nhave: %q", want, got)
|
||||
}
|
||||
|
||||
if want, got := tt.allocated, stats[i].ExtentAllocation.ExtentsAllocated; want != got {
|
||||
t.Errorf("unexpected extents allocated:\nwant: %d\nhave: %d", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFSBcacheStats(t *testing.T) {
|
||||
stats, err := FS("fixtures").BcacheStats()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to parse bcache stats: %v", err)
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
bdevs int
|
||||
caches int
|
||||
}{
|
||||
{
|
||||
name: "deaddd54-c735-46d5-868e-f331c5fd7c74",
|
||||
bdevs: 1,
|
||||
caches: 1,
|
||||
},
|
||||
}
|
||||
|
||||
const expect = 1
|
||||
|
||||
if l := len(stats); l != expect {
|
||||
t.Fatalf("unexpected number of bcache stats: %d", l)
|
||||
}
|
||||
if l := len(tests); l != expect {
|
||||
t.Fatalf("unexpected number of tests: %d", l)
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
if want, got := tt.name, stats[i].Name; want != got {
|
||||
t.Errorf("unexpected stats name:\nwant: %q\nhave: %q", want, got)
|
||||
}
|
||||
|
||||
if want, got := tt.bdevs, len(stats[i].Bdevs); want != got {
|
||||
t.Errorf("unexpected value allocated:\nwant: %d\nhave: %d", want, got)
|
||||
}
|
||||
|
||||
if want, got := tt.caches, len(stats[i].Caches); want != got {
|
||||
t.Errorf("unexpected value allocated:\nwant: %d\nhave: %d", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
31
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
31
vendor/github.com/prometheus/procfs/sysfs/net_class.go
generated
vendored
|
|
@ -11,6 +11,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
|
@ -20,7 +22,8 @@ import (
|
|||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
)
|
||||
|
||||
// NetClassIface contains info from files in /sys/class/net/<iface>
|
||||
|
|
@ -109,7 +112,7 @@ func (nc NetClass) parseNetClassIface(devicePath string) (*NetClassIface, error)
|
|||
panic(fmt.Errorf("field %s does not have a filename tag", fieldType.Name))
|
||||
}
|
||||
|
||||
fileContents, err := sysReadFile(devicePath + "/" + fieldType.Tag.Get("fileName"))
|
||||
value, err := util.SysReadFile(devicePath + "/" + fieldType.Tag.Get("fileName"))
|
||||
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) || err.Error() == "operation not supported" || err.Error() == "invalid argument" {
|
||||
|
|
@ -117,7 +120,6 @@ func (nc NetClass) parseNetClassIface(devicePath string) (*NetClassIface, error)
|
|||
}
|
||||
return nil, fmt.Errorf("could not access file %s: %s", fieldType.Tag.Get("fileName"), err)
|
||||
}
|
||||
value := strings.TrimSpace(string(fileContents))
|
||||
|
||||
switch fieldValue.Kind() {
|
||||
case reflect.String:
|
||||
|
|
@ -149,26 +151,3 @@ func (nc NetClass) parseNetClassIface(devicePath string) (*NetClassIface, error)
|
|||
|
||||
return &interfaceClass, nil
|
||||
}
|
||||
|
||||
// sysReadFile is a simplified ioutil.ReadFile that invokes syscall.Read directly.
|
||||
// https://github.com/prometheus/node_exporter/pull/728/files
|
||||
func sysReadFile(file string) ([]byte, error) {
|
||||
f, err := os.Open(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// On some machines, hwmon drivers are broken and return EAGAIN. This causes
|
||||
// Go's ioutil.ReadFile implementation to poll forever.
|
||||
//
|
||||
// Since we either want to read data or bail immediately, do the simplest
|
||||
// possible read using syscall directly.
|
||||
b := make([]byte, 128)
|
||||
n, err := syscall.Read(int(f.Fd()), b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return b[:n], nil
|
||||
}
|
||||
|
|
|
|||
88
vendor/github.com/prometheus/procfs/sysfs/net_class_test.go
generated
vendored
88
vendor/github.com/prometheus/procfs/sysfs/net_class_test.go
generated
vendored
|
|
@ -1,88 +0,0 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewNetClass(t *testing.T) {
|
||||
fs, err := NewFS("fixtures")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
nc, err := fs.NewNetClass()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
var (
|
||||
addrAssignType int64 = 3
|
||||
addrLen int64 = 6
|
||||
carrier int64 = 1
|
||||
carrierChanges int64 = 2
|
||||
carrierDownCount int64 = 1
|
||||
carrierUpCount int64 = 1
|
||||
devID int64 = 32
|
||||
dormant int64 = 1
|
||||
flags int64 = 4867
|
||||
ifIndex int64 = 2
|
||||
ifLink int64 = 2
|
||||
linkMode int64 = 1
|
||||
mtu int64 = 1500
|
||||
nameAssignType int64 = 2
|
||||
netDevGroup int64 = 0
|
||||
speed int64 = 1000
|
||||
txQueueLen int64 = 1000
|
||||
netType int64 = 1
|
||||
)
|
||||
|
||||
netClass := NetClass{
|
||||
"eth0": {
|
||||
Address: "01:01:01:01:01:01",
|
||||
AddrAssignType: &addrAssignType,
|
||||
AddrLen: &addrLen,
|
||||
Broadcast: "ff:ff:ff:ff:ff:ff",
|
||||
Carrier: &carrier,
|
||||
CarrierChanges: &carrierChanges,
|
||||
CarrierDownCount: &carrierDownCount,
|
||||
CarrierUpCount: &carrierUpCount,
|
||||
DevID: &devID,
|
||||
Dormant: &dormant,
|
||||
Duplex: "full",
|
||||
Flags: &flags,
|
||||
IfAlias: "",
|
||||
IfIndex: &ifIndex,
|
||||
IfLink: &ifLink,
|
||||
LinkMode: &linkMode,
|
||||
MTU: &mtu,
|
||||
Name: "eth0",
|
||||
NameAssignType: &nameAssignType,
|
||||
NetDevGroup: &netDevGroup,
|
||||
OperState: "up",
|
||||
PhysPortID: "",
|
||||
PhysPortName: "",
|
||||
PhysSwitchID: "",
|
||||
Speed: &speed,
|
||||
TxQueueLen: &txQueueLen,
|
||||
Type: &netType,
|
||||
},
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(netClass, nc) {
|
||||
t.Errorf("Result not correct: want %v, have %v", netClass, nc)
|
||||
}
|
||||
}
|
||||
141
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
Normal file
141
vendor/github.com/prometheus/procfs/sysfs/system_cpu.go
generated
vendored
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
// Copyright 2018 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// +build !windows
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/prometheus/procfs/internal/util"
|
||||
)
|
||||
|
||||
// SystemCPUCpufreqStats contains stats from devices/system/cpu/cpu[0-9]*/cpufreq/...
|
||||
type SystemCPUCpufreqStats struct {
|
||||
Name string
|
||||
CurrentFrequency uint64
|
||||
MinimumFrequency uint64
|
||||
MaximumFrequency uint64
|
||||
TransitionLatency uint64
|
||||
AvailableGovernors string
|
||||
Driver string
|
||||
Govenor string
|
||||
RelatedCpus string
|
||||
SetSpeed string
|
||||
}
|
||||
|
||||
// TODO: Add topology support.
|
||||
|
||||
// TODO: Add thermal_throttle support.
|
||||
|
||||
// NewSystemCpufreq returns CPU frequency metrics for all CPUs.
|
||||
func NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) {
|
||||
fs, err := NewFS(DefaultMountPoint)
|
||||
if err != nil {
|
||||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
return fs.NewSystemCpufreq()
|
||||
}
|
||||
|
||||
// NewSystemCpufreq returns CPU frequency metrics for all CPUs.
|
||||
func (fs FS) NewSystemCpufreq() ([]SystemCPUCpufreqStats, error) {
|
||||
var cpufreq = &SystemCPUCpufreqStats{}
|
||||
|
||||
cpus, err := filepath.Glob(fs.Path("devices/system/cpu/cpu[0-9]*"))
|
||||
if err != nil {
|
||||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
systemCpufreq := []SystemCPUCpufreqStats{}
|
||||
for _, cpu := range cpus {
|
||||
cpuName := filepath.Base(cpu)
|
||||
cpuNum := strings.TrimPrefix(cpuName, "cpu")
|
||||
|
||||
cpuCpufreqPath := filepath.Join(cpu, "cpufreq")
|
||||
if _, err := os.Stat(cpuCpufreqPath); os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
if _, err = os.Stat(filepath.Join(cpuCpufreqPath, "scaling_cur_freq")); err == nil {
|
||||
cpufreq, err = parseCpufreqCpuinfo("scaling", cpuCpufreqPath)
|
||||
} else if _, err = os.Stat(filepath.Join(cpuCpufreqPath, "cpuinfo_cur_freq")); err == nil {
|
||||
// Older kernels have metrics named `cpuinfo_...`.
|
||||
cpufreq, err = parseCpufreqCpuinfo("cpuinfo", cpuCpufreqPath)
|
||||
} else {
|
||||
return []SystemCPUCpufreqStats{}, fmt.Errorf("CPU %v is missing cpufreq", cpu)
|
||||
}
|
||||
if err != nil {
|
||||
return []SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
cpufreq.Name = cpuNum
|
||||
systemCpufreq = append(systemCpufreq, *cpufreq)
|
||||
}
|
||||
|
||||
return systemCpufreq, nil
|
||||
}
|
||||
|
||||
func parseCpufreqCpuinfo(prefix string, cpuPath string) (*SystemCPUCpufreqStats, error) {
|
||||
uintFiles := []string{
|
||||
prefix + "_cur_freq",
|
||||
prefix + "_max_freq",
|
||||
prefix + "_min_freq",
|
||||
"cpuinfo_transition_latency",
|
||||
}
|
||||
uintOut := make([]uint64, len(uintFiles))
|
||||
|
||||
for i, f := range uintFiles {
|
||||
v, err := util.ReadUintFromFile(filepath.Join(cpuPath, f))
|
||||
if err != nil {
|
||||
return &SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
|
||||
uintOut[i] = v
|
||||
}
|
||||
|
||||
stringFiles := []string{
|
||||
"scaling_available_governors",
|
||||
"scaling_driver",
|
||||
"scaling_governor",
|
||||
"related_cpus",
|
||||
"scaling_setspeed",
|
||||
}
|
||||
stringOut := make([]string, len(stringFiles))
|
||||
var err error
|
||||
|
||||
for i, f := range stringFiles {
|
||||
stringOut[i], err = util.SysReadFile(filepath.Join(cpuPath, f))
|
||||
if err != nil {
|
||||
return &SystemCPUCpufreqStats{}, err
|
||||
}
|
||||
}
|
||||
|
||||
return &SystemCPUCpufreqStats{
|
||||
CurrentFrequency: uintOut[0],
|
||||
MaximumFrequency: uintOut[1],
|
||||
MinimumFrequency: uintOut[2],
|
||||
TransitionLatency: uintOut[3],
|
||||
AvailableGovernors: stringOut[0],
|
||||
Driver: stringOut[1],
|
||||
Govenor: stringOut[2],
|
||||
RelatedCpus: stringOut[3],
|
||||
SetSpeed: stringOut[4],
|
||||
}, nil
|
||||
}
|
||||
66
vendor/github.com/prometheus/procfs/xfrm_test.go
generated
vendored
66
vendor/github.com/prometheus/procfs/xfrm_test.go
generated
vendored
|
|
@ -1,66 +0,0 @@
|
|||
// Copyright 2017 Prometheus Team
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package procfs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestXfrmStats(t *testing.T) {
|
||||
xfrmStats, err := FS("fixtures").NewXfrmStat()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, test := range []struct {
|
||||
name string
|
||||
want int
|
||||
got int
|
||||
}{
|
||||
{name: "XfrmInError", want: 1, got: xfrmStats.XfrmInError},
|
||||
{name: "XfrmInBufferError", want: 2, got: xfrmStats.XfrmInBufferError},
|
||||
{name: "XfrmInHdrError", want: 4, got: xfrmStats.XfrmInHdrError},
|
||||
{name: "XfrmInNoStates", want: 3, got: xfrmStats.XfrmInNoStates},
|
||||
{name: "XfrmInStateProtoError", want: 40, got: xfrmStats.XfrmInStateProtoError},
|
||||
{name: "XfrmInStateModeError", want: 100, got: xfrmStats.XfrmInStateModeError},
|
||||
{name: "XfrmInStateSeqError", want: 6000, got: xfrmStats.XfrmInStateSeqError},
|
||||
{name: "XfrmInStateExpired", want: 4, got: xfrmStats.XfrmInStateExpired},
|
||||
{name: "XfrmInStateMismatch", want: 23451, got: xfrmStats.XfrmInStateMismatch},
|
||||
{name: "XfrmInStateInvalid", want: 55555, got: xfrmStats.XfrmInStateInvalid},
|
||||
{name: "XfrmInTmplMismatch", want: 51, got: xfrmStats.XfrmInTmplMismatch},
|
||||
{name: "XfrmInNoPols", want: 65432, got: xfrmStats.XfrmInNoPols},
|
||||
{name: "XfrmInPolBlock", want: 100, got: xfrmStats.XfrmInPolBlock},
|
||||
{name: "XfrmInPolError", want: 10000, got: xfrmStats.XfrmInPolError},
|
||||
{name: "XfrmOutError", want: 1000000, got: xfrmStats.XfrmOutError},
|
||||
{name: "XfrmOutBundleGenError", want: 43321, got: xfrmStats.XfrmOutBundleGenError},
|
||||
{name: "XfrmOutBundleCheckError", want: 555, got: xfrmStats.XfrmOutBundleCheckError},
|
||||
{name: "XfrmOutNoStates", want: 869, got: xfrmStats.XfrmOutNoStates},
|
||||
{name: "XfrmOutStateProtoError", want: 4542, got: xfrmStats.XfrmOutStateProtoError},
|
||||
{name: "XfrmOutStateModeError", want: 4, got: xfrmStats.XfrmOutStateModeError},
|
||||
{name: "XfrmOutStateSeqError", want: 543, got: xfrmStats.XfrmOutStateSeqError},
|
||||
{name: "XfrmOutStateExpired", want: 565, got: xfrmStats.XfrmOutStateExpired},
|
||||
{name: "XfrmOutPolBlock", want: 43456, got: xfrmStats.XfrmOutPolBlock},
|
||||
{name: "XfrmOutPolDead", want: 7656, got: xfrmStats.XfrmOutPolDead},
|
||||
{name: "XfrmOutPolError", want: 1454, got: xfrmStats.XfrmOutPolError},
|
||||
{name: "XfrmFwdHdrError", want: 6654, got: xfrmStats.XfrmFwdHdrError},
|
||||
{name: "XfrmOutStateInvaliad", want: 28765, got: xfrmStats.XfrmOutStateInvalid},
|
||||
{name: "XfrmAcquireError", want: 24532, got: xfrmStats.XfrmAcquireError},
|
||||
{name: "XfrmInStateInvalid", want: 55555, got: xfrmStats.XfrmInStateInvalid},
|
||||
{name: "XfrmOutError", want: 1000000, got: xfrmStats.XfrmOutError},
|
||||
} {
|
||||
if test.want != test.got {
|
||||
t.Errorf("Want %s %d, have %d", test.name, test.want, test.got)
|
||||
}
|
||||
}
|
||||
}
|
||||
442
vendor/github.com/prometheus/procfs/xfs/parse_test.go
generated
vendored
442
vendor/github.com/prometheus/procfs/xfs/parse_test.go
generated
vendored
|
|
@ -1,442 +0,0 @@
|
|||
// Copyright 2017 The Prometheus Authors
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package xfs_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/prometheus/procfs"
|
||||
"github.com/prometheus/procfs/xfs"
|
||||
)
|
||||
|
||||
func TestParseStats(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
s string
|
||||
fs bool
|
||||
stats *xfs.Stats
|
||||
invalid bool
|
||||
}{
|
||||
{
|
||||
name: "empty file OK",
|
||||
},
|
||||
{
|
||||
name: "short or empty lines and unknown labels ignored",
|
||||
s: "one\n\ntwo 1 2 3\n",
|
||||
stats: &xfs.Stats{},
|
||||
},
|
||||
{
|
||||
name: "bad uint32",
|
||||
s: "extent_alloc XXX",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "bad uint64",
|
||||
s: "xpc XXX",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "extent_alloc bad",
|
||||
s: "extent_alloc 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "extent_alloc OK",
|
||||
s: "extent_alloc 1 2 3 4",
|
||||
stats: &xfs.Stats{
|
||||
ExtentAllocation: xfs.ExtentAllocationStats{
|
||||
ExtentsAllocated: 1,
|
||||
BlocksAllocated: 2,
|
||||
ExtentsFreed: 3,
|
||||
BlocksFreed: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "abt bad",
|
||||
s: "abt 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "abt OK",
|
||||
s: "abt 1 2 3 4",
|
||||
stats: &xfs.Stats{
|
||||
AllocationBTree: xfs.BTreeStats{
|
||||
Lookups: 1,
|
||||
Compares: 2,
|
||||
RecordsInserted: 3,
|
||||
RecordsDeleted: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "blk_map bad",
|
||||
s: "blk_map 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "blk_map OK",
|
||||
s: "blk_map 1 2 3 4 5 6 7",
|
||||
stats: &xfs.Stats{
|
||||
BlockMapping: xfs.BlockMappingStats{
|
||||
Reads: 1,
|
||||
Writes: 2,
|
||||
Unmaps: 3,
|
||||
ExtentListInsertions: 4,
|
||||
ExtentListDeletions: 5,
|
||||
ExtentListLookups: 6,
|
||||
ExtentListCompares: 7,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "bmbt bad",
|
||||
s: "bmbt 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "bmbt OK",
|
||||
s: "bmbt 1 2 3 4",
|
||||
stats: &xfs.Stats{
|
||||
BlockMapBTree: xfs.BTreeStats{
|
||||
Lookups: 1,
|
||||
Compares: 2,
|
||||
RecordsInserted: 3,
|
||||
RecordsDeleted: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "dir bad",
|
||||
s: "dir 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "dir OK",
|
||||
s: "dir 1 2 3 4",
|
||||
stats: &xfs.Stats{
|
||||
DirectoryOperation: xfs.DirectoryOperationStats{
|
||||
Lookups: 1,
|
||||
Creates: 2,
|
||||
Removes: 3,
|
||||
Getdents: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "trans bad",
|
||||
s: "trans 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "trans OK",
|
||||
s: "trans 1 2 3",
|
||||
stats: &xfs.Stats{
|
||||
Transaction: xfs.TransactionStats{
|
||||
Sync: 1,
|
||||
Async: 2,
|
||||
Empty: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "ig bad",
|
||||
s: "ig 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "ig OK",
|
||||
s: "ig 1 2 3 4 5 6 7",
|
||||
stats: &xfs.Stats{
|
||||
InodeOperation: xfs.InodeOperationStats{
|
||||
Attempts: 1,
|
||||
Found: 2,
|
||||
Recycle: 3,
|
||||
Missed: 4,
|
||||
Duplicate: 5,
|
||||
Reclaims: 6,
|
||||
AttributeChange: 7,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "log bad",
|
||||
s: "log 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "log OK",
|
||||
s: "log 1 2 3 4 5",
|
||||
stats: &xfs.Stats{
|
||||
LogOperation: xfs.LogOperationStats{
|
||||
Writes: 1,
|
||||
Blocks: 2,
|
||||
NoInternalBuffers: 3,
|
||||
Force: 4,
|
||||
ForceSleep: 5,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "rw bad",
|
||||
s: "rw 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "rw OK",
|
||||
s: "rw 1 2",
|
||||
stats: &xfs.Stats{
|
||||
ReadWrite: xfs.ReadWriteStats{
|
||||
Read: 1,
|
||||
Write: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "attr bad",
|
||||
s: "attr 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "attr OK",
|
||||
s: "attr 1 2 3 4",
|
||||
stats: &xfs.Stats{
|
||||
AttributeOperation: xfs.AttributeOperationStats{
|
||||
Get: 1,
|
||||
Set: 2,
|
||||
Remove: 3,
|
||||
List: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "icluster bad",
|
||||
s: "icluster 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "icluster OK",
|
||||
s: "icluster 1 2 3",
|
||||
stats: &xfs.Stats{
|
||||
InodeClustering: xfs.InodeClusteringStats{
|
||||
Iflush: 1,
|
||||
Flush: 2,
|
||||
FlushInode: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "vnodes bad",
|
||||
s: "vnodes 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "vnodes (missing free) OK",
|
||||
s: "vnodes 1 2 3 4 5 6 7",
|
||||
stats: &xfs.Stats{
|
||||
Vnode: xfs.VnodeStats{
|
||||
Active: 1,
|
||||
Allocate: 2,
|
||||
Get: 3,
|
||||
Hold: 4,
|
||||
Release: 5,
|
||||
Reclaim: 6,
|
||||
Remove: 7,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "vnodes (with free) OK",
|
||||
s: "vnodes 1 2 3 4 5 6 7 8",
|
||||
stats: &xfs.Stats{
|
||||
Vnode: xfs.VnodeStats{
|
||||
Active: 1,
|
||||
Allocate: 2,
|
||||
Get: 3,
|
||||
Hold: 4,
|
||||
Release: 5,
|
||||
Reclaim: 6,
|
||||
Remove: 7,
|
||||
Free: 8,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "buf bad",
|
||||
s: "buf 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "buf OK",
|
||||
s: "buf 1 2 3 4 5 6 7 8 9",
|
||||
stats: &xfs.Stats{
|
||||
Buffer: xfs.BufferStats{
|
||||
Get: 1,
|
||||
Create: 2,
|
||||
GetLocked: 3,
|
||||
GetLockedWaited: 4,
|
||||
BusyLocked: 5,
|
||||
MissLocked: 6,
|
||||
PageRetries: 7,
|
||||
PageFound: 8,
|
||||
GetRead: 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "xpc bad",
|
||||
s: "xpc 1",
|
||||
invalid: true,
|
||||
},
|
||||
{
|
||||
name: "xpc OK",
|
||||
s: "xpc 1 2 3",
|
||||
stats: &xfs.Stats{
|
||||
ExtendedPrecision: xfs.ExtendedPrecisionStats{
|
||||
FlushBytes: 1,
|
||||
WriteBytes: 2,
|
||||
ReadBytes: 3,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "fixtures OK",
|
||||
fs: true,
|
||||
stats: &xfs.Stats{
|
||||
ExtentAllocation: xfs.ExtentAllocationStats{
|
||||
ExtentsAllocated: 92447,
|
||||
BlocksAllocated: 97589,
|
||||
ExtentsFreed: 92448,
|
||||
BlocksFreed: 93751,
|
||||
},
|
||||
AllocationBTree: xfs.BTreeStats{
|
||||
Lookups: 0,
|
||||
Compares: 0,
|
||||
RecordsInserted: 0,
|
||||
RecordsDeleted: 0,
|
||||
},
|
||||
BlockMapping: xfs.BlockMappingStats{
|
||||
Reads: 1767055,
|
||||
Writes: 188820,
|
||||
Unmaps: 184891,
|
||||
ExtentListInsertions: 92447,
|
||||
ExtentListDeletions: 92448,
|
||||
ExtentListLookups: 2140766,
|
||||
ExtentListCompares: 0,
|
||||
},
|
||||
BlockMapBTree: xfs.BTreeStats{
|
||||
Lookups: 0,
|
||||
Compares: 0,
|
||||
RecordsInserted: 0,
|
||||
RecordsDeleted: 0,
|
||||
},
|
||||
DirectoryOperation: xfs.DirectoryOperationStats{
|
||||
Lookups: 185039,
|
||||
Creates: 92447,
|
||||
Removes: 92444,
|
||||
Getdents: 136422,
|
||||
},
|
||||
Transaction: xfs.TransactionStats{
|
||||
Sync: 706,
|
||||
Async: 944304,
|
||||
Empty: 0,
|
||||
},
|
||||
InodeOperation: xfs.InodeOperationStats{
|
||||
Attempts: 185045,
|
||||
Found: 58807,
|
||||
Recycle: 0,
|
||||
Missed: 126238,
|
||||
Duplicate: 0,
|
||||
Reclaims: 33637,
|
||||
AttributeChange: 22,
|
||||
},
|
||||
LogOperation: xfs.LogOperationStats{
|
||||
Writes: 2883,
|
||||
Blocks: 113448,
|
||||
NoInternalBuffers: 9,
|
||||
Force: 17360,
|
||||
ForceSleep: 739,
|
||||
},
|
||||
ReadWrite: xfs.ReadWriteStats{
|
||||
Read: 107739,
|
||||
Write: 94045,
|
||||
},
|
||||
AttributeOperation: xfs.AttributeOperationStats{
|
||||
Get: 4,
|
||||
Set: 0,
|
||||
Remove: 0,
|
||||
List: 0,
|
||||
},
|
||||
InodeClustering: xfs.InodeClusteringStats{
|
||||
Iflush: 8677,
|
||||
Flush: 7849,
|
||||
FlushInode: 135802,
|
||||
},
|
||||
Vnode: xfs.VnodeStats{
|
||||
Active: 92601,
|
||||
Allocate: 0,
|
||||
Get: 0,
|
||||
Hold: 0,
|
||||
Release: 92444,
|
||||
Reclaim: 92444,
|
||||
Remove: 92444,
|
||||
Free: 0,
|
||||
},
|
||||
Buffer: xfs.BufferStats{
|
||||
Get: 2666287,
|
||||
Create: 7122,
|
||||
GetLocked: 2659202,
|
||||
GetLockedWaited: 3599,
|
||||
BusyLocked: 2,
|
||||
MissLocked: 7085,
|
||||
PageRetries: 0,
|
||||
PageFound: 10297,
|
||||
GetRead: 7085,
|
||||
},
|
||||
ExtendedPrecision: xfs.ExtendedPrecisionStats{
|
||||
FlushBytes: 399724544,
|
||||
WriteBytes: 92823103,
|
||||
ReadBytes: 86219234,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
var (
|
||||
stats *xfs.Stats
|
||||
err error
|
||||
)
|
||||
|
||||
if tt.s != "" {
|
||||
stats, err = xfs.ParseStats(strings.NewReader(tt.s))
|
||||
}
|
||||
if tt.fs {
|
||||
stats, err = procfs.FS("../fixtures").XFSStats()
|
||||
}
|
||||
|
||||
if tt.invalid && err == nil {
|
||||
t.Error("expected an error, but none occurred")
|
||||
}
|
||||
if !tt.invalid && err != nil {
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if want, have := tt.stats, stats; !reflect.DeepEqual(want, have) {
|
||||
t.Errorf("unexpected XFS stats:\nwant:\n%v\nhave:\n%v", want, have)
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue