Setup Grafana, Jaeger & Zipkin locally

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

WesleySkeen
/
Grafana-Data-Sources

Grafana-Data-Sources
The current set up in this repo is …


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wesley Skeen

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

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

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

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

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 .

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

> docker-compose up

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']

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);

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


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Wesley Skeen


Print Share Comment Cite Upload Translate Updates
APA

Wesley Skeen | Sciencx (2022-11-21T16:17:59+00:00) Setup Grafana, Jaeger & Zipkin locally. Retrieved from https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/

MLA
" » Setup Grafana, Jaeger & Zipkin locally." Wesley Skeen | Sciencx - Monday November 21, 2022, https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/
HARVARD
Wesley Skeen | Sciencx Monday November 21, 2022 » Setup Grafana, Jaeger & Zipkin locally., viewed ,<https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/>
VANCOUVER
Wesley Skeen | Sciencx - » Setup Grafana, Jaeger & Zipkin locally. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/
CHICAGO
" » Setup Grafana, Jaeger & Zipkin locally." Wesley Skeen | Sciencx - Accessed . https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/
IEEE
" » Setup Grafana, Jaeger & Zipkin locally." Wesley Skeen | Sciencx [Online]. Available: https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/. [Accessed: ]
rf:citation
» Setup Grafana, Jaeger & Zipkin locally | Wesley Skeen | Sciencx | https://www.scien.cx/2022/11/21/setup-grafana-jaeger-zipkin-locally/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.