Working with Grafana 12 Loki, I would like to show the "log volume" graph in a dashboard. That graph is shown in the Explorer view for Loki.
How can I make a barchart to show stacks with errors in red, warnings in yellow and info in green? For example:
See the visualization below, this is what i have: the bars show counts for the errors, warnings and info's. Nice. But all 3 parts are shown in green.
The timeline of 5 minutes and 6 hours. I just chose to get visitable data. The log generating apps did not run for some time. I will improve that one later.
I tried all kinds of ways using the panel options:
Nothing helped so far. I hope you can help.
When asked for it, this is the JSON model:
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 4,
"links": [],
"panels": [
{
"datasource": {
"type": "loki",
"uid": "P8E80F9AEF21F6940"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "series",
"axisGridShow": true,
"axisLabel": "",
"axisPlacement": "auto",
"fillOpacity": 80,
"gradientMode": "scheme",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineWidth": 1,
"scaleDistribution": {
"type": "linear"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [
{
"options": {
"ERROR": {
"color": "red",
"index": 0,
"text": "Error"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "Value"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "red",
"mode": "fixed"
}
},
{
"id": "custom.axisColorMode",
"value": "text"
}
]
},
{
"matcher": {
"id": "byName",
"options": "WARN"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "yellow",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "INFO"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "green",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"barRadius": 0,
"barWidth": 0.24,
"colorByField": "Time",
"fullHighlight": false,
"groupWidth": 0.7,
"legend": {
"calcs": [
"count"
],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"orientation": "vertical",
"showValue": "always",
"stacking": "normal",
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
},
"xField": "Time",
"xTickLabelRotation": 0,
"xTickLabelSpacing": 200
},
"pluginVersion": "12.0.1",
"targets": [
{
"direction": "backward",
"editorMode": "code",
"expr": "sum by (level) (count_over_time({namespace=\"default\"} | json | line_format \"{{.log}}\" | json | message !~ \"^$\" or stacktrace !~ \"^$\" [5m]))",
"legendFormat": "{{level}}",
"queryType": "range",
"refId": "Query error",
"step": ""
}
],
"title": "Level counts",
"type": "barchart"
},
{
"datasource": {
"type": "loki",
"uid": "P8E80F9AEF21F6940"
},
"fieldConfig": {
"defaults": {
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"inspect": false
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green"
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "Time"
},
"properties": [
{
"id": "custom.width",
"value": 175
}
]
},
{
"matcher": {
"id": "byName",
"options": "container"
},
"properties": [
{
"id": "custom.width",
"value": 226
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 8
},
"id": 1,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true,
"sortBy": []
},
"pluginVersion": "12.0.1",
"targets": [
{
"datasource": {
"type": "loki",
"uid": "P8E80F9AEF21F6940"
},
"direction": "backward",
"editorMode": "code",
"expr": "{namespace=\"default\"} | json | line_format \"{{.log}}\" | json | line_format \"[{{.container}}] {{.message}}\\n{{.stack_trace}}\"",
"queryType": "range",
"refId": "A"
}
],
"title": "New Panel",
"transformations": [
{
"id": "extractFields",
"options": {
"source": "labels"
}
},
{
"id": "organize",
"options": {
"includeByName": {
"Time": true,
"container": true,
"message": true
},
"indexByName": {
"Time": 0,
"container": 1,
"message": 2
}
}
}
],
"type": "table"
}
],
"preload": false,
"schemaVersion": 41,
"tags": [],
"templating": {
"list": []
},
"time": {
"from": "now-1h",
"to": "now"
},
"timepicker": {},
"timezone": "browser",
"title": "Loki 3",
"uid": "5722542b-797b-4dbd-89e5-9f72853cbdfb",
"version": 3
}
Unset the Color by field visualization option.
Use the color value for a sibling field to color each bar value.
You have it set to "Time" which colors each bar with the color of the time value (and green is the default).
It's the 4th last option in the "Bar chart" options group, but you can easily search for it by clicking the magnifying glass next to the visualization type dropdown.