mon

command module
v0.0.0-...-1806f38 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 11 Imported by: 0

README

mon - A simple local services monitor

mon is a simple command-line tool to monitor services. Services are specified in a simple JSON file, containing service name, a URL to check, and optional HTTP headers to send in any requests (for things like specifying Accepts or Authorization headers).

All services are assumed to be HTTP services, and mon simply checks that the provided URL for a service returns a 200 (OK) response.

mon is MacOS-centric currently, and assumes presence of osascript for delivering desktop notifications.

Installation

mon is a regular Go program with no third-party dependencies. It can be installed into $GOBIN with:

go install github.com/chriswalker/mon

Configuration

Services to monitor are defined in a simple JSON file, by default located at ~/Library/Application Support/mon/services.json under MacOS. This can be overridden with the --services-file or -s flags.

The file is an array of objects, each of which must minimally define a name and url. HTTP headers can be optionally specified in the headers property.

A sample services file might look like:

[
    { "name": "godocs", "url": "http://localhost:6060" },
    { "name": "rss - miniflux", "url": "http://localhost:8050" },
    {
        "name": "gokrazy",
        "url": "http://gokrazy.local/",
        "headers": {
            "Accepts": "application/json",
            "Authorization": "Basic <bas64 encoded username/pwd here>"
        }
    }
]

If a headers map is provided for a service, the specified headers are provided as-is to the request made to the service. Use this for services that might require some kind of authorisation, or where requests must specify what they accept.

Command-line Flags

Flag Description
-s, --services-file Path to the services configuration file (defaults to ~/Library/Application Support/mon/services.json on MacOS)
-j, --json Output status information as JSON (if omitted, defaults to tubular status output)
--notify Display a desktop notification for each service that does not return a success (200 OK) status

Automation

A sample launchd plist file is provided as a starting point for using mon on MacOS.

Documentation

Overview

mon is a simple service monitor.

It pings HTTP services specified in a JSON configuration file. Services returning a 200 (OK) status code are deemed to be up. Non-200 status codes result in an error status.

By default, mon reads its configuration file from:

[config_dir]/mon/services.json

where [config_dir] is whatever os.UserConfigDir() returns. This can be overriden with the -s/-services-file flags.

mon can output status results in tabular format (the default), as JSON or as a MacOS notification for 'failing' services.

Usage:

mon [flags]

The flags are:

-s,-services-file
    Full path including filename to the configuration file
-j,-json
    Output results in JSON format
-notify
    Display a MacOS notification for failing services via osascript

Jump to

Keyboard shortcuts

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