Skip to content

Latest commit

 

History

History

exercise-3

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Exercise 3

Introduction

Even if you know how to fix a memory leak, you would have preferred not having to!

Monitoring your application is the key.

In this exercise, you will start a Prometheus, make it scrape your application, and create an alert.

Start

Run the exercise application

npm run start-exercise-3

In another terminal, run the docker image "prom/prometheus"

docker run \
  --network host \
  --volume "/prometheus" \
  --volume "$(pwd)/src/exercise-3/prometheus-data:/prometheus-data" \
  prom/prometheus \
    --storage.tsdb.path=/prometheus-data/storage \
    --config.file=/prometheus-data/prometheus.yml 

Open http://localhost:9090, you should see the prometheus interface

Graphing

Prerequisites

Have a look at the prometheus queries!

Watch the heap!

From there, create graphs showing the heap spaces sizes over 5 minutes.

Solution

  • click on "add graph" to get 2 graphs
  • switch to graph mode for both
  • enter the following queries
    nodejs_heap_space_size_used_bytes{space="new"}
    
    and
    nodejs_heap_space_size_used_bytes{space="old"}
    
  • press "execute" for both

Watch the GC!

Create another graph on the same page showing the garbage collector reclaimed bytes increase per minute over 5 minutes..

Solution

  • click on "add graph"
  • switch to graph mode
  • enter the following query
    increase(nodejs_gc_reclaimed_bytes_total{}[1m])
    
  • check "stacked"
  • press "execute"

Eventually, you should reach this state.