← Back to Docs

Get started with application monitoring

Monibot collects, aggregates and monitors your application metrics, and notifies you if metrics go out of bounds:

  • Number of served HTTP requests
  • Number of registered users
  • Database size
  • Number of running processes
  • Anything that can be expressed in numbers

Create a metric in Monibot

  • Log into your Monibot account. If you don't have one, register now, it's free.
  • In the main menu, click on the 'Metrics' link. Here you'll see a 'New Metric' button.
  • Click the 'New Metric' button. Enter a name, for example 'Users' or 'Requests'. You can chose any name here, it's used only for display.
  • Select a metric type:
    • 'Counter': Counters go up only, e.g. number of served requests or number of failed database queries.
    • 'Gauge': Gauges can go up and down, e.g. number of registered users or worker pool queue sizes.
    • 'Histogram': Histograms are value distributions, e.g. request latencies or database transaction latencies.
  • Click 'Save'. Your metric is now ready and waits for data from your server or application. Please note that we've allocated a unique id for your metric. You will need that id in the next steps.

Send metric values from your server or application

After you have successfully created a metric, you are now ready to send metric values from your server or application to Monibot. For that, you have a number of options:

  • With our moni command line tool.
  • With curl.
  • With our Go SDK.
  • With any HTTP library of your choice.

Send metric values with our moni command line tool

You can use our moni command line tool to send metric values from the command line or from a shell script.

#!/bin/sh
export MONIBOT_API_KEY=0000000000000000
export METRIC_ID=1111111111111111
export NUM_PROCS=$(ps -e | wc -l)
/path/to/moni set $METRIC_ID $NUM_PROCS

The above script does the following:

  • It stores your API key in the environment variable MONIBOT_API_KEY. You can find your API key on your Monibot account profile. While you can set the API key directly in the moni invocation, it's a good practice to set it as an environment variable. The moni tool will pick it up from there.
  • It stores the id of your metric in the environment variable METRIC_ID. This is the id of the metric you created above.
  • Then it counts the number of processes (ps -e lists all processes, wc -l counts the lines) and stores them in the environment variable NUM_PROCS.
  • The last line sends the metric value to Monibot.

Send metric values with curl

You can use curl to send metric values from the command line or from a shell script.

#!/bin/sh
export MONIBOT_API_KEY=0000000000000000
export METRIC_ID=1111111111111111
export NUM_PROCS=$(ps -e | wc -l)
curl -X POST https://monibot.io/api/metric/$METRIC_ID/set \
    -H "Authorization: Bearer $MONIBOT_API_KEY" \
    -d "value=$NUM_PROCS"

The above script does the following:

  • It stores your API key in the environment variable MONIBOT_API_KEY. You can find your API key on your Monibot account profile. While you can set the API key directly in the moni invocation, it's a good practice to set it as an environment variable. The moni tool will pick it up from there.
  • It stores the id of your metric in the environment variable METRIC_ID. This is the id of the metric you created above.
  • Then it counts the number of processes (ps -e lists all processes, wc -l counts the lines) and stores them in the environment variable NUM_PROCS.
  • The last line sends the metric value to Monibot.

Send metric values with our Go (golang) SDK

You can use our Go SDK to send heartbeats programmatically.

package main

func main() {
    // replace with your API key and metric id
    const apiKey = "00000000000000000000000000000000"
    const metricId = "11111111111111111111111111111111"

    // initialize monibot api
    api := monibot.NewApi(apiKey)

    // load current user count from DB
    userCount := loadUserCountFromDatabase()

    // send user count to Monibot
    api.PostMetricSet(metricId, userCount)
}

Send metric values with any HTTP library

You don't have to use Go for using Monibot. In fact, any HTTP library in any programming language can be used. Here's a python sample:

import requests

# change this to your API key and metric id
apiKey = '00000000000000000000000000000000'
metricId = '11111111111111111111111111111111'

# load current user count from DB
userCount = loadUserCountFromDatabase()

# send POST request
res = requests.post(
    url = 'https://monibot.io/api/metric/' + metricId + '/set',
    headers={
        'Content-Type': 'application/x-www-form-urlencoded',
        'Authorization': 'Bearer ' + apiKey
    },
    data='value=' + str(userCount)
)

# print response
print (res)

# Output: <Response [200]>

Advanced options

In the above sections we have shown how to create a metric and send values for it. But there is more: You can set limits on metrics and have Monibot notify you if metric values stop coming in.


Metric limits

Let's say you have create a counter metric 'HTTP requests' for your web app. On each HTTP request, this metric is incremented by one. You expect 100 to 1 million requests per hour. If the number of requests per hour falls below 100, you know something is wrong. If the number of requests per hour increases beyond 1 million, you want to be notified also, there might be a DDOS attack.

With Monibot, you an configure lower and upper bounds for each metric. If the metric values are below the lower bound or above the upper bound, Monibot will notify you.


Value timeout

Metric values are typically sent regularly, either by cron jobs, systemd timers, windows scheduler, application background threads, and so on. In Monibot, you can configure metric value timeouts, so that if metric values stop coming in, Monibot will notify you. This helps to detect failed cron jobs, timers and background threads.





If you have a question that is not covered by our docs, please feel free to contact us, we are happy to help.









Made and hosted in Germany
© 2024 monibot.io