DEV Community

Cover image for Prometric-Go Part 2 β€” Full Hands-On Demo with Grafana, Prometheus & k6 πŸ“ˆ
Md Asraful Haque (Sohel)
Md Asraful Haque (Sohel)

Posted on

Prometric-Go Part 2 β€” Full Hands-On Demo with Grafana, Prometheus & k6 πŸ“ˆ

This article is Part 2 of my Prometric-Go series.

If you haven't read Part 1 yet β€” the introduction to the library β€” you can check it out here:

πŸ”— https://dev.to/asraful_haque/simplifying-prometheus-metrics-in-go-with-prometric-go-22ef


πŸ‘‹ What we’re building in Part 2

In this article we will instrument a real Go API using prometric-go, collect metrics in Prometheus, and visualize everything in Grafana β€” including a load-test using k6 to generate traffic.

To make this super easy, I created a ready-to-run sample project:

πŸ”— GitHub Repo: https://github.com/peek8/prometric-go-sample

This repository contains:

Purpose Tool
Metric instrumentation prometric-go
Metrics storage Prometheus
Metrics visualization Grafana
Web API Go + net/http
Traffic Generation Grafan k6

k6 hits the API β†’ API exposes metrics via /metrics β†’ Prometheus scrapes β†’ Grafana visualizes.


βš™οΈ Clone & Run the Sample

$ git clone https://github.com/peek8/prometric-go-sample
$ cd prometric-go-sample
$ make run
Enter fullscreen mode Exit fullscreen mode

This will run the api server at port 7080. You can explore the prometheus metrics exposed by prometric-go library at url:

http://localhost:7080/metrics
Enter fullscreen mode Exit fullscreen mode

See the full metrics list exposed at prometric-go library readme

The K6 Script

I use Grafan k6 to generate traffic against the prometric API. This k6-scripts demonstrates a simple scenario that exercises the CRUD endpoints for Person objects.

What the script does

  • Creates some 50K Objects (ie Person) in ~20 mins (50000 iterations shared among 50 VUs, maxDuration: 10m).
  • Tries to get Person by Random Id for 10 mins (20.00 iterations/s for 10m0s, maxVUs: 10).
  • Tries to get Person list for 10 mins (10.00 iterations/s for 10m0s, maxVUs: 5).
  • Updates the Person for 10 mins (5.00 iterations/s for 2m0s, maxVUs: 5).
  • Deletes about 1500 Persons randomly within 10 mins (1500 iterations shared among 2 VUs,maxDuration: 10m0s).

These above iterations are enough to generate some adequate prometheus metrics which can be used to play with prometheus and grafana dashboard.

Run k6

  • Install Grafan k6 at your local machine and run the k6-scripts from the repo:
$ k6 run ./scripts/k6-scripts.js
Enter fullscreen mode Exit fullscreen mode

And now if you hit the metric endpoint, you will see different metric values keep changing.

Prometheus and Grafana

Run Prometheus

Run prometheus using the prometheus.yml file:

$ docker run \
    -p 9090:9090 \
    -v ./resources/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus
Enter fullscreen mode Exit fullscreen mode

N.B: If you are using podman use host.containers.internal as targets at prometheus.yml file, ie:

targets: ["host.containers.internal:7080"]
Enter fullscreen mode Exit fullscreen mode

Run Grafana

Run Grafan using docker:

$ docker run -d -p 3000:3000 grafana/grafana
Enter fullscreen mode Exit fullscreen mode

Then grafana will be available at http://localhost:3000, use admin:admin as to login for the first time.

Import the included dashboard

Create Grafana Data Source

Import Grafana Dashboard

  • Open Grafana β†’ Dashboards
  • Click Import
  • Upload grafana-dashboard.json
  • Select Prometheus datasource β†’ prometric-k6 (or the one you use)

Voila, You’ll now see real-time metrics at the dashboard from the sample app:

Image Grafana Dashboard

πŸ’‘ What You Learn From This Sample

Category Benefit
Go backend Clean way to expose metrics
Prometheus Scraping & querying the app
Grafana Dashboarding for API performance
k6 Generating programmable load
Observability From raw counters β†’ real visual insights

🎁 Bonus: You Can Reuse This as a Template

The repo is intentionally simple, so you can fork it and adapt it for your own services.

  • Replace Person CRUD API with your own business logic
  • Keep the prometric-go instrumentation + dashboard
  • Add additional domain metrics as needed
  • Extend k6 tests to simulate real traffic

🌟 Final Thoughts

Prometheus + Grafana can feel complex when you start from scratch β€”
but with prometric-go, you get:

πŸ‘Œ Meaningful metrics by default
πŸ“¦ Domain-specific metrics with 2–3 lines of code
πŸš€ Dashboards ready to plug into production

If you try out the sample, I’d love to hear your feedback!

⭐ If this helped you…

Support the project by giving a ⭐ to both repos:

πŸ”— https://github.com/peek8/prometric-go

πŸ”— https://github.com/peek8/prometric-go-sample

And feel free to reach out if you want help adding alerting rules, histograms tuning, Grafana provisioning, or Kubernetes deployment.

Top comments (0)