Skip to content

monofox/monit_exporter

 
 

Repository files navigation

monit_exporter

Contributors Forks Stargazers Issues MIT License

Index

About

monit_exporter periodically scrapes the monit status and provides its data via HTTP to Prometheus.

Features

Exported metrics

These metrics are exported by monit_exporter:

name description
monit_service_check Monit service check info with following labels provided:
check_name
Name of monit check
monitored
Specifies, if the service is monitored or not, whereas 0 means no, 1 means yes, 2 means init and 4 means waiting. A combination is possible. E.g. 5 means, that the service is monitored, but currently waiting for e.g. the right time range.
type
Specifies the type of service.

Value of this metric is representing "error". Means: 0 is "service is fine" whereas > 0 means, there is an error.
monit_service_cpu_perc Monit service CPU info with following labels:
check_name
Name of monit check
type
Specifies value type whereas value can be percentage or percentage_total
monit_service_mem_bytes Monit service mem info with following labels:
check_name
Name of monit check
type
Specifies value type whereas value can be kilobyte or kilobyte_total
monit_service_network_link_state Monit service link states
check_name
Name of monit check

Value can be either -1 = Not available, 0 = down and 1 = up
monit_service_network_link_statistics Monit service link statistics
check_name
Name of monit check
direction
Specifies link direction (upload / download)
unit
Spcifies unit of metrics (bytes, errors, packets)
type
Specifies the type with either now or total. Whereas now means "per second"
monit_service_port_response_times Monit service port, unix socket and icmp checks response times
check_name
Name of monit check
hostname
Specifies hostname checked
path
Specifies a unix socket path
port
Specifies port to check
protocol
Specifies protocol used for checking service (e.g. POP, IMAP, REDIS, etc.). Default is a RAW check.
type
Specifies protocol type (e.g. TCP, UDP, UNIX, ICMP)
uri
Gives full URI for the service check including type, host and port or path.
monit_service_read_bytes Monit service Disk Read Bytes
check_name
Name of monit check
type
Specifies type of read / write. Possible values: read_count, read_count_total. Value is given in bytes.
monit_service_uptime Service and server uptime in seconds
check_name
Name of monit check
type
Type of the uptime service check (Possible values: system / server)
monit_service_write_bytes Monit service Disk Writes Bytes
check_name
Name of monit check
type
Specifies type of read / write. Possible values: write_count, write_count_total. Value is given in bytes.
monit_up Monit status availability. 0 = not available and 1 = available
monit_version Monit current version as label - the value is const 1.

Service types

Services type provided correspond to the XML structure of monit:

type id type name
0 filesystem
1 directory
2 file
3 process
4 host
5 system
6 fifo
7 program
8 network

Support

Dependencies

This application is written in Go and has the following dependencies:

Setup

Requirements

This application has the following build requirements:

  • Git
  • Go

Installation

From source

To build the application from source, simply run the following commands:

git clone https://github.com/monofox/monit_exporter.git
cd monit_exporter
go build

Docker Image

The preferred way to use monit_exporter is by running the provided Docker image. It is currently provided on GitHub Container Registry:

The following tags are available:

  • x.y.z pointing to the release with that version
  • latest pointing to the most recent released version
  • master pointing to the latest build from the default branch

Scrape configuration

The exporter will query the monit server every time it is scraped by prometheus. If you want to reduce load on the monit server you need to change the scrape interval accordingly:

scrape_configs:
  - job_name: 'monit'
    scrape_interval: 90s
    static_configs:
      - targets: ['localhost:9338']

Update

To rebuild the application with the latest Go release, execute the following commands:

export GO_VERSION="1.21.3"
cd ~
curl --location https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz --output ~/go${GO_VERSION}.linux-amd64.tar.gz
tar xzvf ~/go${GO_VERSION}.linux-amd64.tar.gz
sudo rm -rf /usr/local/src/go
sudo mv ~/go /usr/local/src
echo 'PATH=$PATH:/usr/local/src/go/bin:$GOPATH/bin' | sudo tee /etc/profile.d/go.sh
source /etc/profile.d/go.sh

git clone https://github.com/monofox/monit_exporter.git
cd ./monit_exporter/
rm -f go\.mod  go\.sum
sed -i 's@go-version: .*@go-version: ${GO_VERSION}@g' .github/workflows/release.yml
go mod init github.com/monofox/monit_exporter
go mod tidy

Usage

The application will load the config.toml file located in the same directory if present. Use the -conf flag to override the default configuration file name and location.

To run the application, simply execute the Go binary.

Parameters

Config parameter Environment equivalent Description Type Default
listen_address MONIT_LISTEN_ADDRESS address and port to bind String 0.0.0.0:9388
metrics_path MONIT_METRICS_PATH relative path to expose metrics String /metrics
ignore_ssl MONIT_IGNORE_SSL whether of not to ignore ssl errors Boolean false
monit_scrape_uri MONIT_MONIT_SCRAPE_URI uri to get monit status String http://localhost:2812/_status?format=xml&level=full
monit_user MONIT_MONIT_USER user for monit basic auth, if needed String none
monit_password MONIT_MONIT_PASSWORD password for monit status, if needed String none

Example config

listen_address = "0.0.0.0:9388"
metrics_path = "/metrics"
ignore_ssl = false
monit_scrape_uri = "https://localhost:2812/_status?format=xml&level=full"
monit_user = "monit"
monit_password = "example-secret"

License

Distributed under the MIT License.

See LICENSE file for more information.

Contact

Project: monit_exporter

Credits

Acknowledgements: