Grafana dashboard: Apache Logs and Metrics
Description: Visualize apache logs.

Revamped Apache Logs dashboard, which was originally created by Nicolas Zachow (ID 968).

The original one was not working on my setup, so I reworked it.

Telegraf config:


[[outputs.influxdb]]

  database = "my_metrics_database"


[[inputs.tail]]

  files = ["/var/log/apache2/access.log", "/var/log/apache2/error.log"]

  data_format = "grok"

  grok_patterns = ["%{COMBINED_LOG_FORMAT}"]

  from_beginning = true

{
  "__inputs": [
    {
      "name": "DS_INFLUX",
      "label": "Influx",
      "description": "",
      "type": "datasource",
      "pluginId": "influxdb",
      "pluginName": "InfluxDB"
    }
  ],
  "__elements": {},
  "__requires": [
    {
      "type": "panel",
      "id": "barchart",
      "name": "Bar chart",
      "version": ""
    },
    {
      "type": "panel",
      "id": "bargauge",
      "name": "Bar gauge",
      "version": ""
    },
    {
      "type": "grafana",
      "id": "grafana",
      "name": "Grafana",
      "version": "9.4.7"
    },
    {
      "type": "datasource",
      "id": "influxdb",
      "name": "InfluxDB",
      "version": "1.0.0"
    },
    {
      "type": "panel",
      "id": "stat",
      "name": "Stat",
      "version": ""
    },
    {
      "type": "panel",
      "id": "table",
      "name": "Table",
      "version": ""
    }
  ],
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "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"
      }
    ]
  },
  "description": "Visualize apache logs.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "gnetId": 18527,
  "graphTooltip": 0,
  "id": null,
  "links": [],
  "liveNow": false,
  "panels": [
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "N/A"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "short"
        },
        "overrides": []
      },
      "id": 5,
      "links": [],
      "maxDataPoints": 100,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "dsType": "influxdb",
          "groupBy": [
            {
              "params": [
                "$interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "policy": "default",
          "query": "SELECT count(\"request\") \nFROM \"tail\" \nWHERE \"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/ AND \"request\" !~ /\\/server-status/ \nAND $timeFilter ",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "Code $code responses",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "N/A"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 3,
        "w": 6,
        "x": 6,
        "y": 0
      },
      "id": 6,
      "links": [],
      "maxDataPoints": 100,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "dsType": "influxdb",
          "groupBy": [
            {
              "params": [
                "$interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "policy": "default",
          "query": "SELECT mean(\"resp_bytes\") FROM \"tail\" WHERE \"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/ AND \"request\" !~ /\\/server-status/ AND $timeFilter ",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "Response average size",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "N/A"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 3,
        "w": 6,
        "x": 12,
        "y": 0
      },
      "id": 8,
      "links": [],
      "maxDataPoints": 100,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "dsType": "influxdb",
          "groupBy": [
            {
              "params": [
                "$interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "policy": "default",
          "query": "SELECT percentile(\"resp_bytes\",99) FROM \"tail\" WHERE \"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/  AND \"request\" !~ /\\/server-status/ AND $timeFilter ",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "99 percentile size",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [
            {
              "options": {
                "match": "null",
                "result": {
                  "text": "N/A"
                }
              },
              "type": "special"
            }
          ],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          },
          "unit": "bytes"
        },
        "overrides": []
      },
      "gridPos": {
        "h": 3,
        "w": 6,
        "x": 18,
        "y": 0
      },
      "id": 7,
      "links": [],
      "maxDataPoints": 100,
      "options": {
        "colorMode": "none",
        "graphMode": "none",
        "justifyMode": "auto",
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "mean"
          ],
          "fields": "",
          "values": false
        },
        "textMode": "auto"
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "dsType": "influxdb",
          "groupBy": [
            {
              "params": [
                "$interval"
              ],
              "type": "time"
            },
            {
              "params": [
                "null"
              ],
              "type": "fill"
            }
          ],
          "policy": "default",
          "query": "SELECT max(\"resp_bytes\") FROM \"tail\" WHERE \"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/  AND \"request\" !~ /\\/server-status/ AND $timeFilter",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "time_series",
          "select": [
            [
              {
                "params": [
                  "value"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "mean"
              }
            ]
          ],
          "tags": []
        }
      ],
      "title": "Max response size",
      "type": "stat"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "fillOpacity": 80,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineWidth": 1,
            "scaleDistribution": {
              "type": "linear"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "orange",
                "value": 1000
              },
              {
                "color": "dark-red",
                "value": 3000
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "resp_code"
            },
            "properties": [
              {
                "id": "mappings",
                "value": [
                  {
                    "options": {
                      "pattern": "2.+",
                      "result": {
                        "color": "green",
                        "index": 0
                      }
                    },
                    "type": "regex"
                  },
                  {
                    "options": {
                      "pattern": "4.+",
                      "result": {
                        "color": "light-orange",
                        "index": 1
                      }
                    },
                    "type": "regex"
                  },
                  {
                    "options": {
                      "pattern": "5.+",
                      "result": {
                        "color": "dark-red",
                        "index": 2
                      }
                    },
                    "type": "regex"
                  },
                  {
                    "options": {
                      "pattern": "3.+",
                      "result": {
                        "color": "light-purple",
                        "index": 3
                      }
                    },
                    "type": "regex"
                  }
                ]
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 3
      },
      "id": 11,
      "options": {
        "barRadius": 0.05,
        "barWidth": 0.7,
        "colorByField": "resp_code",
        "fullHighlight": false,
        "groupWidth": 0.7,
        "legend": {
          "calcs": [],
          "displayMode": "list",
          "placement": "bottom",
          "showLegend": false
        },
        "orientation": "auto",
        "showValue": "auto",
        "stacking": "none",
        "tooltip": {
          "mode": "single",
          "sort": "asc"
        },
        "xTickLabelRotation": 0,
        "xTickLabelSpacing": 0
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "alias": "",
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "groupBy": [
            {
              "params": [
                "resp_code"
              ],
              "type": "tag"
            }
          ],
          "measurement": "tail",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT count(agent) as total \nFROM \"tail\" \nWHERE (\"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/ AND \"request\" !~ /\\/server-status/) \nAND $timeFilter GROUP BY resp_code",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "agent"
                ],
                "type": "field"
              },
              {
                "params": [],
                "type": "count"
              }
            ]
          ],
          "tags": [
            {
              "key": "host",
              "operator": "=~",
              "value": "/^$server$/"
            },
            {
              "condition": "AND",
              "key": "resp_code",
              "operator": "=~",
              "value": "/^$code$/"
            }
          ]
        }
      ],
      "title": "Status Code Distribution",
      "transformations": [
        {
          "id": "convertFieldType",
          "options": {
            "conversions": [
              {
                "destinationType": "string",
                "targetField": "resp_code"
              }
            ],
            "fields": {}
          }
        }
      ],
      "type": "barchart"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "orange",
                "value": 1000
              },
              {
                "color": "dark-red",
                "value": 3000
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "verb"
            },
            "properties": []
          }
        ]
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 12,
        "y": 3
      },
      "id": 10,
      "options": {
        "displayMode": "gradient",
        "minVizHeight": 5,
        "minVizWidth": 0,
        "orientation": "horizontal",
        "reduceOptions": {
          "calcs": [
            "sum"
          ],
          "fields": "",
          "limit": 10,
          "values": true
        },
        "showUnfilled": true,
        "text": {
          "valueSize": 25
        }
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "alias": "total",
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "groupBy": [
            {
              "params": [
                "verb"
              ],
              "type": "tag"
            }
          ],
          "measurement": "tail",
          "orderByTime": "ASC",
          "policy": "default",
          "query": "SELECT count(agent) as total FROM \"tail\" WHERE (\"host\" =~ /^$server$/ AND \"resp_code\" =~ /^$code$/ AND verb =~ /$verb$/ AND \"request\" !~ /\\/server-status/) AND $timeFilter GROUP BY \"verb\"",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table",
          "select": [
            [
              {
                "params": [
                  "agent"
                ],
                "type": "field"
              }
            ]
          ],
          "tags": [
            {
              "key": "host",
              "operator": "=~",
              "value": "/^$server$/"
            },
            {
              "condition": "AND",
              "key": "resp_code",
              "operator": "=~",
              "value": "/^$code$/"
            }
          ]
        }
      ],
      "title": "Verb Request Distribution",
      "type": "bargauge"
    },
    {
      "datasource": {
        "type": "influxdb",
        "uid": "${DS_INFLUX}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "fixed"
          },
          "custom": {
            "align": "left",
            "cellOptions": {
              "type": "color-text"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "light-purple",
                "value": 300
              },
              {
                "color": "light-orange",
                "value": 400
              },
              {
                "color": "semi-dark-red",
                "value": 500
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Time"
            },
            "properties": [
              {
                "id": "unit",
                "value": "time: YYYY-MM-DD HH:mm:ss"
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Response"
            },
            "properties": [
              {
                "id": "custom.align",
                "value": "center"
              },
              {
                "id": "color",
                "value": {
                  "mode": "thresholds"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 19,
        "w": 24,
        "x": 0,
        "y": 11
      },
      "id": 4,
      "links": [],
      "options": {
        "footer": {
          "countRows": false,
          "enablePagination": true,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "9.4.7",
      "targets": [
        {
          "datasource": {
            "type": "influxdb",
            "uid": "${DS_INFLUX}"
          },
          "query": "SELECT  client_ip as Client, agent as Agent, referrer as Referer, request as Request, resp_code as Response, verb as Verb, http_version as \"HTTP Version\" \nFROM \"tail\" \nWHERE host =~ /$server$/ AND resp_code =~ /$code$/ AND verb =~ /$verb$/ AND \n$timeFilter AND \"request\" !~ /\\/server-status/ fill(null)",
          "rawQuery": true,
          "refId": "A",
          "resultFormat": "table"
        }
      ],
      "title": "Apache Logs",
      "transformations": [
        {
          "id": "convertFieldType",
          "options": {
            "conversions": [],
            "fields": {}
          }
        },
        {
          "id": "merge",
          "options": {
            "reducers": []
          }
        }
      ],
      "type": "table"
    }
  ],
  "refresh": "1m",
  "revision": 1,
  "schemaVersion": 38,
  "style": "dark",
  "tags": [
    "Apache2",
    "Logs"
  ],
  "templating": {
    "list": [
      {
        "current": {},
        "datasource": {
          "type": "influxdb",
          "uid": "${DS_INFLUX}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": false,
        "label": "Server",
        "multi": false,
        "name": "server",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"host\" where \"resp_code\" =~ /./",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "current": {},
        "datasource": {
          "type": "influxdb",
          "uid": "${DS_INFLUX}"
        },
        "definition": "",
        "hide": 0,
        "includeAll": true,
        "label": "Response code",
        "multi": true,
        "name": "code",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"resp_code\" where host =~ /^$server$/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      },
      {
        "allValue": "",
        "current": {},
        "datasource": {
          "type": "influxdb",
          "uid": "${DS_INFLUX}"
        },
        "definition": "SHOW TAG VALUES WITH KEY = \"verb\" where host =~ /^$server$/ and resp_code =~ /^$code$/",
        "hide": 0,
        "includeAll": true,
        "label": "Verb",
        "multi": true,
        "name": "verb",
        "options": [],
        "query": "SHOW TAG VALUES WITH KEY = \"verb\" where host =~ /^$server$/ and resp_code =~ /^$code$/",
        "refresh": 1,
        "regex": "",
        "skipUrlSync": false,
        "sort": 0,
        "type": "query"
      }
    ]
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {
    "refresh_intervals": [
      "5s",
      "10s",
      "30s",
      "1m",
      "5m",
      "15m",
      "30m",
      "1h",
      "2h",
      "1d"
    ],
    "time_options": [
      "5m",
      "15m",
      "1h",
      "6h",
      "12h",
      "24h",
      "2d",
      "7d",
      "30d"
    ]
  },
  "timezone": "browser",
  "title": "Apache Logs and Metrics",
  "uid": "3IaDF3zRz",
  "version": 75,
  "weekStart": ""
}