diff options
Diffstat (limited to 'collector')
-rw-r--r-- | collector/drbd_linux.go | 2 | ||||
-rw-r--r-- | collector/filesystem_freebsd.go | 6 | ||||
-rw-r--r-- | collector/filesystem_linux_test.go | 2 | ||||
-rw-r--r-- | collector/fixtures/sys.ttar | 11 | ||||
-rw-r--r-- | collector/helper.go | 14 | ||||
-rw-r--r-- | collector/helper_test.go | 63 | ||||
-rw-r--r-- | collector/kvm_bsd.go | 2 | ||||
-rw-r--r-- | collector/mountstats_linux.go | 2 | ||||
-rw-r--r-- | collector/nfs_linux.go | 2 | ||||
-rw-r--r-- | collector/nfsd_linux.go | 2 | ||||
-rw-r--r-- | collector/perf_linux.go | 2 | ||||
-rw-r--r-- | collector/powersupplyclass.go | 7 | ||||
-rw-r--r-- | collector/schedstat_linux.go | 2 | ||||
-rw-r--r-- | collector/sysctl_bsd.go | 2 | ||||
-rw-r--r-- | collector/wifi_linux.go | 2 | ||||
-rw-r--r-- | collector/xfs_linux.go | 2 | ||||
-rw-r--r-- | collector/zfs_freebsd.go | 2 | ||||
-rw-r--r-- | collector/zfs_linux.go | 2 | ||||
-rw-r--r-- | collector/zfs_solaris.go | 1 |
19 files changed, 120 insertions, 8 deletions
diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index 6815c5f..4beb31d 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nodrbd | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index f37029e..1d377b1 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go | |||
@@ -40,14 +40,14 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { | |||
40 | } | 40 | } |
41 | stats := []filesystemStats{} | 41 | stats := []filesystemStats{} |
42 | for _, fs := range buf { | 42 | for _, fs := range buf { |
43 | mountpoint := string(fs.Mntonname[:]) | 43 | mountpoint := bytesToString(fs.Mntonname[:]) |
44 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { | 44 | if c.ignoredMountPointsPattern.MatchString(mountpoint) { |
45 | level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) | 45 | level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) |
46 | continue | 46 | continue |
47 | } | 47 | } |
48 | 48 | ||
49 | device := string(fs.Mntfromname[:]) | 49 | device := bytesToString(fs.Mntfromname[:]) |
50 | fstype := string(fs.Fstypename[:]) | 50 | fstype := bytesToString(fs.Fstypename[:]) |
51 | if c.ignoredFSTypesPattern.MatchString(fstype) { | 51 | if c.ignoredFSTypesPattern.MatchString(fstype) { |
52 | level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) | 52 | level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) |
53 | continue | 53 | continue |
diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index 973cd14..e401779 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go | |||
@@ -11,8 +11,6 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nofilesystem | ||
15 | |||
16 | package collector | 14 | package collector |
17 | 15 | ||
18 | import ( | 16 | import ( |
diff --git a/collector/fixtures/sys.ttar b/collector/fixtures/sys.ttar index a4550a5..3e52c60 100644 --- a/collector/fixtures/sys.ttar +++ b/collector/fixtures/sys.ttar | |||
@@ -1756,6 +1756,17 @@ Lines: 1 | |||
1756 | 0 | 1756 | 0 |
1757 | Mode: 644 | 1757 | Mode: 644 |
1758 | # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 1758 | # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
1759 | Path: sys/devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/bcache/writeback_rate_debug | ||
1760 | Lines: 7 | ||
1761 | rate: 1.1M/sec | ||
1762 | dirty: 20.4G | ||
1763 | target: 20.4G | ||
1764 | proportional: 427.5k | ||
1765 | integral: 790.0k | ||
1766 | change: 321.5k/sec | ||
1767 | next io: 17ms | ||
1768 | Mode: 644 | ||
1769 | # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
1759 | Directory: sys/devices/pci0000:00/0000:00:0d.0/ata5 | 1770 | Directory: sys/devices/pci0000:00/0000:00:0d.0/ata5 |
1760 | Mode: 755 | 1771 | Mode: 755 |
1761 | # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 1772 | # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
diff --git a/collector/helper.go b/collector/helper.go index 2bf461e..df5cd26 100644 --- a/collector/helper.go +++ b/collector/helper.go | |||
@@ -14,6 +14,7 @@ | |||
14 | package collector | 14 | package collector |
15 | 15 | ||
16 | import ( | 16 | import ( |
17 | "bytes" | ||
17 | "io/ioutil" | 18 | "io/ioutil" |
18 | "strconv" | 19 | "strconv" |
19 | "strings" | 20 | "strings" |
@@ -30,3 +31,16 @@ func readUintFromFile(path string) (uint64, error) { | |||
30 | } | 31 | } |
31 | return value, nil | 32 | return value, nil |
32 | } | 33 | } |
34 | |||
35 | // Take a []byte{} and return a string based on null termination. | ||
36 | // This is useful for situations where the OS has returned a null terminated | ||
37 | // string to use. | ||
38 | // If this function happens to receive a byteArray that contains no nulls, we | ||
39 | // simply convert the array to a string with no bounding. | ||
40 | func bytesToString(byteArray []byte) string { | ||
41 | n := bytes.IndexByte(byteArray, 0) | ||
42 | if n < 0 { | ||
43 | return string(byteArray) | ||
44 | } | ||
45 | return string(byteArray[:n]) | ||
46 | } | ||
diff --git a/collector/helper_test.go b/collector/helper_test.go new file mode 100644 index 0000000..0424d48 --- /dev/null +++ b/collector/helper_test.go | |||
@@ -0,0 +1,63 @@ | |||
1 | // Copyright 2020 The Prometheus Authors | ||
2 | // Licensed under the Apache License, Version 2.0 (the "License"); | ||
3 | // you may not use this file except in compliance with the License. | ||
4 | // You may obtain a copy of the License at | ||
5 | // | ||
6 | // http://www.apache.org/licenses/LICENSE-2.0 | ||
7 | // | ||
8 | // Unless required by applicable law or agreed to in writing, software | ||
9 | // distributed under the License is distributed on an "AS IS" BASIS, | ||
10 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
11 | // See the License for the specific language governing permissions and | ||
12 | // limitations under the License. | ||
13 | |||
14 | package collector | ||
15 | |||
16 | import ( | ||
17 | "testing" | ||
18 | ) | ||
19 | |||
20 | func TestBytesToString(t *testing.T) { | ||
21 | tests := []struct { | ||
22 | name string | ||
23 | b []byte | ||
24 | expected string | ||
25 | }{ | ||
26 | { | ||
27 | "Single null byte", | ||
28 | []byte{0}, | ||
29 | "", | ||
30 | }, | ||
31 | { | ||
32 | "Empty byte array", | ||
33 | []byte{}, | ||
34 | "", | ||
35 | }, | ||
36 | { | ||
37 | "Not null terminated", | ||
38 | []byte{65, 66, 67}, | ||
39 | "ABC", | ||
40 | }, | ||
41 | { | ||
42 | "Null randomly in array", | ||
43 | []byte{65, 66, 67, 0, 65, 0, 65}, | ||
44 | "ABC", | ||
45 | }, | ||
46 | { | ||
47 | "Array starts with null and contains other valid bytes", | ||
48 | []byte{0, 65, 66, 67, 0}, | ||
49 | "", | ||
50 | }, | ||
51 | } | ||
52 | |||
53 | for _, tt := range tests { | ||
54 | name := tt.name | ||
55 | b := tt.b | ||
56 | result := bytesToString(b) | ||
57 | expected := tt.expected | ||
58 | |||
59 | if result != expected { | ||
60 | t.Errorf("bytesToString(%#v): Name: %s, expected %#v, got %#v)", b, name, expected, result) | ||
61 | } | ||
62 | } | ||
63 | } | ||
diff --git a/collector/kvm_bsd.go b/collector/kvm_bsd.go index b4e95e6..8798736 100644 --- a/collector/kvm_bsd.go +++ b/collector/kvm_bsd.go | |||
@@ -11,7 +11,7 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nomeminfo | 14 | // +build !nokvm |
15 | // +build freebsd dragonfly | 15 | // +build freebsd dragonfly |
16 | 16 | ||
17 | package collector | 17 | package collector |
diff --git a/collector/mountstats_linux.go b/collector/mountstats_linux.go index 3fa1597..4102067 100644 --- a/collector/mountstats_linux.go +++ b/collector/mountstats_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nomountstats | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index 55f9e19..a540bb3 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nonfs | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index b6f2f8e..8cb1e05 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nonfsd | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/perf_linux.go b/collector/perf_linux.go index e452754..3a2f739 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !noperf | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 988b0ee..309b08c 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go | |||
@@ -17,7 +17,9 @@ | |||
17 | package collector | 17 | package collector |
18 | 18 | ||
19 | import ( | 19 | import ( |
20 | "errors" | ||
20 | "fmt" | 21 | "fmt" |
22 | "os" | ||
21 | "regexp" | 23 | "regexp" |
22 | 24 | ||
23 | "github.com/go-kit/kit/log" | 25 | "github.com/go-kit/kit/log" |
@@ -54,6 +56,9 @@ func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) { | |||
54 | func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { | 56 | func (c *powerSupplyClassCollector) Update(ch chan<- prometheus.Metric) error { |
55 | powerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern) | 57 | powerSupplyClass, err := getPowerSupplyClassInfo(c.ignoredPattern) |
56 | if err != nil { | 58 | if err != nil { |
59 | if errors.Is(err, os.ErrNotExist) { | ||
60 | return ErrNoData | ||
61 | } | ||
57 | return fmt.Errorf("could not get power_supply class info: %s", err) | 62 | return fmt.Errorf("could not get power_supply class info: %s", err) |
58 | } | 63 | } |
59 | for _, powerSupply := range powerSupplyClass { | 64 | for _, powerSupply := range powerSupplyClass { |
@@ -184,7 +189,7 @@ func getPowerSupplyClassInfo(ignore *regexp.Regexp) (sysfs.PowerSupplyClass, err | |||
184 | powerSupplyClass, err := fs.PowerSupplyClass() | 189 | powerSupplyClass, err := fs.PowerSupplyClass() |
185 | 190 | ||
186 | if err != nil { | 191 | if err != nil { |
187 | return powerSupplyClass, fmt.Errorf("error obtaining power_supply class info: %s", err) | 192 | return powerSupplyClass, fmt.Errorf("error obtaining power_supply class info: %w", err) |
188 | } | 193 | } |
189 | 194 | ||
190 | for device := range powerSupplyClass { | 195 | for device := range powerSupplyClass { |
diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index d2f04f6..9e5b744 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !noshedstat | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/sysctl_bsd.go b/collector/sysctl_bsd.go index 3038f41..a671bc2 100644 --- a/collector/sysctl_bsd.go +++ b/collector/sysctl_bsd.go | |||
@@ -12,7 +12,7 @@ | |||
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build freebsd dragonfly openbsd netbsd darwin | 14 | // +build freebsd dragonfly openbsd netbsd darwin |
15 | // +build !nomeminfo | 15 | // +build cgo |
16 | 16 | ||
17 | package collector | 17 | package collector |
18 | 18 | ||
diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index 118e714..b4b3759 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nowifi | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/xfs_linux.go b/collector/xfs_linux.go index 77824c5..36dfff5 100644 --- a/collector/xfs_linux.go +++ b/collector/xfs_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !noxfs | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index a625bbc..92661e4 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nozfs | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index e2c9749..2449c26 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go | |||
@@ -11,6 +11,8 @@ | |||
11 | // See the License for the specific language governing permissions and | 11 | // See the License for the specific language governing permissions and |
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build !nozfs | ||
15 | |||
14 | package collector | 16 | package collector |
15 | 17 | ||
16 | import ( | 18 | import ( |
diff --git a/collector/zfs_solaris.go b/collector/zfs_solaris.go index bfda64f..1c0460c 100644 --- a/collector/zfs_solaris.go +++ b/collector/zfs_solaris.go | |||
@@ -12,6 +12,7 @@ | |||
12 | // limitations under the License. | 12 | // limitations under the License. |
13 | 13 | ||
14 | // +build solaris | 14 | // +build solaris |
15 | // +build !nozfs | ||
15 | 16 | ||
16 | package collector | 17 | package collector |
17 | 18 | ||