Grafana dashboard: K8s Logs
Description: This dashboard shows logs along with log generation rate, error and exception log rate and the amount of log generated with its rate in MB


{
  "__inputs": [
    {
      "name": "DS_LOKI-PROD-RELEASE",
      "label": "Loki-prod-release",
      "description": "Loki",
      "type": "datasource",
      "pluginId": "loki",
      "pluginName": "Loki"
    }
  ],
  "__elements": {},
  "__requires": [
    {
      "type": "panel",
      "id": "gauge",
      "name": "Gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "9.1.7"
    },
    {
      "type": "panel",
      "id": "logs",
      "name": "Logs",
      "version": ""
    },
    {
      "type": "datasource",
      "id": "loki",
      "name": "Loki",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "timeseries",
      "name": "Time series",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "datasource",
          "uid": "grafana"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "target": {
          "limit": 100,
          "matchAny": false,
          "tags": [],
          "type": "dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": null,
  "links": [
    {
      "asDropdown": false,
      "icon": "dashboard",
      "includeVars": false,
      "keepTime": false,
      "tags": [],
      "targetBlank": true,
      "title": "pod Metrics",
      "tooltip": "",
      "type": "link",
      "url": "https://iamgrafana.groww.in/d/iWcvUh7nz/compute-resources-pods?orgId=1&refresh=10s"
    }
  ],
  "liveNow": false,
  "panels": [
    {
      "collapsed": false,
      "datasource": {
        "type": "prometheus",
        "uid": "k1DFTi3Gz"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 12,
      "panels": [],
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "k1DFTi3Gz"
          },
          "refId": "A"
        }
      ],
      "title": "Log Panel",
      "type": "row"
    },
    {
      "datasource": {
        "type": "loki",
        "uid": "${DS_LOKI-PROD-RELEASE}"
      },
      "gridPos": {
        "h": 18,
        "w": 24,
        "x": 0,
        "y": 1
      },
      "id": 2,
      "links": [
        {
          "targetBlank": true,
          "title": "pod Metrics",
          "url": "https://iamgrafana.groww.in/d/iWcvUh7nz/compute-resources-pods?orgId=1&refresh=10s"
        }
      ],
      "options": {
        "dedupStrategy": "exact",
        "enableLogDetails": true,
        "prettifyLogMessage": true,
        "showCommonLabels": false,
        "showLabels": false,
        "showTime": false,
        "sortOrder": "Descending",
        "wrapLogMessage": true
      },
      "targets": [
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "expr": "{cluster=\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"} |~ \"(?i)$search\" ",
          "hide": false,
          "refId": "A"
        }
      ],
      "title": "Logs",
      "type": "logs"
    },
    {
      "collapsed": true,
      "datasource": {
        "type": "prometheus",
        "uid": "k1DFTi3Gz"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 19
      },
      "id": 10,
      "panels": [
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "fixedColor": "orange",
                "mode": "palette-classic"
              },
              "custom": {
                "axisCenteredZero": false,
                "axisColorMode": "text",
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 21,
                "gradientMode": "opacity",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "smooth",
                "lineWidth": 2,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "never",
                "spanNulls": true,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "links": [
                {
                  "targetBlank": true,
                  "title": "Pod Metrics",
                  "url": "https://iamgrafana.groww.in/d/iWcvUh7nz/compute-resources-pods?orgId=1&refresh=10s"
                }
              ],
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              },
              "unit": "short"
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 0,
            "y": 20
          },
          "id": 8,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "bottom",
              "showLegend": true
            },
            "tooltip": {
              "mode": "single",
              "sort": "none"
            }
          },
          "pluginVersion": "8.1.1",
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(rate({cluster=\"$cluster\",workload=~\"$workload\",pod=~\"$pod\"} |~ \"(?i)exception\"[1m])) by (workload)",
              "legendFormat": "{{workload}}",
              "refId": "A"
            }
          ],
          "title": "Rate of Exception Logs[1m]",
          "transparent": true,
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "fixedColor": "red",
                "mode": "palette-classic",
                "seriesBy": "last"
              },
              "custom": {
                "axisCenteredZero": false,
                "axisColorMode": "text",
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 23,
                "gradientMode": "opacity",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "smooth",
                "lineWidth": 2,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "links": [
                {
                  "targetBlank": true,
                  "title": "Pod Metrics",
                  "url": "https://iamgrafana.groww.in/d/iWcvUh7nz/compute-resources-pods?orgId=1&refresh=10s&var-datasource=Thanos-v2"
                }
              ],
              "mappings": [],
              "noValue": "No Error ",
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 8,
            "w": 12,
            "x": 12,
            "y": 20
          },
          "id": 6,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "bottom",
              "showLegend": true
            },
            "tooltip": {
              "mode": "single",
              "sort": "none"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(rate({cluster=\"$cluster\",workload=~\"$workload\",pod=~\"$pod\"} |~ \"(?i)error\"[1m])) by (workload)",
              "instant": false,
              "legendFormat": "{{workload}}",
              "maxLines": 0,
              "range": true,
              "refId": "A"
            }
          ],
          "title": "Rate of Error logs[1m]",
          "transparent": true,
          "type": "timeseries"
        }
      ],
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "k1DFTi3Gz"
          },
          "refId": "A"
        }
      ],
      "title": "Error and Exception Rate",
      "type": "row"
    },
    {
      "collapsed": true,
      "datasource": {
        "type": "prometheus",
        "uid": "k1DFTi3Gz"
      },
      "gridPos": {
        "h": 1,
        "w": 24,
        "x": 0,
        "y": 20
      },
      "id": 14,
      "panels": [
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 6,
            "w": 12,
            "x": 0,
            "y": 29
          },
          "id": 20,
          "options": {
            "orientation": "auto",
            "reduceOptions": {
              "calcs": [
                "lastNotNull"
              ],
              "fields": "",
              "values": false
            },
            "showThresholdLabels": false,
            "showThresholdMarkers": true
          },
          "pluginVersion": "9.1.7",
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(bytes_over_time({cluster=~\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"} |~ \"(?i)$search\"  [$__range]))/1024/1024",
              "legendFormat": "",
              "refId": "A"
            }
          ],
          "title": "Log Data in MB",
          "type": "gauge"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "description": "Total logs produced by application",
          "fieldConfig": {
            "defaults": {
              "color": {
                "fixedColor": "blue",
                "mode": "fixed"
              },
              "mappings": [
                {
                  "options": {
                    "match": "null",
                    "result": {
                      "index": 0,
                      "text": "0"
                    }
                  },
                  "type": "special"
                }
              ],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 6,
            "w": 12,
            "x": 12,
            "y": 29
          },
          "id": 18,
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "auto",
            "orientation": "auto",
            "reduceOptions": {
              "calcs": [
                "last"
              ],
              "fields": "",
              "values": false
            },
            "text": {},
            "textMode": "auto"
          },
          "pluginVersion": "9.1.7",
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(count_over_time({cluster=~\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"} |~ \"(?i)$search\"  [$__range]))",
              "hide": false,
              "instant": false,
              "legendFormat": "Total Logs",
              "range": true,
              "refId": "A"
            }
          ],
          "title": "Total Number of   Log Lines",
          "type": "stat"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisCenteredZero": false,
                "axisColorMode": "text",
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 0,
                "gradientMode": "none",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "linear",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 6,
            "w": 12,
            "x": 0,
            "y": 35
          },
          "id": 21,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "bottom",
              "showLegend": true
            },
            "tooltip": {
              "mode": "single",
              "sort": "none"
            }
          },
          "pluginVersion": "8.4.3",
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(bytes_rate({cluster=~\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"} |~ \"(?i)$search\"  [5m]))",
              "legendFormat": "",
              "refId": "A"
            }
          ],
          "title": "Bytes sent rate",
          "type": "timeseries"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "description": "Percentage of Error logs produced by application\npattern used to filter error log line is  \"ERROR\"",
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "thresholds"
              },
              "mappings": [
                {
                  "options": {
                    "match": "null",
                    "result": {
                      "index": 0,
                      "text": "0"
                    }
                  },
                  "type": "special"
                }
              ],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 0.5
                  }
                ]
              },
              "unit": "none"
            },
            "overrides": []
          },
          "gridPos": {
            "h": 6,
            "w": 12,
            "x": 12,
            "y": 35
          },
          "id": 16,
          "options": {
            "colorMode": "value",
            "graphMode": "area",
            "justifyMode": "auto",
            "orientation": "auto",
            "reduceOptions": {
              "calcs": [
                "last"
              ],
              "fields": "",
              "values": false
            },
            "text": {},
            "textMode": "auto"
          },
          "pluginVersion": "9.1.7",
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(count_over_time({cluster=~\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"}  |~ \"ERROR\"[$__range]))",
              "hide": false,
              "refId": "A"
            },
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(count_over_time({cluster=~\"$k8s_cluster\",workload=~\"$application_name\"}  |~ \"ERROR\"[$__range]))/sum(count_over_time({cluster=~\"$k8s_cluster\",workload=~\"$application_name\"}  [$__range]))",
              "hide": true,
              "refId": "B"
            }
          ],
          "title": "Number of  Error Log Lines",
          "type": "stat"
        },
        {
          "datasource": {
            "type": "loki",
            "uid": "${DS_LOKI-PROD-RELEASE}"
          },
          "fieldConfig": {
            "defaults": {
              "color": {
                "mode": "palette-classic"
              },
              "custom": {
                "axisCenteredZero": false,
                "axisColorMode": "text",
                "axisLabel": "",
                "axisPlacement": "auto",
                "barAlignment": 0,
                "drawStyle": "line",
                "fillOpacity": 45,
                "gradientMode": "opacity",
                "hideFrom": {
                  "legend": false,
                  "tooltip": false,
                  "viz": false
                },
                "lineInterpolation": "smooth",
                "lineWidth": 1,
                "pointSize": 5,
                "scaleDistribution": {
                  "type": "linear"
                },
                "showPoints": "auto",
                "spanNulls": false,
                "stacking": {
                  "group": "A",
                  "mode": "none"
                },
                "thresholdsStyle": {
                  "mode": "off"
                }
              },
              "mappings": [],
              "thresholds": {
                "mode": "absolute",
                "steps": [
                  {
                    "color": "green",
                    "value": null
                  },
                  {
                    "color": "red",
                    "value": 80
                  }
                ]
              }
            },
            "overrides": []
          },
          "gridPos": {
            "h": 10,
            "w": 24,
            "x": 0,
            "y": 41
          },
          "id": 4,
          "options": {
            "legend": {
              "calcs": [],
              "displayMode": "list",
              "placement": "bottom",
              "showLegend": true
            },
            "tooltip": {
              "mode": "single",
              "sort": "none"
            }
          },
          "targets": [
            {
              "datasource": {
                "type": "loki",
                "uid": "${DS_LOKI-PROD-RELEASE}"
              },
              "expr": "sum(rate({cluster=~\"$cluster\",workload=~\"$workload\",pod=~\"$pod\",container=~\"$container\"} |~ \"(?i)$search\"[1m])) by (workload)",
              "legendFormat": "{{workload}}",
              "refId": "A"
            }
          ],
          "title": "Rate of Log generation[1m]",
          "type": "timeseries"
        }
      ],
      "targets": [
        {
          "datasource": {
            "type": "prometheus",
            "uid": "k1DFTi3Gz"
          },
          "refId": "A"
        }
      ],
      "title": "Log Count",
      "type": "row"
    }
  ],
  "refresh": false,
  "schemaVersion": 37,
  "style": "dark",
  "tags": [],
  "templating": {
    "list": [
      {
        "current": {
          "selected": false,
          "text": "Loki-prod-release",
          "value": "Loki-prod-release"
        },
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "datasource",
        "options": [],
        "query": "loki",
        "queryValue": "",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "type": "datasource"
      },
      {
        "current": {},
        "datasource": {
          "type": "loki",
          "uid": "${DS_LOKI-PROD-RELEASE}"
        },
        "definition": "label_values(cluster)",
        "hide": 0,
        "includeAll": false,
        "label": "Cluster",
        "multi": false,
        "name": "cluster",
        "options": [],
        "query": "label_values(cluster)",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "loki",
          "uid": "${DS_LOKI-PROD-RELEASE}"
        },
        "definition": "label_values({cluster=\"$cluster\"},workload)",
        "hide": 0,
        "includeAll": false,
        "multi": false,
        "name": "workload",
        "options": [],
        "query": "label_values({cluster=\"$cluster\"},workload)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "allValue": ".*",
        "current": {},
        "datasource": {
          "type": "loki",
          "uid": "${DS_LOKI-PROD-RELEASE}"
        },
        "definition": "label_values({cluster=\"$cluster\",workload=\"$workload\"},pod)",
        "hide": 0,
        "includeAll": true,
        "multi": true,
        "name": "pod",
        "options": [],
        "query": "label_values({cluster=\"$cluster\",workload=\"$workload\"},pod)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "loki",
          "uid": "${DS_LOKI-PROD-RELEASE}"
        },
        "definition": "label_values({cluster=\"$cluster\",workload=\"$workload\",pod=~\"$pod\"},container)",
        "hide": 0,
        "includeAll": true,
        "multi": true,
        "name": "container",
        "options": [],
        "query": "label_values({cluster=\"$cluster\",workload=\"$workload\",pod=~\"$pod\"},container)",
        "refresh": 2,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {
          "selected": true,
          "text": "",
          "value": ""
        },
        "hide": 0,
        "name": "search",
        "options": [
          {
            "selected": true,
            "text": "",
            "value": ""
          }
        ],
        "query": "",
        "skipUrlSync": false,
        "type": "textbox"
      }
    ]
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {
    "hidden": false,
    "refresh_intervals": [
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ]
  },
  "timezone": "browser",
  "title": "K8s Logs",
  "uid": "xuP1xv57k",
  "version": 63,
  "weekStart": "",
  "gnetId": 17161,
  "description": "This dashboard shows logs along with log generation rate, error and exception log rate and the amount of log generated with its rate in MB"
}