Logo

dev-resources.site

for different kinds of informations.

Real-time data visualization and alerts using Redis TimeSeries, Grafana and Slack.

Published at
12/13/2023
Categories
grafana
slack
dashboard
redis
Author
parallelthreads
Categories
4 categories in total
grafana
open
slack
open
dashboard
open
redis
open
Author
15 person written this
parallelthreads
open
Real-time data visualization and alerts using Redis TimeSeries, Grafana and Slack.

In any non-trivial application, each part of the system generates a substantial amount of data. Whatever be the domain, we want to observe, monitor, and act on this data.

We will explore visualization of real-time data in Grafana and while Prometheus is usually what is associated with in such scenarios, we will look at Redis TimeSeries.
We will create a dashboard for a simple app that generates a continuous stream of data and store it in Redis as Time Series data and visualize in Grafana, and configure alerts via Slack.

Application and Data

The client is a simple .NET console app that sends memory usage data on the Windows client, with an introduced delay of 750 milliseconds. This data includes total system memory usage (which is what is visualized) and memory used by each process.

The server is a basic Node.js app, and for simplicity it uses WebSocket connection as we have a steady stream of data being received. This data is then passed on to the primary Redis instance which will accept the incoming writes.

Note:
The client and the server apps are developed to get the data flowing in and do not follow any best practices like retries, error handling, configuration, logging etc.
In the current dev setup, the Node.js server, Redis and Grafana all run on the same Mac.

Configuring Redis

Installing Redis on Mac is straightforward following the instructions here. We have 2 Redis instances running - one to accept the writes and the other, from which Grafana will pull the data for visualization. There is significant documentation on replication and persistence in Redis and for this example, the second instance acts as a read-only replica which is replicated asynchronously.

We use the Redis TimeSeries type which, as the name suggests,¬ stores time series data. The type expects the value to be numeric and that is what we have - a series of numbers representing the memory utilization, in Megabytes, at that point in time.

For every data point, the key is the current timestamp, and the memory utilization number is the value. At this point, we have the data in memory, in the format we need, which can be visualized on a dashboard.

Note: We have a single Windows client here, but we can have multiple clients with a label for each time series data entry to query on.

Grafana and the Dashboard

Grafana is an open-source data visualization and monitoring solution - it allows us to query, visualize, set alerts and more for the data at hand. In this example, Grafana is setup to run locally on the Mac. After installation, the webpage is available at http://localhost:3000 where you can sign-in with the default credentials of admin/admin (and change the password).

First order of business in Grafana is to set up a dashboard with the data source of our choice, in this case Redis. You can create a new dashboard and provide Redis as the data source for the dashboard.

Image description

The screenshot shows the dashboard with Redis as the source and TimeSeries as the type. There are several commands available but the one we are interested is the TS.GET to fetch the data. You can also notice on the right side the numerous ways to customize the visualization with tool-tips, legend, graph styles etc.

We also apply a Transformation on the data for visualization where it creates a new data frame for each pair of data being received.

Image description

Once the entire setup is up and running, we can see the data show up in the dashboard as a continuously updated graph of memory utilization over time.

Slack Alerts for High-Memory Usage

Now that we have the dashboard setup and we can visualize the data, it would be nice if we could do something other than just looking at the graph.
As it is system memory usage, let’s say that we want to be notified if total system memory usage crosses 7000 MB on the client machine. To achieve this, an alert rule is configured where Grafana will notify on a Slack channel.

Image description

The alert also allows configuring options like how long it should evaluate the alert condition, how often to check for the condition, silencing options and more.

Image description

Here as we are using Slack, we first need to configure it to allow an incoming webhook (This webhook allows POST to the provided URL and is not shared anywhere other than in the Grafana notification setting).
Once added, you should see the notifications in Slack when the alert condition is met.

Image description

Grafana supports notification templates which can be reused across different types of notification contact points and messages can be configured and formatted too.
It also supports a whole bunch of options when it comes to alerting other than Slack.

Here are the GitHub links for the Windows client app, and the Node.js service with the Redis configs and Grafana dashboard/alert rule export.

Cover image credit: Photo by Markus Winkler on Unsplash

dashboard Article's
30 articles in total
Favicon
Prometheus Instance Exposed
Favicon
Designing Beautiful Dashboard Layouts with Tailwind CSS
Favicon
Unlock 1 Billion NYC Taxi Rides: A Step-by-Step Guide
Favicon
Create a Warehouse Dashboard In 3 Steps
Favicon
Case Study:- SaaS Dashboard Design
Favicon
Dicas para criação de dashboards de monitoramento no Kibana
Favicon
Create an E-commerce Dashboard In 3 Steps
Favicon
Deploy a lightweight BI solution with your first dashboard in 5 steps
Favicon
Déployer une solution de BI légère avec son premier dashboard en 5 étapes
Favicon
Crafting My Perfect Home Assistant Dashboard
Favicon
Building a Real-Time IoT Dashboard with HarperDB and Node.js
Favicon
Power BI Dashboard: Ultimate Tool for Dynamic Data Visualization and Storytelling
Favicon
Dashboard Estratégico X Dashboard Operacional
Favicon
Whatsapp Webhook Setup and Nodejs Code Example
Favicon
Better tools make good work -- learn to use the research environment to analyze trading principles
Favicon
My Experience Learning Go, next steps
Favicon
Kaiadmin Lite - Free Bootstrap 5 Admin Dashboard
Favicon
Copy & Paste React Components for Dashboards
Favicon
Tailwind Dashboard Template Free Starter
Favicon
Code-Along: How to Develop a REST API Dashboard
Favicon
Portfolio Showcase?
Favicon
7 Premium Tailwind Dashboard Admin Templates for 2024
Favicon
Real-time data visualization and alerts using Redis TimeSeries, Grafana and Slack.
Favicon
Salesforce Reports & Dashboards Best Practices
Favicon
11 Best Tailwind Dashboard Template For 2024
Favicon
Web Dashboard GUI for Kafka Cluster Monitoring
Favicon
Develop a Simple PDF Invoicing App for your Business with CASE
Favicon
Top Benefits of Using Core App Dashboard
Favicon
Awesome Free Bootstrap Admin Dashboards.
Favicon
Creating your first React Native table vs DronaHQ table! which one is easy?

Featured ones: