Skip to content

Instantly share code, notes, and snippets.

@s1037989
Created April 18, 2025 09:47
Show Gist options
  • Save s1037989/612498a49732ef49ce3b99f9df91be2b to your computer and use it in GitHub Desktop.
Save s1037989/612498a49732ef49ce3b99f9df91be2b to your computer and use it in GitHub Desktop.
With the sample Open Metrics SLOC scrape, how to represent that in a Grafana table with these headers?
Baseline, Release, Total Baseline SLOC Ada, Total Release SLOC C++, Added SLOC Ada, Added SLOC C++, Modified SLOC Ada, Modified SLOC C++, Deleted SLOC Ada, Deleted SLOC C++
ChatGPT said:
To represent the OpenMetrics SLOC data in a Grafana table with your specified headers, follow this plan:
🪄 Grafana Table Setup Plan
📋 Desired Headers:
| Baseline | Release | Total Baseline SLOC Ada | Total Baseline SLOC C++ | Added SLOC Ada | Added SLOC C++ | Modified SLOC Ada | Modified SLOC C++ | Deleted SLOC Ada | Deleted SLOC C++ |
🧮 Step 1: Use Prometheus as a Data Source
In Grafana:
Add your Prometheus server as a data source.
Create a new dashboard panel with Visualization → Table.
🧠 Step 2: Prometheus Queries Per Column
For each metric, you’ll query using label_values to filter by language, baseline_version, and release.
Use Grafana's instant queries to get single-point values for a snapshot table.
Example queries for each column:
Column Query
Baseline label_values(sloc_total_baseline_lines, baseline_version) (use Transform later)
Release label_values(sloc_total_baseline_lines, release) (use Transform later)
Total Baseline SLOC Ada sloc_total_baseline_lines{language="ada"}
Total Baseline SLOC C++ sloc_total_baseline_lines{language="cpp"}
Added SLOC Ada sloc_added_lines{language="ada"}
Added SLOC C++ sloc_added_lines{language="cpp"}
Modified SLOC Ada sloc_modified_lines{language="ada"}
Modified SLOC C++ sloc_modified_lines{language="cpp"}
Deleted SLOC Ada sloc_deleted_lines{language="ada"}
Deleted SLOC C++ sloc_deleted_lines{language="cpp"}
🛠️ Step 3: Use Transformations in Grafana
Once all queries are added:
Add a transformation → "Outer join" by baseline_version and release labels.
Rename the fields to match your header titles exactly (e.g., "Added SLOC Ada").
Optionally, use Format → Table and remove timestamp columns if you don’t need them.
🎯 Result: A single Grafana table like:
Baseline Release Total Baseline SLOC Ada Total Baseline SLOC C++ Added SLOC Ada ...
1.2.3 R45 12345 67890 100 ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment