simple online nosql database database with REST API and MongoDB queries
  • Features
  • Docs
  • Blog
  • Templates
  • Pricing
  • Contact
  • Sign Up
  • Log In

Blog

 The latest news and articles about restdb.io  

Database templates!
Don't forget to visit our template catalog! It's the fastest way to get up and running with a restdb.io database. View templates »

DevOps nirvana: Roll your own low-cost realtime server monitoring with Bash, Javascript and NoSQL

by Jon Erik Solheim
|
Howto|Tutorials|API|
  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

There are plenty of excellent tools to monitor servers in real-time (New Relic, LogicMonitor). These products have tons of features and often costs more than you are (eagerly) willing to pay. Maybe you just need something simple or something custom that you want to keep an eye on in a dashboard. Perhaps the Dev in you is bigger than the Ops? In any of those cases, this article is for you.

We will show how you can use a pre-made restdb.io database template to create your own DevOps server monitoring dashboard with JavaScript, Google Charts and Bash shell scripts. The setup is simple and will only take you a few minutes to try out.

All you have to do is to instantiate a new database from our template and add a simple script to each server you want to monitor. The scripts will report the current server load to your database, and you will get a nice dashboard with graphs showing each servers load profile, in real time. The template is easy to extend and adapt.

 

The illustration below shows how 3 servers reports its load average to your restdb.io cloud database (using the REST API):

illustration

When you have finished this setup guide you will see a dashboard with one chart for each of your servers.

Example dashboard for an 8 server set up showing load averages for the last 3 hours:

Set it up

To set up a database for monitoring your servers, follow these steps:

  1. Clone this database image
  2. Set up the API keys
  3. Install server scripts
  4. Configure crontab

1. Clone the database image

Use this key to create a new database from our template snapshot:

b130a31a03af6c4aaed2ee838d57a042

For example, you can call your database myloaddb:

This creates a new database from our template complete with web pages and scripts for monitoring.

When your database has been created, navigate to it by clicking on its icon and start the rest of the set up below.

2. Set up API keys

Use the full access key or a create a new web enabled CORS key for API access from the scripts. Edit the JavaScript script.js Page (activate developer mode in the top right corner).


Then insert the CORS api-key on the following code line:

var apikey = "<insert your api-key>";

That's all the work you have to do in restdb.io. If you click on the left menu item called loadmeter, you will see a sample Page with an image. This is where our live charts will be shown.

For that magic to happen, the next steps needs to be completed. 

The first step is to install a bash script on each server you want to monitor.

3. Install server scripts

First create a script on each server.

cd /somedir
touch loadscript.sh
chmod +x loadscript.sh

Server load stats

We'll be using the /proc/loadavg filesystem output and parse the string for the load values. Make sure that you can run the cat /proc/loadavg command on your server, and that the output is similar to the example below:

user:~# cat /proc/loadavg
0.40 0.23 0.16 3/94 16179

On most *nix variants the following command works for getting the load averages:

cat /proc/loadavg | awk '{print $1}'

This script is tested on Linux Ubuntu servers.

You may have to tweak it for small variations on your system, or even replace it with any other method, e.g. uptime, vmstat etc.

Then open the script in your favorite editor, e.g.

user:~# nano /somedir/loadscript.sh

Add the following code into the script:

#!/bin/bash
server=`hostname`
apikey=<your api-key>
load0=`cat /proc/loadavg | awk '{print $1}'`
load1=`cat /proc/loadavg | awk '{print $2}'`
load2=`cat /proc/loadavg | awk '{print $3}'`
json="{\"host\": \"$server\", \"load0\": $load0, \"load1\": $load1, \"load2\": $load2}"
curl -k -H "Content-Type: application/json" -H "x-apikey: $apikey" -X POST -d "$json" 'https://<your db name>.restdb.io/rest/serverload' 

Replace <your api-key> with your api-key.
Replace <your db name> with your actual database name, e.g. myloaddb-f20b.

4. Configure crontab

Then edit the crontab file (as root user):

user:~# crontab -e

Add this line to send load to your database once each minute, or any other crontab value you prefer:

* * * * * bash /somedir/loadscript.sh >/tmp/stdout.log 2>/tmp/stderr.log

Replace /somedir with the path to where you saved your script.

Conclusion

We've now shown you how you can quickly roll your own monitoring solution using a restdb.io database, some Javascript code and Bash scripts. It's quick and easy to set up and most importantly, it is very easy to adapt and extend to your particular use case. Perhaps you want to add more parameters to monitor from you servers? 

Now it's time to set it up and dig into the code and make it your own. If you create something absolutely magical,  perhaps you can create a new improved snapshot that we can share with other DevOpses?

You can read more about how to create restdb.io databases in our documentation section. There is also some gems hidden in our blog. And last but not least, sign up for a free restdb.io account and get going.

  • Share on Facebook
  • Tweet
  • Add to Pocket
  • Share on LinkedIn
  • Send email

All Posts


Search

Topics

  • API
  • Authentication
  • Case study
  • Features
  • Howto
  • Integrations
  • Newsletter
  • Productivity
  • Prototyping
  • Tutorials
  • User

restdb.io is a fast and simple NoSQL cloud database service. With restdb.io you get schema, relations, REST API and an efficient multi-user admin UI for working with data.

Our customers use it for backends, business databases, API-first CMS, data collection and much more. It is easy to get started with the free development plan.

Start Building »

  • Site Links
  • Home Page
  • About Us
  • Contact
  • Blog
  • Templates Catalog
  • Cloud Service
  • Features
  • Pricing
  • Terms & Conditions
  • Privacy Policy
  • Sign Up »
  • Documentation
  • Overview
  • Getting Started
  • Coding against the API
  • Utils
  • Security and Admin
© 2025 restdb.io