diskmon

command module
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2021 License: MIT Imports: 9 Imported by: 0

README

Diskmon

Build and Test Release

Diskmon will notify you via Slack if a disk has reached (>=) a configurable size limit.

Design Rationale

Diskmon was created to monitor volumes on Digital Ocean. Digital ocean does not provide that feature in its droplet metrics (as of 09/2021).

We chose to implement this ourselves in the simplest way we could think of. We did not want to setup Prometheus for this. If you have prometheus already please use the node exporter. It provides mount point monitoring and much more!

Since volumes are mounted under one directory on Digital Ocean (at least in our setup) we chose to just get the disk usage for all its child directories (non-recursive). In contrast, node_exporter will look at disk usage of your mount points and let you for example ignore filesystems or mount points you are not interested in.

We make a system call to statfs to get filesystem statistics. You can try stat -f go.mod locally to see what usage information we get.

Get started

Dowload a pre-built binary or build the binary yourself

go build -o /usr/local/bin/diskmon

Change the destination to a path of your choice and make sure it can be found by your shell via the $PATH variable.

Or run it directly

go run main.go -basedir <directory> -limit 65

which will write usage reports to stdout.

Notifications

Notifications can be sent to

  • stdout (by default)
  • or Slack using a Slack App

For Slack please follow the Slack documentation on how to create a Slack App Bot. You can also follow this YouTube tutorial Golang Tutorial: Build a Slack Bot.

You will then need to pass the Slack Bot User OAuth Token and the channel ID to the binary via CLI flags.

Prefer passing credentials for example like so

diskmon -basedir <directory> -limit 65 \
  -slackToken $SLACK_TOKEN \
  -slackChannel $SLACK_CHANNEL

so that the credentials are not in your shell history.

Limitations

The diskmon is not a general purpose disk monitor. It is specifically designed for the use case we had (see Design Rationale).

If you have prometheus already please use the node exporter. It provides mount point monitoring and much more!

  • Notifications can only be sent to Slack using a Slack App or to stdout. You can of course adapt the code to send notifications anywhere 😄
  • It will not discover all mount points for you like the node exporter. You can only provide one directory in which your mount points should be. For our use case the volumes we wanted to monitor were all in one directory.
  • Does not work on Windows due to the syscall we are making
  • Only checks disk usage for non-privileged users. A privileged user might have more disk space available. This might not work for you as it depends on the user permissions of the user writing to the disk you want to monitor.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package usage provides a disk usage check and notification mechanism.
Package usage provides a disk usage check and notification mechanism.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL