Skip to content

Commit

Permalink
Merge pull request #626 from mackerelio/fix-check-disk
Browse files Browse the repository at this point in the history
Ignores fuse.portal partitions
  • Loading branch information
lufia committed Jul 21, 2022
2 parents f5823f7 + e809f29 commit 4c078c3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 1 addition & 3 deletions check-disk/README.md
Expand Up @@ -13,9 +13,7 @@ check-disk --warning=10 --critical=5 --path=/
First, build this program.

```
go get github.com/mackerelio/go-check-plugins
cd $(go env GOPATH)/src/github.com/mackerelio/go-check-plugins/check-disk
go install
go install github.com/mackerelio/go-check-plugins/check-disk@latest
```

Or you can use this program by installing the official Mackerel package. See [Using the official check plugin pack for check monitoring - Mackerel Docs](https://mackerel.io/docs/entry/howto/mackerel-check-plugins).
Expand Down
13 changes: 7 additions & 6 deletions check-disk/lib/check-disk.go
Expand Up @@ -159,7 +159,7 @@ func run(args []string) *checkers.Checker {
for _, partition := range partitions {
disk, err := gpud.Usage(partition.Mountpoint)
if err != nil {
return checkers.Unknown(fmt.Sprintf("Failed to fetch disk usage: %s", err))
return checkers.Unknown(fmt.Sprintf("%s[type=%s]: Failed to fetch disk usage: %s", partition.Mountpoint, partition.Fstype, err))
}

if disk.Total != 0 {
Expand Down Expand Up @@ -188,7 +188,7 @@ func run(args []string) *checkers.Checker {
for _, disk := range disks {
checkSt, err = checkInodes(checkSt, *opts.InodeCritical, disk, checkers.CRITICAL)
if err != nil {
return checkers.Unknown(fmt.Sprintf("Failed to check disk status: %s", err))
return checkers.Unknown(fmt.Sprintf("%s: Failed to check disk status: %s", disk.Path, err))
}

if checkSt == checkers.CRITICAL {
Expand All @@ -201,7 +201,7 @@ func run(args []string) *checkers.Checker {
for _, disk := range disks {
checkSt, err = checkDisk(checkSt, *opts.Critical, u.Size, disk, checkers.CRITICAL)
if err != nil {
return checkers.Unknown(fmt.Sprintf("Failed to check disk status: %s", err))
return checkers.Unknown(fmt.Sprintf("%s: Failed to check disk status: %s", disk.Path, err))
}

if checkSt == checkers.CRITICAL {
Expand All @@ -214,7 +214,7 @@ func run(args []string) *checkers.Checker {
for _, disk := range disks {
checkSt, err = checkInodes(checkSt, *opts.InodeWarning, disk, checkers.WARNING)
if err != nil {
return checkers.Unknown(fmt.Sprintf("Failed to check disk status: %s", err))
return checkers.Unknown(fmt.Sprintf("%s: Failed to check disk status: %s", disk.Path, err))
}

if checkSt == checkers.WARNING {
Expand All @@ -227,7 +227,7 @@ func run(args []string) *checkers.Checker {
for _, disk := range disks {
checkSt, err = checkDisk(checkSt, *opts.Warning, u.Size, disk, checkers.WARNING)
if err != nil {
return checkers.Unknown(fmt.Sprintf("Failed to check disk status: %s", err))
return checkers.Unknown(fmt.Sprintf("%s: Failed to check disk status: %s", disk.Path, err))
}

if checkSt == checkers.WARNING {
Expand All @@ -250,7 +250,7 @@ func run(args []string) *checkers.Checker {
}

// ref: mountlist.c in gnulib
// https://github.com/coreutils/gnulib/blob/a742bdb3/lib/mountlist.c#L168
// https://github.com/coreutils/gnulib/blob/df336dc/lib/mountlist.c#L164
func listPartitions() ([]gpud.PartitionStat, error) {
allPartitions, err := gpud.Partitions(true)
if err != nil {
Expand All @@ -265,6 +265,7 @@ func listPartitions() ([]gpud.PartitionStat, error) {
"debugfs",
"devpts",
"fusectl",
"fuse.portal",
"mqueue",
"rpc_pipefs",
"sysfs",
Expand Down
5 changes: 4 additions & 1 deletion check-disk/test.sh
Expand Up @@ -10,4 +10,7 @@ then
exit 2
fi

exec $plugin
# GitHub-hosted Linux runner mounts tracefs on /sys/kernel/debug/tracing.
# That fstype don't appear in ME_DUMMY macro on coreutils.
# Thus, for now, we ignore it only in test.sh.
exec $plugin -X tracefs

0 comments on commit 4c078c3

Please sign in to comment.