{
  "annotations": { "list": [] },
  "editable": true,
  "graphTooltip": 1,
  "schemaVersion": 39,
  "tags": ["central-logging"],
  "title": "Central Logs — přehled",
  "uid": "central-logs",
  "time": { "from": "now-24h", "to": "now" },
  "refresh": "30s",
  "templating": {
    "list": [
      {
        "name": "env",
        "label": "Prostředí",
        "type": "query",
        "datasource": { "type": "loki", "uid": "loki" },
        "query": "label_values(env)",
        "refresh": 2,
        "includeAll": true,
        "allValue": ".+",
        "multi": true,
        "current": { "text": "All", "value": "$__all" }
      },
      {
        "name": "app",
        "label": "Skript (app)",
        "type": "query",
        "datasource": { "type": "loki", "uid": "loki" },
        "query": "label_values({env=~\"$env\"}, app)",
        "refresh": 2,
        "includeAll": true,
        "allValue": ".+",
        "multi": true,
        "current": { "text": "All", "value": "$__all" }
      },
      {
        "name": "level",
        "label": "Úroveň",
        "type": "custom",
        "query": "DEBUG,INFO,WARNING,ERROR,CRITICAL",
        "includeAll": true,
        "allValue": ".+",
        "multi": true,
        "current": { "text": "All", "value": "$__all" }
      },
      {
        "name": "search",
        "label": "Hledat v textu",
        "type": "textbox",
        "current": { "text": "", "value": "" }
      }
    ]
  },
  "panels": [
    {
      "id": 1,
      "type": "stat",
      "title": "Logů celkem (rozsah)",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 4, "w": 8, "x": 0, "y": 0 },
      "options": { "colorMode": "value", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "sum(count_over_time({app=~\"$app\", env=~\"$env\", level=~\"$level\"} |~ \"(?i)$search\" [$__range]))",
          "queryType": "instant"
        }
      ]
    },
    {
      "id": 2,
      "type": "stat",
      "title": "Chyby (ERROR+CRITICAL, rozsah)",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 4, "w": 8, "x": 8, "y": 0 },
      "fieldConfig": {
        "defaults": {
          "color": { "mode": "thresholds" },
          "thresholds": { "mode": "absolute", "steps": [
            { "color": "green", "value": null },
            { "color": "red", "value": 1 }
          ] }
        }
      },
      "options": { "colorMode": "background", "graphMode": "area", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "sum(count_over_time({app=~\"$app\", env=~\"$env\", level=~\"ERROR|CRITICAL\"} |~ \"(?i)$search\" [$__range]))",
          "queryType": "instant"
        }
      ]
    },
    {
      "id": 3,
      "type": "stat",
      "title": "Aktivních skriptů",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 4, "w": 8, "x": 16, "y": 0 },
      "options": { "colorMode": "value", "graphMode": "none", "reduceOptions": { "calcs": ["lastNotNull"] } },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "count(sum by (app) (count_over_time({env=~\"$env\"} [$__range])))",
          "queryType": "instant"
        }
      ]
    },
    {
      "id": 4,
      "type": "timeseries",
      "title": "Tok logů podle úrovně",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 8, "w": 12, "x": 0, "y": 4 },
      "fieldConfig": { "defaults": { "custom": { "drawStyle": "bars", "fillOpacity": 60, "stacking": { "mode": "normal" } } } },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "sum by (level) (count_over_time({app=~\"$app\", env=~\"$env\", level=~\"$level\"} |~ \"(?i)$search\" [$__interval]))",
          "legendFormat": "{{level}}"
        }
      ]
    },
    {
      "id": 5,
      "type": "timeseries",
      "title": "Chyby podle skriptu",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 8, "w": 12, "x": 12, "y": 4 },
      "fieldConfig": { "defaults": { "custom": { "drawStyle": "bars", "fillOpacity": 70, "stacking": { "mode": "normal" } } } },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "sum by (app) (count_over_time({app=~\"$app\", env=~\"$env\", level=~\"ERROR|CRITICAL\"} |~ \"(?i)$search\" [$__interval]))",
          "legendFormat": "{{app}}"
        }
      ]
    },
    {
      "id": 6,
      "type": "logs",
      "title": "Poslední logy",
      "datasource": { "type": "loki", "uid": "loki" },
      "gridPos": { "h": 14, "w": 24, "x": 0, "y": 12 },
      "options": {
        "showTime": true,
        "showLabels": false,
        "showCommonLabels": false,
        "wrapLogMessage": true,
        "prettifyLogMessage": true,
        "enableLogDetails": true,
        "dedupStrategy": "none",
        "sortOrder": "Descending"
      },
      "targets": [
        {
          "refId": "A",
          "datasource": { "type": "loki", "uid": "loki" },
          "expr": "{app=~\"$app\", env=~\"$env\", level=~\"$level\"} |~ \"(?i)$search\" | json",
          "maxLines": 1000
        }
      ]
    }
  ]
}
