DEV Community

Cover image for Setup Grafana, Jaeger & Zipkin locally
Wesley Skeen
Wesley Skeen

Posted on

Setup Grafana, Jaeger & Zipkin locally

Here is an easy way to setup Grafana locally using docker and dotnet.

Grafana-Data-Sources

The current set up in this repo is very minimal. I am just touching the surface of what is possible. I wanted to demonstrate how to run the services locally

Build and run the api with docker on local port 4000

> docker build --pull --no-cache -t weather_forecast_api -f ops/docker/Dockerfile .
> docker run -p 4000:5000 --rm weather_forecast_api
Enter fullscreen mode Exit fullscreen mode

You should now be able to view OTEL metrics from the API

> curl http://localhost:4000/metrics

# TYPE process_runtime_dotnet_gc_collections_count counter
# HELP process_runtime_dotnet_gc_collections_count Number of garbage collections that have occurred since process start.
process_runtime_dotnet_gc_collections_count{generation="gen2"} 0 1665568680770
process_runtime_dotnet_gc_collections_count{generation="gen1"} 0 1665568680770
process_runtime_dotnet_gc_collections_count{generation="gen0"} 0 1665568680770

.
.
.

# EOF
Enter fullscreen mode Exit fullscreen mode

Build and run the api with docker compose

Using docker compose, we can combine multiple docker containers into a single deployment These containers can communicate with each other since we can specify what…

Please refer to the above repo for the source code to run the below commands and follow along.

Build and run the api with docker on local port 4000

> docker build --pull --no-cache -t weather_forecast_api -f ops/docker/Dockerfile .
> docker run -p 4000:5000 --rm weather_forecast_api
Enter fullscreen mode Exit fullscreen mode

You should now be able to view OTEL metrics from the API

> curl http://localhost:4000/metrics

# TYPE process_runtime_dotnet_gc_collections_count counter
# HELP process_runtime_dotnet_gc_collections_count Number of garbage collections that have occurred since process start.
process_runtime_dotnet_gc_collections_count{generation="gen2"} 0 1665568680770
process_runtime_dotnet_gc_collections_count{generation="gen1"} 0 1665568680770
process_runtime_dotnet_gc_collections_count{generation="gen0"} 0 1665568680770

.
.
.

# EOF
Enter fullscreen mode Exit fullscreen mode

Build and run the api with docker compose

Using docker compose, we can combine multiple docker containers into a single deployment.
These containers can communicate with each other since we can specify what network they can be added to.

First build the image

> docker build --pull --no-cache -t weather_forecast_api -f ops/docker/Dockerfile .
Enter fullscreen mode Exit fullscreen mode

Then in the docker folder (ops/docker), run

> docker-compose up
Enter fullscreen mode Exit fullscreen mode

Among other things, this will bring up Promethius. We have set Promethius up to scrape metrics from the /metrics endpoint of the weather forecaset API.
Notice in the promethius.yml file

static_configs:      
      # replace the IP with your local IP for development
      # localhost is not it, as that is w/in the container :)
      - targets: ['weather_forecast_api:5000']
Enter fullscreen mode Exit fullscreen mode

To confirm promethius can access the API metric scraping endpoint, browse to Browse to the targets page. You should see

Promethius targets page

Notice that the Status is UP

Grafana set up

Browse to the datasources page

username : admin

password : P@ssw0rd

Promethius

Set the URL to http://prometheus:9090 and then click Save & Test

Then go to the explore page and select promethius as the data source. You should be able to access the metrics

Promethius metrics

Custom metrics

As an example, I have added a custom meter counter that we can use to track the number of requests made to /WeatherForecast

In WeatherForecastController.cs We have

SharedTelemetryUtilities.RequestCounter.Add(1);
Enter fullscreen mode Exit fullscreen mode

This will add a new metric with a name we have specified data.request_counter
We can now view this custom metric in Grafana

Promethius custom metric

Loki

Set the URL to http://loki:3100 and then click Save & Test

Then go to the explore page and select loki as the data source. Under labels, select filename. You should have have a log file accessable.

Loki dashboard

Traces

In the endpoint /WeatherForecast I added some external calls to show traces in action. Once you make some calls to this endpoint, you will start to generate traces

Zipkin

Browse to zipkin and click RUN QUERY. This should display some traces

Zipkin dashboard

Clicking one of these traces will give you more detail. As you can see, there is an over all request and the 2 external calls.

Zipkin trace

Jaeger

Browse to Jaeger, select a service and click Find Traces. This should display some traces

Jaeger dashboard

Similar to Zipkin, clicking on one of the traces will give more detail

Jaeger trace

Top comments (0)