Skip to content

The project is focused on using Prometheus for monitoring on different levels and Grafana for data visualization.

Notifications You must be signed in to change notification settings

Taiwolawal/Prometheus-and-Grafana

Repository files navigation

Prometheus-and-Grafana

This project is focused on using Prometheus for monitoring on different levels and also implementing Grafana for data visualization :

  • Infrastructure Level: CPU, RAM, Network etc
  • Platform Level: Kubernetes components
  • Application Level: 3rd-party and Own application

Requirements:

  • Ensure AWS-CLI, Kubectl and Helm are installed
  • Configure AWS credentials on local machine with admin access (for project purpose)

Setup EKS cluster using EKSCTL command.

image

Connect to the cluster, add prometheus chart and install prometheus chart for kubernetes into the cluster

image image

image

Port forward to grafana and prometheus service to connect to the U.I

image

Access UI for prometheus and grafana (enter required credentials)

image

image

image

image

List below are the metrics gotten from the clusters including the nodes also

image

Below is a detailed metrics for the cluster

image

Deployed a microservice application

image

image

We will launch a container dedicated to using the Curl command on the load balancer. This involves connecting to the applications through a script that establishes a loop, which create a high traffic

image image image

image

The expression rate(node_cpu_seconds_total{mode="idle"}[2m]) is a Prometheus query that calculates the per-second rate of change for the node_cpu_seconds_total metric with the mode label set to `"idle". This type of expression is what is used by grafana to display metrics needed.

image

There is need to get notified when something goes wrong, this is where alerting comes into play

  • Define what we want to be notified about e.g when CPU usage is above is 50%
  • Send notification i.e email/slack notification (will be implemented later)

We will set alert rules on any usecase we are interested e.g pod not starting. The prometheusrule handles the rules

image

When setting up this rules, its imperative to make use of the appropriate labels in the rules we plans on setting up, the highlighted lables below needs to be specified in our rule.

image

We are setting two alerts respectively downand HostHighCpuLoad. The labels are included so that prometheusrule can include it in the alert that it has to monitor

image

When you apply this rules, ensure you check prometheus log of config-reloader container to confirm a reload has triggered(which implies the rule has been added) by checking the time and confirm it occured after applying the rule.

image image

The alerts have been updated.

image

image

Let run cpustress container to generate CPU load and see if the alert will be triggered.

image

image

We just completed Kubernetes-level monitoring. Now, we are turning our attention to monitoring Redis, a third-party application within our microservices. To achieve this, we are utilizing an exporter that fetches metric data from the service and transforms the service-specific metrics into a format understandable by Prometheus. This exporter exposes the translated metrics through the /metrics endpoint. To ensure Prometheus is aware of this new exporter, we will deploy a ServiceMonitor, a custom Kubernetes resource designed for this purpose.

Deploy redis exporter, ensure you set servicemonitor to true and specify the redis service name in the helms value

image image image image image

Redis-exporter is deployed by checking the targets under the status section and we can query different redis metrics.

image

image

We can see the redis-exporter pod

image image

We can setup a prometheusrule using ready made rules Exporter rules to define the rules to specify for our exporters. For our redis application, we will be using Redis rule, like the screenshot below.

image

Ensure you specified the appropriate labels and apply the rule

image image

image

Let edit the redis pod replica to zero, to see if the redis-exporter will be triggered.

image image

image

Now lets try and create a dashboard for our redis application, we can make use of ready made dashboards from Grafana, we will be making use on one of the numerous dashoard for Redis

Copy the ID number and import the dashboard in grafana using the number, ensure you select data source as prometheus.

image

image

image

image

image

There are other redis dashboards you can also use. The one below is with ID 15895.

image

Lastly, we want to monitor our own application deployed in the cluster and we are using a nodejs application. There are no exporter available for our own application, so we have to define the metrics (custom solution). There are prometheus client library for different languages in which the application is written it. Developers write the code using the prometheus client library. The screenshot shows metrics to monitor in the application

image

We need to ensure to setup a servicemonitor with the appropriate label for the application nodeappand prometheus release=prometheus respectively so that the targets can be included in prometheus for monitoring

image

The targets have been included and we can query metrics for the application

image

image

image

Define the metrics we want to monitor and setup a grafana dashboard to display this metrics.

image

image

image

image

image

Ensure you delete the project when finished

BLOCKER: RESOLVED DELETING THE CLUSTER

When trying to delete the cluster you might get the error below

image

Follow the command below to resolve

image

About

The project is focused on using Prometheus for monitoring on different levels and Grafana for data visualization.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published