Monika is a monitoring tool that runs probes and sends notifications when a probe fails.
- HTTP probes
- Ping probes
- Alerting system
- Notifications
- Discord
- Go v1.23 or higher
# Clone the repository
git clone https://github.com/dennypradipta/monika-go.git
# Copy the example configuration file
cp monika.example.yml monika.yml
# Run Monika
make run
# Build Monika
make build
# Test Monika
make test
Monika uses a YAML configuration file to define probes and notifications. An example configuration file is provided in the monika.yml
file.
To run Monika with a custom configuration file, run the following command:
./monika -c monika.yml
Probes are defined in the configuration file. Each probe has the following properties:
id
: A unique identifier for the probe.name
: A name for the probe.interval
: The interval in seconds between probes.requests
: An array of requests to be made by the probe.timeout
: The timeout in milliseconds for the request.method
: The HTTP method to use for the request.url
: The URL to make the request to.recoveryThreshold
: The number of times the probe should recover before marking it as an incident. By default, it will use the largest value ofrecoveryThreshold
from all requests.incidentThreshold
: The number of times the probe should fail before marking it as an incident. By default, it will use the largest value ofincidentThreshold
from all requests.alerts
: An array of alerts to be evaluated for the probe. (More details below)query
: The query to evaluate.message
: The message to send if the query evaluates to true.
ping
: Indicates that the probe is a Ping probeuri
: The URI to ping
Alerts allows you to define conditions for triggering alerts based on HTTP probe responses. Each alert has the following properties:
query
: The query to evaluate.message
: The message to send if the query evaluates to true.
Alerts in Monika are defined using expressions that evaluate to boolean values. These expressions are evaluated against the response data of your HTTP probes. If an expression evaluates to true, the alert is triggered.
WARNING: The expression language used in Monika is not the same as the one used in Monika GO.
Variable | Type | Description |
---|---|---|
response.status |
Number | HTTP status code of the response |
response.time |
Number | Response time in milliseconds |
response.body |
String | Response body as a string |
response.headers |
Map | Response headers as key-value pairs |
response.size |
Number | Size of the response in bytes |
# Alert when HTTP status code is not a success (not in the 200-299 range)
response.status < 200 || response.status > 299
# Alert when response time is greater than 2000 milliseconds
response.time > 2000
# Alert when response body contains the word "error"
contains(response.body, "error")
# Alert when a specific header is missing
response.headers["Content-Type"] == nil
# Alert when response size is too large
response.size > 1000000 # Over 1MB
# Combining multiple conditions
response.time > 1000 && (response.status != 200 || contains(response.body, "error"))
The expr language supports a variety of operators and functions:
+
(addition)-
(subtraction)*
(multiplication)/
(division)%
(modulo)
==
(equal)!=
(not equal)<
(less than)>
(greater than)<=
(less than or equal)>=
(greater than or equal)
&&
(logical AND)||
(logical OR)!
(logical NOT)
contains(s, substr)
: Checks if strings
contains substringsubstr
startsWith(s, prefix)
: Checks if strings
starts withprefix
endsWith(s, suffix)
: Checks if strings
ends withsuffix
len(s)
: Returns the length of strings
len(array)
: Returns the length of an arrayall(array, predicate)
: Returns true if all elements in the array satisfy the predicateany(array, predicate)
: Returns true if any element in the array satisfies the predicatefilter(array, predicate)
: Returns a new array with elements that satisfy the predicatemap(array, function)
: Returns a new array with the results of applying the function to each element
Notifications are defined in the configuration file. Each notification has the following properties:
id
: A unique identifier for the notification.type
: The type of notification to send.data
: The data to send with the notification.url
: The webhook URL to send the notification to.
Contributions are welcome! Please open an issue or submit a pull request if you have any suggestions or improvements.
This project is licensed under the MIT License.