如何基于Prometheus InfoMetricFamily在Grafana构建指定列的表格面板?
health_info Metrics Got it, let's break down exactly how to turn that Prometheus metric into a clean table in Grafana with name, status, and value as your columns. Here's a step-by-step guide:
Step 1: Create a New Table Panel
- Open your Grafana dashboard (or create a new one)
- Click Add panel → Select Table as the visualization type
Step 2: Write the PromQL Query
In the query editor, select your Prometheus data source and enter this simple query:
health_info
This pulls in all instances of your health_info gauge metric, including all its attached labels (name, status, value).
Step 3: Convert Labels to Table Columns
By default, Grafana will show the Time and Value columns, but we need to extract the labels into separate columns. Here's how:
- Switch to the Transform tab in the panel editor
- Click Add transformation → Select Labels to Fields
- This will automatically pull every label from your metric into its own column (you'll see
name,status,valueappear as new columns)
- This will automatically pull every label from your metric into its own column (you'll see
- Optional: Remove unnecessary columns (like
Timeor the originalValuecolumn, since it's always1.0for your metric) by clicking the eye icon next to the column name in the table preview.
Step 4: Polish the Table (Optional but Recommended)
- Rename columns: Go to the Panel options tab → Under Table options, find the Column styles section. You can set friendly names like
Nameinstead oflabel_name,Statusinstead oflabel_status, etc. - Add conditional coloring: For the
Statuscolumn, you can set cell colors based on the value (e.g., red for "danger", green for "ok"). In Column styles, select theStatuscolumn, set Color to "Thresholds", and define your color rules (e.g., "danger" = red, "ok" = green).
Why This Works
Your health_info metric stores all the relevant data (name, status, value) as Prometheus labels. Grafana's Labels to Fields transformation is perfect here—it takes those label key-value pairs and turns them into proper table columns, which is exactly what you need for your dashboard.
内容的提问来源于stack exchange,提问作者Rudziankoŭ

