{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "description": "ktalk: логи сервисов, системные, docker, auth. Vector → OTel Collector → ClickHouse.",
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 2,
  "links": [],
  "panels": [
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "palette-classic"
          },
          "custom": {
            "axisBorderShow": false,
            "axisCenteredZero": false,
            "axisColorMode": "text",
            "axisLabel": "",
            "axisPlacement": "auto",
            "fillOpacity": 80,
            "gradientMode": "none",
            "hideFrom": {
              "legend": false,
              "tooltip": false,
              "viz": false
            },
            "lineWidth": 0,
            "scaleDistribution": {
              "type": "linear"
            },
            "thresholdsStyle": {
              "mode": "off"
            }
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "ERROR"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "red",
                  "mode": "fixed"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "WARN"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "orange",
                  "mode": "fixed"
                }
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "INFO"
            },
            "properties": [
              {
                "id": "color",
                "value": {
                  "fixedColor": "blue",
                  "mode": "fixed"
                }
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 6,
        "w": 24,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "barAlignment": 0,
        "barRadius": 0,
        "barWidth": 0.97,
        "fillOpacity": 80,
        "fullHighlight": false,
        "groupWidth": 0.7,
        "legend": {
          "calcs": [
            "sum"
          ],
          "displayMode": "list",
          "placement": "right",
          "showLegend": true
        },
        "orientation": "auto",
        "showValue": "auto",
        "stacking": {
          "group": "A",
          "mode": "normal"
        },
        "tooltip": {
          "hideZeros": false,
          "mode": "multi",
          "sort": "none"
        },
        "xTickLabelRotation": 0,
        "xTickLabelSpacing": 0
      },
      "pluginVersion": "12.3.1",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${datasource}"
          },
          "meta": {
            "builderOptions": {
              "queryType": "sql"
            }
          },
          "rawSql": "SELECT toStartOfInterval(Timestamp, INTERVAL $__interval_s SECOND) AS time, SeverityText AS level, count() AS value FROM `ktalk-logs`.logs WHERE $__timeFilter(Timestamp) AND $__conditionalAll(ServiceName IN (${service:singlequote}), $service) AND $__conditionalAll(ResourceAttributes['log.type'] IN (${log_type:singlequote}), $log_type) AND $__conditionalAll(ResourceAttributes['host.hostname'] IN (${host:singlequote}), $host) AND $__conditionalAll(ResourceAttributes['project'] IN (${project:singlequote}), $project) AND $__conditionalAll(ResourceAttributes['subproject'] IN (${subproject:singlequote}), $subproject) GROUP BY time, level ORDER BY time",
          "refId": "A"
        }
      ],
      "title": "Log Volume",
      "type": "barchart"
    },
    {
      "datasource": {
        "type": "grafana-clickhouse-datasource",
        "uid": "${datasource}"
      },
      "fieldConfig": {
        "defaults": {
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "footer": {
              "reducers": []
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": 0
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": [
          {
            "matcher": {
              "id": "byName",
              "options": "Timestamp"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 180
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Level"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Service"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 140
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Host"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 160
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Type"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 80
              }
            ]
          },
          {
            "matcher": {
              "id": "byName",
              "options": "Message"
            },
            "properties": [
              {
                "id": "custom.width",
                "value": 600
              }
            ]
          }
        ]
      },
      "gridPos": {
        "h": 16,
        "w": 24,
        "x": 0,
        "y": 6
      },
      "id": 2,
      "options": {
        "cellHeight": "sm",
        "enablePagination": true,
        "frameIndex": 0,
        "showHeader": true,
        "sortBy": [
          {
            "desc": true,
            "displayName": "Timestamp"
          }
        ]
      },
      "pluginVersion": "12.3.1",
      "targets": [
        {
          "datasource": {
            "type": "grafana-clickhouse-datasource",
            "uid": "${datasource}"
          },
          "meta": {
            "builderOptions": {
              "queryType": "sql"
            }
          },
          "rawSql": "SELECT Timestamp, SeverityText AS Level, ServiceName AS Service, ResourceAttributes['host.hostname'] AS Host, ResourceAttributes['log.type'] AS Type, Body AS Message FROM `ktalk-logs`.logs WHERE $__timeFilter(Timestamp) AND $__conditionalAll(ServiceName IN (${service:singlequote}), $service) AND $__conditionalAll(ResourceAttributes['log.type'] IN (${log_type:singlequote}), $log_type) AND $__conditionalAll(ResourceAttributes['host.hostname'] IN (${host:singlequote}), $host) AND $__conditionalAll(ResourceAttributes['project'] IN (${project:singlequote}), $project) AND $__conditionalAll(ResourceAttributes['subproject'] IN (${subproject:singlequote}), $subproject) AND ('${search}' = '' OR Body ILIKE concat('%', '${search}', '%')) ORDER BY Timestamp DESC LIMIT 500",
          "refId": "A"
        }
      ],
      "title": "Log Records",
      "type": "table"
    }
  ],
  "preload": false,
  "refresh": "30s",
  "schemaVersion": 42,
  "tags": [
    "monitoring",
    "logs",
    "vector"
  ],
  "templating": {
    "list": [
      {
        "current": {
          "text": "ClickHouse Logs",
          "value": "P66BE7379BCB99AA8"
        },
        "label": "Datasource",
        "name": "datasource",
        "options": [],
        "query": "grafana-clickhouse-datasource",
        "refresh": 1,
        "regex": "/ClickHouse Logs.*/",
        "type": "datasource"
      },
      {
        "current": {
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${datasource}"
        },
        "definition": "SELECT DISTINCT ServiceName FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "includeAll": true,
        "label": "Service",
        "multi": true,
        "name": "service",
        "options": [],
        "query": "SELECT DISTINCT ServiceName FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "refresh": 2,
        "sort": 1,
        "type": "query"
      },
      {
        "current": {
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${datasource}"
        },
        "definition": "SELECT DISTINCT ResourceAttributes['log.type'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "includeAll": true,
        "label": "Log Type",
        "multi": true,
        "name": "log_type",
        "options": [],
        "query": "SELECT DISTINCT ResourceAttributes['log.type'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "refresh": 2,
        "sort": 1,
        "type": "query"
      },
      {
        "current": {
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${datasource}"
        },
        "definition": "SELECT DISTINCT ResourceAttributes['host.hostname'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "includeAll": true,
        "label": "Host",
        "multi": true,
        "name": "host",
        "options": [],
        "query": "SELECT DISTINCT ResourceAttributes['host.hostname'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY ORDER BY 1",
        "refresh": 2,
        "sort": 1,
        "type": "query"
      },
      {
        "current": {
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${datasource}"
        },
        "definition": "SELECT DISTINCT ResourceAttributes['project'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY AND ResourceAttributes['project'] != '' ORDER BY 1",
        "includeAll": true,
        "label": "Project",
        "multi": true,
        "name": "project",
        "options": [],
        "query": "SELECT DISTINCT ResourceAttributes['project'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY AND ResourceAttributes['project'] != '' ORDER BY 1",
        "refresh": 2,
        "sort": 1,
        "type": "query"
      },
      {
        "current": {
          "text": [
            "All"
          ],
          "value": [
            "$__all"
          ]
        },
        "datasource": {
          "type": "grafana-clickhouse-datasource",
          "uid": "${datasource}"
        },
        "definition": "SELECT DISTINCT ResourceAttributes['subproject'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY AND ResourceAttributes['subproject'] != '' ORDER BY 1",
        "includeAll": true,
        "label": "Subproject",
        "multi": true,
        "name": "subproject",
        "options": [],
        "query": "SELECT DISTINCT ResourceAttributes['subproject'] FROM `ktalk-logs`.logs WHERE Timestamp >= now() - INTERVAL 1 DAY AND ResourceAttributes['subproject'] != '' ORDER BY 1",
        "refresh": 2,
        "sort": 1,
        "type": "query"
      },
      {
        "current": {
          "text": "",
          "value": ""
        },
        "label": "Search",
        "name": "search",
        "options": [
          {
            "selected": true,
            "text": "",
            "value": ""
          }
        ],
        "query": "",
        "type": "textbox"
      }
    ]
  },
  "time": {
    "from": "now-1h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "browser",
  "title": "KTalk Logs",
  "uid": "ktalk-logs",
  "version": 1
}
