MySQL Monitoring with Telegraf, InfluxDB & Grafana

This post will walk you through each step of creating interactive, real-time & dynamic dashboard to monitor your MySQL instances using Telegraf, InfluxDB & Grafana.

Start by enabling the MySQL input plugin in /etc/telegraf/telegraf.conf :

Once Telegraf is up and running it’ll start collecting data and writing them to the InfluxDB database:

Finally, point your browser to your Grafana URL, then login as the admin user. Choose ‘Data Sources‘ from the menu. Then, click ‘Add new‘ in the top bar.

Fill in the configuration details for the InfluxDB data source:

You can now import the dashboard.json file by opening the dashboard dropdown menu and click ‘Import‘ :

Note: Check my Github for more interactive & beautiful Grafana dashboards.

Exploring Swarm & Container Overview Dashboard in Grafana

In my previous post, your learnt how to monitor your Swarm Cluster with TICK Stack. In this part, I will show you how to use the same Stack but instead of using Chronograf as our visualization and exploration tool we will use Grafana.

Connect to your manager node via SSH, and clone the following Github repository:

Use the docker-compose.yml below to setup the monitoring stack:

Then, issue the following command to deploy the stack:

Once deployed, you should see the list of services running on the cluster:

Point your browser to http://IP:3000, you should be able to reach the Grafana Dashboard:

The default username & password are admin. Go ahead and log in.

Go to “Data Sources” and create 2 InfluxDB data sources:

  • Vms: pointing to your Cluster Nodes metrics database.
  • Docker: pointing to your Docker Services metrics database.

Finally, import the dashboard by hitting the “import” button:

From here, you can upload the dashboard.json, then pick the data sources you created earlier:

You will end up with an interactive and dynamic dashboard:

Monitor Swarm cluster with TICK stack & Slack

In this article, I will show you how to setup an Open Source time series platform to monitor your Docker Swarm cluster & send notification on Slack in case of anomaly detection.

Components of our monitoring Stack:

Plugin driven server agent for collecting and reporting metrics.

Scalable time series database for metrics, events and real-time analytics.

Real time visualization tool for building graphs on top of data.

Framework for processing, monitoring, and alerting on time series data.

Real-time team messaging application.

Note: all the code used in this post is available on my Github.

1 – Swarm Setup

If you already have an existing Swarm cluster, you can skip this part, if not use the following script to setup a Swarm with 3 nodes (1 manager & 2 workers):

Issue the following commands:

The output of the above command is as follows:

2 – Stack Setup

Once created, connect to your manager node via SSH, and clone the following repository:

To start all of these containers I’m using docker-compose:

Issue the following command to deploy the stack:

Wait for nodes to pull the images from DockerHub:

Once pulled you should see the services running:

Open your browser on http://IP:8888 (Chronograf Dashboard) and properly configure the data source:

3 – System usage Dashboard

Click on “create dashboard“, and assign a name to the dashboard:

Before adding graphs, we will use a concept called Dashboard Template Variable, to create dynamic & interactive graphs. Instead of hard-coding things like node name and container name in our metric queries we will use variables in their place. So click on “Templates Varibles” in top of the dashboard created earlier. And, create a variable called :host: as follows:

Note: currently, there’s no solution to set hostname for services created with swarm global mode (Github). Thats why we got list of IDs instead of names

You can now use the dropdown at the top of the dashboard to select the different options for the :host: template variable:

Now it’s time to create our first graph, so click on “Add Graph” button.

3.1 – Memory usage per Node

To create a query, you can either use the Query Builder or, if you’re already familar with InfluxQL, you can manually enter the query in the text input:

Our query calculates the average of the field keys freeused, and total in the measurement mem_vm, and it groups them by the time and node name.

You can change the graph type, X, and Y axes format by clicking on “Options” tab:

One visualization on a dashboard isn’t spectacularly interesting, so I added a couple more graphs to show you more possibilities:

3.2 – CPU usage per Node

3.3 – Disk usage per Node

We end up with a beautiful dashboard like this:

Let’s create another dashboard to monitor Docker Containers running on the Cluster.

4 – Swarm Services Dashboard

Create a second dashboard called “Services“, and create a template variable to store list of services running on cluster:

You can filter now metrics by service name:

4.1 – Memory usage per Service

4.2 – CPU usage per Service

4.3 – Network Transmit/Receive

4.4 – IO Read/Write per Service

Result:

Note: you can take this further, and filter metrics by the node on which the service is running on by creating another template variable:

Let’s see what happen if we create another service on Swarm:

If you go back to Chronograf, you should see the service has been added automatically to the container dropdown list:

And that’s it! You now have the foundation for building beautiful data visualizations and dashboards with Chronograf.

Kapacitor is the last piece of the puzzle. We now know how to store, get and read metrics, and now you need to elaborate on them to do something like alerting or proactive monitoring.

So on the “Configuration” tab, click on “Add config“:

Add new Kapacitor instance as below, and enable Slack:

Note: update the Slack channel & Webhook URL in case you didn’t update the kapacitor.conf file in the beginning of this tutorial. You can get a Webhook URL by going to this page:

5 – Alerts definition

5.1 – High Memory Utilization Alert

Navigate to the “Rule Configuration” page by visiting the “Alerting” page and click on the “Build Rule” button in the top right corner:

We will trigger an alert if the memory usage is over 60%:

Next, we select Slack as the event handler and configure the alert message:

Note: there’s no need to include a Slack channel in the Alert Message section if you specified a default channel in the initial Slack configuration.

5.2 – High CPU Utilization Alert

Create a second rule to trigger an alert if CPU usage is over 40%:

Alert endpoint:

Save the rule, and you’re all set !

Now our alert rules are defined, lets test them out by creating some load on our cluster.

6 – Stress Testing

I used stress, a tool for generating workload. It can produce CPU, memory, I/O, and disk stress.

6.1 – Stressing the CPU

Note: depending on the type of your CPU, make sure to replace ‘4‘ accordingly.

After few seconds, you should receive a Slack notification:

Kapacitor trigger an alert and also recovered them (Status OK) if the alert is resolved.

6.2 – Stressing the Memory

It will stress memory using three processes, with each about 256 Mb (override with the option –vm-bytes).

Let it run for a couple seconds :

That’s it! You’ve successfully setup a highly scalable, distributed monitoring platform for your Swarm cluster with only Open Source projects.

Résultat de recherche d'images pour "wow amazing meme"

 

Monitor your Infrastructure with TIG Stack

In this tutorial, I will show you how to setup a monitoring stack for your infrastructure. So you can collects data from your servers, docker containers 🐋, and other kinds of network devices 📶 so you can analyze it for trends or problems.

Note: All code is available on my Github. 😎

1 – How it works ?

1.1 – Telegraf

Data collector written in Go for collecting, processing, and aggregating and writting metrics. Its a plugin driven tool, we will use a few plugins while implementing our use case.

1.2 – InfluxDB

Scalable time series database for metrics, events and real-time analytics.

1.3 – Grafana

Data visualization and exploration tool. It lets you create graphs and dashboards based on data from various data sources (InfluxDB, Prometheus, Elasticsearch, Cloudwatch …)

2 – Setup

Clone the repository:

To start all of these containers I’m using docker-compose:

The docker-compose bring up 3 containers:

1 – Influxdb:

Due to the ephemeral nature of containers. We exposed the Influxdb data folder to our host system. So our data wont disappear if the container restarts or is stopped.

The port mapping contains 3 port:

  • 8083: this is the administration web server’s port, you can open the admin page by http://localhost:8083
  • 8086: this is the HTTP API endpoint port, it’s used to send query to Influxdb by Telegraf

2 – Grafana

The port 3000 is the default web server port.

We used docker’s link feature to link Grafana container with our Influxdb container, so Grafana can connect to Influxdb and query data from it.

3 – Telegraf

Telegraf collect metrics from “input” plugins, parse it to the correct format then send it to “output” plugins. There is a lot of input and output plugins, you just have to activate them in the Telegraf configuration file:

Here I’m using the Docker input plugin to fetch all the stats from the docker daemon (resource usage per container) and System input plugin to pull server metrics (Disk, CPU, RAM …)

To start all of these services, we will use docker-compose:

If you type “docker ps“, you should see the TIG containers:

3 – Configure

Point your browser to http://SERVER_IP:3000, you should see Grafana Dashboard:

The default credential is admin with password admin. You will want to change this as soon as you can.

Now we need to create an Influxdb datasource pointing to the InfluxDB container.

3.1 – VM Data Source

We configure Grafana to pull data from vm_metrics database:

3.2 – Docker Data Source

Then we create another data source to fetch data from docker_metrics database.

Once that is completed, you are ready to start creating dashboards.

4 – Dashboards

On the top left menu, click on “Add a new Dashboard” then click on “Add a panel“:

4.1 – VM

4.1.1 – Memory

4.1.1 – Disk

4.1.3 – CPU

4.1.4 – Network

All graphs combined:

4.2 – Docker

4.2.1- Create Container Filter

In order to filter our data by container name, we will use a concept in Grafana called Templating which makes our Dashboard more interactive and dynamic. Therefore we won’t hard-code the name of the container in the metric query but instead we will use a variable.

So to create a variable, click on settings icon ⚒ then “Templating“:

Click on “New” and fill the fields as described below:

Once created, now the variable is shown as dropdown select boxes at the top of the dashboard. This dropdown make it easy to change the data being displayed in your dashboard.

Now our filter is created, we can jump to create our first graph:

4.2.1 – Memory

Here is a screenshot of the result: