This content originally appeared on DEV Community and was authored by Md Asraful Haque (Sohel)
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
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
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
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
N.B: If you are using podman use host.containers.internal as targets at prometheus.yml file, ie:
targets: ["host.containers.internal:7080"]
Run Grafana
Run Grafan using docker:
$ docker run -d -p 3000:3000 grafana/grafana
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
- You can create datasource if you don't have any running the shell script: grafana-datasource.sh
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:
π‘ 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.
This content originally appeared on DEV Community and was authored by Md Asraful Haque (Sohel)
Md Asraful Haque (Sohel) | Sciencx (2025-11-18T04:19:43+00:00) Prometric-Go Part 2 β Full Hands-On Demo with Grafana, Prometheus & k6 π. Retrieved from https://www.scien.cx/2025/11/18/prometric-go-part-2-full-hands-on-demo-with-grafana-prometheus-k6-%f0%9f%93%88/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.
