-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,034 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,4 @@ simplemonitor.code-workspace | |
client.log | ||
master.log | ||
coverage.xml | ||
_build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Minimal makefile for Sphinx documentation | ||
# | ||
|
||
# You can set these variables from the command line, and also | ||
# from the environment for the first two. | ||
SPHINXOPTS ?= | ||
SPHINXBUILD ?= sphinx-build | ||
SOURCEDIR = . | ||
BUILDDIR = _build | ||
|
||
# Put it first so that "make" without argument is like "make help". | ||
help: | ||
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) | ||
|
||
.PHONY: help Makefile | ||
|
||
# Catch-all target: route all unknown targets to Sphinx using the new | ||
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). | ||
%: Makefile | ||
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Configuration file for the Sphinx documentation builder. | ||
# | ||
# This file only contains a selection of the most common options. For a full | ||
# list see the documentation: | ||
# https://www.sphinx-doc.org/en/master/usage/configuration.html | ||
|
||
# -- Path setup -------------------------------------------------------------- | ||
|
||
# If extensions (or modules to document with autodoc) are in another directory, | ||
# add these directories to sys.path here. If the directory is relative to the | ||
# documentation root, use os.path.abspath to make it absolute, like shown here. | ||
# | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath('.')) | ||
import sphinx_rtd_theme # noqa: F401 | ||
from sphinx.application import Sphinx | ||
from sphinx.util.docfields import Field | ||
|
||
# -- Project information ----------------------------------------------------- | ||
|
||
project = "SimpleMonitor" | ||
copyright = "2021, James Seward" | ||
author = "James Seward" | ||
|
||
|
||
# -- General configuration --------------------------------------------------- | ||
|
||
# Add any Sphinx extension module names here, as strings. They can be | ||
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom | ||
# ones. | ||
extensions = ["sphinx_rtd_theme"] | ||
|
||
# Add any paths that contain templates here, relative to this directory. | ||
templates_path = ["_templates"] | ||
|
||
# List of patterns, relative to source directory, that match files and | ||
# directories to ignore when looking for source files. | ||
# This pattern also affects html_static_path and html_extra_path. | ||
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"] | ||
|
||
|
||
# -- Options for HTML output ------------------------------------------------- | ||
|
||
# The theme to use for HTML and HTML Help pages. See the documentation for | ||
# a list of builtin themes. | ||
# | ||
html_theme = "sphinx_rtd_theme" | ||
|
||
# Add any paths that contain custom static files (such as style sheets) here, | ||
# relative to this directory. They are copied after the builtin static files, | ||
# so a file named "default.css" will overwrite the builtin "default.css". | ||
html_static_path = ["_static"] | ||
|
||
|
||
# Borrowed from mypy's conf.py | ||
def setup(app: Sphinx) -> None: | ||
app.add_object_type( | ||
"confval", | ||
"confval", | ||
objname="configuration value", | ||
indextemplate="pair: %s; configuration value", | ||
doc_field_types=[ | ||
Field("type", label="Type", has_arg=False, names=("type",)), | ||
Field("default", label="Default", has_arg=False, names=("default",)), | ||
Field("required", label="Required", has_arg=True, names=("required",)), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
Configuration | ||
============= | ||
|
||
The main configuration lives in :file:`monitor.ini`. By default, SimpleMonitor will | ||
look for it in the working directory when launched. To specify a different | ||
file, use the ``-f`` option. | ||
|
||
The format is fairly standard "INI"; section names are lowercase in ``[square | ||
brackets]``, and values inside the sections are defined as ``key=value``. You | ||
can use blank lines to space things out, and comments start with ``#``. | ||
|
||
Section names and option values, but not option names, support environment | ||
variable injection. To include the value of an environment variable, use | ||
``%env:VARIABLE%``, which will inject the value of ``$VARAIBLE`` from the | ||
environment. You can use this to share a common configuration file across | ||
multiple hosts, for example. | ||
|
||
This main configuration file contains the global settings for SimpleMonitor, | ||
plus the logging and alerting configuration. A separate file, by default | ||
:file:`monitors.ini`, contains the monitor configuration. You can specify a | ||
different monitors configuration file using a directive in the main | ||
configuration. | ||
|
||
.. warning:: I know the configuration file names are dumb, sorry. | ||
|
||
.. _config-bytes: | ||
|
||
Configuration value types | ||
------------------------- | ||
|
||
Values which take **bool** accept ``1``, ``yes``, and ``true`` as truthy, and | ||
everything else as falsey. | ||
|
||
Values which take **bytes** accept suffixes of ``K``, ``M``, or ``G`` for | ||
kibibytes, mibibytes or gibibytes, otherwise are just a number of bytes. | ||
|
||
``monitor.ini`` | ||
--------------- | ||
|
||
This file must contain a ``[monitor]`` section, which must contain at least the ``interval`` setting. | ||
|
||
``[monitor]`` section | ||
^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. confval:: interval | ||
|
||
:type: integer | ||
:required: true | ||
|
||
defines how many seconds to wait between running all the monitors. Note that | ||
the time taken to run the monitors is not subtracted from the interval, so | ||
the next iteration will run at interval + time_to_run_monitors seconds. | ||
|
||
.. confval:: monitors | ||
|
||
:type: string | ||
:required: false | ||
:default: ``monitors.ini`` | ||
|
||
the filename to load the monitors themselves from. Relative to the cwd, not | ||
the path of this configuration file. | ||
|
||
.. confval:: pidfile | ||
|
||
:type: string | ||
:required: false | ||
:default: none | ||
|
||
the path to write a pidfile to. | ||
|
||
.. confval:: remote | ||
|
||
:type: bool | ||
:required: false | ||
:default: false | ||
|
||
enables the listener for receiving data from remote instances. Can be | ||
overridden to disabled with ``-N`` command line option. | ||
|
||
.. confval:: remote_port | ||
|
||
:type: integer | ||
:required: if ``remote`` is enabled | ||
|
||
the TCP port to listen on for remote data | ||
|
||
.. confval:: key | ||
|
||
:type: string | ||
:required: if ``remote`` is enabled | ||
|
||
shared secret for validating data from remote instances. | ||
|
||
.. confval:: bind_host | ||
|
||
:type: string | ||
:required: false | ||
:default: ``0.0.0.0`` (all interfaces) | ||
|
||
the local IP address to listen on, if ``remote`` is enabled. | ||
|
||
.. confval:: hup_file | ||
|
||
:type: string | ||
:required: false | ||
:default: none | ||
|
||
a file to watch the modification time on. If the modification time increases, SimpleMonitor reloads its configuration. | ||
|
||
.. tip:: SimpleMonitor will reload if it receives SIGHUP; this option is useful for platforms which don't have that. | ||
|
||
.. confval:: bind_host | ||
|
||
:type: string | ||
:required: false | ||
:default: all interfaces | ||
|
||
the local address to bind to for remote data | ||
|
||
``[reporting]`` section | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. confval:: loggers | ||
|
||
:type: comma-separated list of string | ||
:required: false | ||
:default: none | ||
|
||
the names of the loggers you want to use. Each one must be a ``[section]`` in this configuration file. | ||
|
||
See Loggers for the common options and list of Alerters with their configurations. | ||
|
||
.. confval:: alerters | ||
|
||
:type: comma-separated list of string | ||
:required: false | ||
:default: none | ||
|
||
the names of the alerters you want to use. Each one must be a ``[section]`` in this configuration file. | ||
|
||
See Alerters for the common options and list of Alerters with their configurations. | ||
|
||
``monitors.ini`` | ||
---------------- | ||
|
||
This file only contains monitors. Each monitor is a ``[section]`` in the file, | ||
with the section name giving the monitor its name. The name ``defaults`` is | ||
reserved, and can be used to specify default values for options. Each monitor's | ||
individual configuration overrides the defaults. | ||
|
||
See Monitors for the common options and list of Monitors with their configurations. | ||
|
||
Example configuration | ||
--------------------- | ||
|
||
This is an example pair of configuration files to show what goes where. For more examples, see :ref:`Config examples`. | ||
|
||
:file:`monitor.ini`: | ||
|
||
.. code-block:: ini | ||
[monitor] | ||
interval=60 | ||
[reporting] | ||
loggers=logfile | ||
alerters=email,sms | ||
# write a log file with the state of each monitor, each time | ||
[logfile] | ||
type=logfile | ||
filename=monitor.log | ||
# email me when monitors fail or succeed | ||
[email] | ||
type=email | ||
host=mailserver.example.com | ||
from=monitor@example.com | ||
to=admin@example.com | ||
# send me an SMS after a monitor has failed 10 times in a row | ||
[sms] | ||
type=bulksms | ||
username=some-username | ||
password=some-password | ||
target=+447777123456 | ||
limit=10 | ||
:file:`monitors.ini`: | ||
|
||
.. code-block:: ini | ||
# check the webserver pings | ||
[www-ping] | ||
type=ping | ||
host=www.example.com | ||
# check the webserver answers https; don't bother checking if it's not pinging | ||
[www-http] | ||
type=http | ||
url=https://www.example.com | ||
depend=www-ping | ||
# check the root partition has at least 1GB of free space | ||
[root-diskspace] | ||
type=diskspace | ||
partition=/ | ||
limit=1G | ||
Reloading | ||
--------- | ||
|
||
You can send SimpleMonitor a SIGHUP to make it reload its configuration. On | ||
platforms which don't have that (e.g. Windows), you can specify a file to | ||
watch. If the modification time of the file changes, SimpleMonitor will reload | ||
its configration. | ||
|
||
Reloading will pick up a change to ``interval`` but no other configuration in | ||
the ``[monitor]`` section. Monitors, Alerters and Loggers are reloaded. You can | ||
add and remove them, and change their configurations, but not change their | ||
types. (To change a type, first remove it from the configuration and reload, | ||
then add it back in.) |
Oops, something went wrong.