问题
I have following code:
c = InfoMetricFamily("health", "Health Monitoring")
c.add_metric(labels=name, value={"name": name, "status": status, "value": value})
that supply Prometheus with following metric:
# HELP health_info Health Monitoring
# TYPE health_info gauge
health_info{name="external",status="danger",value="N\\A"} 1.0
I would like to build table dashboard in Grafana where name, status, value will be columns. How could I do this?
回答1:
Since Grafana v4.3, the table panel supports the display of Prometheus labels.
To create the display, add a table panel in your dashboard:
- In the
Querytab- Toggle
Instantto True and setFormattoTable; if you start by filling the query you may have a BIG response freezing your window - Write your query in
Metrics: in your casehealth_info
- Toggle
- In the visualization Tab, you will control the columns that should appear and format their display
- Remove the
Timecolumn (unless you need it, personally I rarely do) - Set the catchall rule
/.*/to TypeHidden; it will hide all your columns - Use
Add column styleto hide a column to display by typing then name inApply to columns named(the completion works well) - You can adjust name of column in
Column Headerand tune the display
- Remove the
NOTE: currently, you cannot modify the order of the columns.
If you want to display multiple metrics on the same lines note that:
- all labels must match: remove conflicting ones by apply an aggregation function
- the name of the metric is a label: you need also to get rid of
__name__label - When adding the second value, the name of the column of the first value changes to
Value #Aand the display needs to be adjusted
来源:https://stackoverflow.com/questions/58627208/make-table-visualization-in-grafana-using-prometheuss-infometricfamily