Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 52b2ecd

Browse files
benkeith-splunkkeitwb
authored andcommitted
filesystems monitor: Strip mountpoint dim properly (#1190)
If there is a hostFSPath configured and the mountpoint is the root of that path, insert a / after the stripping out of the hostFSPath. Also add doc about migrating from collectd/df.
1 parent 68449db commit 52b2ecd

File tree

5 files changed

+116
-1
lines changed

5 files changed

+116
-1
lines changed

docs/monitors/filesystems.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ procPath: /hostfs/proc
2121
monitors:
2222
- type: filesystems
2323
hostFSPath: /hostfs
24+
25+
## Migrating from collectd/df
26+
The `collectd/df` monitor is being deprecated in favor of the `filesystems`
27+
monitor. While the `collectd/df` monitor will still be available in
28+
5.0, it is recommended that you switch to the `filesystems` monitor soon
29+
after upgrading. There are a few incompatibilities to be aware of between
30+
the two monitors:
31+
32+
- `collectd/df` used a dimension called `plugin_instance` to identify the
33+
mount point or device of the filesystem. This dimension is completely
34+
removed in the `filesystems` monitor and replaced by the `mountpoint`
35+
and `device` dimensions. You no longer have to select between the two
36+
(the `reportByDevice` option on `collectd/df`) as both are always
37+
reported.
38+
39+
- The mountpoints in the `plugin_instance` dimension of `collectd/df`
40+
were reported with `-` instead of the more conventional `/` separated
41+
path segments. The `filesystems` monitor always reports mountpoints in
42+
the `mountpoint` dimension and uses the conventional `/` separator.
43+
44+
- The `collectd/df` plugin set a dimension `plugin: df` on all datapoints,
45+
but `filesystems` has no such comparable dimension.
46+
2447
```
2548

2649

pkg/monitors/filesystems/filesystems.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ func (m *Monitor) getCommonDimensions(partition *gopsutil.PartitionStat) map[str
6969
// sanitize hostfs path in mountpoint
7070
if m.hostFSPath != "" {
7171
dims["mountpoint"] = strings.Replace(dims["mountpoint"], m.hostFSPath, "", 1)
72+
if dims["mountpoint"] == "" {
73+
dims["mountpoint"] = "/"
74+
}
7275
}
7376

7477
return dims
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package filesystems
2+
3+
import (
4+
"testing"
5+
6+
gopsutil "github.com/shirou/gopsutil/disk"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestCommonDimensions(t *testing.T) {
11+
cases := []struct {
12+
hostFSPath string
13+
ps *gopsutil.PartitionStat
14+
expectedDims map[string]string
15+
}{
16+
{
17+
hostFSPath: "/hostfs",
18+
ps: &gopsutil.PartitionStat{
19+
Device: "/dev/sdb1",
20+
Mountpoint: "/hostfs/var/lib",
21+
Fstype: "ext4",
22+
},
23+
expectedDims: map[string]string{
24+
"mountpoint": "/var/lib",
25+
"device": "/dev/sdb1",
26+
"fs_type": "ext4",
27+
},
28+
},
29+
{
30+
hostFSPath: "/hostfs",
31+
ps: &gopsutil.PartitionStat{
32+
Device: "/dev/sdb1",
33+
Mountpoint: "/hostfs",
34+
Fstype: "ext4",
35+
},
36+
expectedDims: map[string]string{
37+
"mountpoint": "/",
38+
"device": "/dev/sdb1",
39+
"fs_type": "ext4",
40+
},
41+
},
42+
{
43+
hostFSPath: "",
44+
ps: &gopsutil.PartitionStat{
45+
Device: "/dev/sdb1",
46+
Mountpoint: "/",
47+
Fstype: "ext4",
48+
},
49+
expectedDims: map[string]string{
50+
"mountpoint": "/",
51+
"device": "/dev/sdb1",
52+
"fs_type": "ext4",
53+
},
54+
},
55+
}
56+
57+
for _, tt := range cases {
58+
m := Monitor{
59+
hostFSPath: tt.hostFSPath,
60+
}
61+
62+
dims := m.getCommonDimensions(tt.ps)
63+
64+
assert.Equal(t, tt.expectedDims, dims)
65+
}
66+
}

pkg/monitors/filesystems/metadata.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,29 @@ monitors:
1212
monitors:
1313
- type: filesystems
1414
hostFSPath: /hostfs
15+
16+
## Migrating from collectd/df
17+
The `collectd/df` monitor is being deprecated in favor of the `filesystems`
18+
monitor. While the `collectd/df` monitor will still be available in
19+
5.0, it is recommended that you switch to the `filesystems` monitor soon
20+
after upgrading. There are a few incompatibilities to be aware of between
21+
the two monitors:
22+
23+
- `collectd/df` used a dimension called `plugin_instance` to identify the
24+
mount point or device of the filesystem. This dimension is completely
25+
removed in the `filesystems` monitor and replaced by the `mountpoint`
26+
and `device` dimensions. You no longer have to select between the two
27+
(the `reportByDevice` option on `collectd/df`) as both are always
28+
reported.
29+
30+
- The mountpoints in the `plugin_instance` dimension of `collectd/df`
31+
were reported with `-` instead of the more conventional `/` separated
32+
path segments. The `filesystems` monitor always reports mountpoints in
33+
the `mountpoint` dimension and uses the conventional `/` separator.
34+
35+
- The `collectd/df` plugin set a dimension `plugin: df` on all datapoints,
36+
but `filesystems` has no such comparable dimension.
37+
1538
```
1639
metrics:
1740
df_complex.free:

selfdescribe.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25712,7 +25712,7 @@
2571225712
"sendAll": false,
2571325713
"sendUnknown": false,
2571425714
"dimensions": null,
25715-
"doc": "This monitor reports metrics about free disk space on mounted devices.\n\nOn Linux hosts, this monitor relies on the `/proc` filesystem.\nIf the underlying host's `/proc` file system is mounted somewhere other than\n/proc please specify the path using the top level configuration `procPath`.\n\n```yaml\nprocPath: /hostfs/proc\nmonitors:\n - type: filesystems\n hostFSPath: /hostfs\n```\n",
25715+
"doc": "This monitor reports metrics about free disk space on mounted devices.\n\nOn Linux hosts, this monitor relies on the `/proc` filesystem.\nIf the underlying host's `/proc` file system is mounted somewhere other than\n/proc please specify the path using the top level configuration `procPath`.\n\n```yaml\nprocPath: /hostfs/proc\nmonitors:\n - type: filesystems\n hostFSPath: /hostfs\n\n## Migrating from collectd/df\nThe `collectd/df` monitor is being deprecated in favor of the `filesystems`\nmonitor. While the `collectd/df` monitor will still be available in\n5.0, it is recommended that you switch to the `filesystems` monitor soon\nafter upgrading. There are a few incompatibilities to be aware of between\nthe two monitors:\n\n - `collectd/df` used a dimension called `plugin_instance` to identify the\n mount point or device of the filesystem. This dimension is completely\n removed in the `filesystems` monitor and replaced by the `mountpoint`\n and `device` dimensions. You no longer have to select between the two\n (the `reportByDevice` option on `collectd/df`) as both are always\n reported.\n\n - The mountpoints in the `plugin_instance` dimension of `collectd/df`\n were reported with `-` instead of the more conventional `/` separated\n path segments. The `filesystems` monitor always reports mountpoints in\n the `mountpoint` dimension and uses the conventional `/` separator.\n\n - The `collectd/df` plugin set a dimension `plugin: df` on all datapoints,\n but `filesystems` has no such comparable dimension.\n\n```\n",
2571625716
"groups": {
2571725717
"": {
2571825718
"description": "",

0 commit comments

Comments
 (0)