Skip to content

This repository contains sample Spring Boot application that exposes metrics to Prometheus and Grafana. The goal of this project was to showcase how to collect and monitor application's metrics running inside kubernetes (Prometheus Operator) or docker compose.

License

rbiedrawa/spring-k8s-prometheus

Repository files navigation

Spring Boot Micrometer application with Prometheus Operator

This repository contains sample Spring Boot application that exposes metrics to Prometheus and Grafana.

The goal of this project was to showcase how to collect and monitor application's metrics running inside kubernetes or docker compose.

Table of Content

Features

  • Spring Boot Micrometer/Prometheus metrics integration.
  • Prometheus and Grafana docker-compose set up.
  • Kubernetes setup for running demo application with Prometheus Operator.
  • Service monitor configuration.

Architecture

architecture.png

Getting Started

Prerequisites

  • Java 11
  • Docker
  • Docker Compose
  • Kubernetes
  • Helm

Installation

Build docker image.

./gradlew bootBuildImage

Usage

Docker

  • Run docker-compose demo.

    docker-compose -f ./docker/docker-compose.yml up -d
  • Check if all applications are running

    docker-compose -f ./docker/docker-compose.yml ps
    
           Name                      Command                  State               Ports         
    --------------------------------------------------------------------------------------------
    grafana               /run.sh                          Up (healthy)   0.0.0.0:3000->3000/tcp
    hello-world-service   /cnb/process/web                 Up             0.0.0.0:8080->8080/tcp
    prometheus            /bin/prometheus --config.f ...   Up (healthy)   0.0.0.0:9090->9090/tcp

    **** all services should be up and running

  • Visit Prometheus targets page and check if hello-world-service scrapper is up and running.

  • Open your web browser and go to Grafana login page. On the login page, enter admin for username and password.

  • Open http://localhost:3000/dashboard/import and import JVM (Micrometer) dashboard. jvm-micrometer.png

  • Stop demo.

    docker-compose -f ./docker/docker-compose.yml down -v

Kubernetes

  • Install Prometheus Operator inside monitoring namespace.

    • Install helm.

      brew install helm
    • Add prometheus-community repo and update helm.

      helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
      
      helm repo update
    • Create monitoring namespace inside kubernetes.

      kubectl create ns monitoring
    • Install operator.

      helm install -n monitoring prometheus-operator prometheus-community/kube-prometheus-stack --set prometheus-node-exporter.hostRootFsMount=false

      *** --set prometheus-node-exporter.hostRootFsMount=false added to resolve this issue.

  • Start hello-world demo with service-monitor.

    • Create hello-world-service namespace.

      kubectl apply -f ./k8s/namespace.yml
    • Apply other k8s manifests.

      kubectl apply -f ./k8s 
  • Port forward Prometheus and Grafana services.

    kubectl port-forward svc/prometheus-operated 9090:9090 -n monitoring
    
    kubectl port-forward svc/prometheus-operator-grafana 3000:80 -n monitoring
  • Visit Prometheus targets page and check if hello-world-service scrapper is up and running.

    prometheus-targets.png

  • Open your web browser and go to Grafana login page. On the login page, enter admin for username and prom-operator as a password.

  • Import JVM (Micrometer) dashboard.

  • Check all dashboards provided by Prometheus Operator.

  • Uninstall demo from kubernetes environment.

    helm delete -n monitoring prometheus-operator
    
    kubectl delete ns monitoring
    
    kubectl delete all --all -n hello-world-service
    
    kubectl delete ns hello-world-service

References

License

Distributed under the MIT License. See LICENSE for more information.

About

This repository contains sample Spring Boot application that exposes metrics to Prometheus and Grafana. The goal of this project was to showcase how to collect and monitor application's metrics running inside kubernetes (Prometheus Operator) or docker compose.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages