From 9871ba73ef0c2a6a3337974543688d2d772271d0 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 11:29:29 +0300 Subject: [PATCH 1/6] replace migrator & add local domain --- .env | 4 ++++ Makefile | 16 ++++++++++++++-- docker-compose.yml | 11 ++++++++--- files/Dockerfile.migrator | 3 +++ .../1698135711_create_logs_table.down.sql | 1 - ...35711_create_logs_table.up.sql => 1_init.sql} | 0 6 files changed, 29 insertions(+), 6 deletions(-) create mode 100644 .env create mode 100644 files/Dockerfile.migrator delete mode 100644 files/migrations/1698135711_create_logs_table.down.sql rename files/migrations/{1698135711_create_logs_table.up.sql => 1_init.sql} (100%) diff --git a/.env b/.env new file mode 100644 index 0000000..03ba094 --- /dev/null +++ b/.env @@ -0,0 +1,4 @@ +CLICKHOUSE_USER=default +CLICKHOUSE_PASSWORD=default +CLICKHOUSE_DB=default +CLICKHOUSE_PORT=8123 diff --git a/Makefile b/Makefile index c57a52c..aeb8bc8 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,24 @@ +include .env SHELL = /bin/bash -o pipefail ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) -MIGRATIONS_DIR=$(SRC_DIR)/files/migrations +MIGRATIONS_DIR=$(ROOT_DIR)/files/migrations + +all: migrator migrate up + +migrator: + @docker buildx build --tag neur0toxine/clickhouse-migrations:latest -f $(ROOT_DIR)/files/Dockerfile.migrator $(ROOT_DIR)/files migrate: @docker-compose up -d - @docker run -v $(MIGRATIONS_DIR):/migrations --network host migrate/migrate -path=/migrations/ -database "clickhouse://localhost:8123?username=default&password=default&database=default" up all + @docker run -v $(MIGRATIONS_DIR):/migrations --network host neur0toxine/clickhouse-migrations:latest migrate --host=http://localhost:$(CLICKHOUSE_PORT) --user=$(CLICKHOUSE_USER) --password=$(CLICKHOUSE_PASSWORD) --db=default --migrations-home=/migrations @docker-compose stop up: @docker-compose up + +stop: + @docker-compose stop + +down: + @docker-compose down -v diff --git a/docker-compose.yml b/docker-compose.yml index 5131ab6..07d436e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,13 +7,18 @@ services: - grafana_data:/var/lib/grafana ports: - '3000:3000' + labels: + traefik.enable: "true" + traefik.http.routers.grafana.entrypoints: web + traefik.http.routers.grafana.rule: "Host(`grafana.test`)" + traefik.http.services.grafana.loadbalancer.server.port: "3000" clickhouse: image: docker.io/bitnami/clickhouse:23 environment: - - CLICKHOUSE_ADMIN_USER=default - - CLICKHOUSE_ADMIN_PASSWORD=default + - CLICKHOUSE_ADMIN_USER=${CLICKHOUSE_USER} + - CLICKHOUSE_ADMIN_PASSWORD=${CLICKHOUSE_PASSWORD} ports: - - '8123:8123' + - '${CLICKHOUSE_PORT}:8123' volumes: - clickhouse_data:/bitnami/clickhouse vector: diff --git a/files/Dockerfile.migrator b/files/Dockerfile.migrator new file mode 100644 index 0000000..3d43416 --- /dev/null +++ b/files/Dockerfile.migrator @@ -0,0 +1,3 @@ +FROM node:lts-alpine +RUN npm install --global clickhouse-migrations && npm cache clean --force +ENTRYPOINT ["/usr/local/bin/clickhouse-migrations"] \ No newline at end of file diff --git a/files/migrations/1698135711_create_logs_table.down.sql b/files/migrations/1698135711_create_logs_table.down.sql deleted file mode 100644 index b1c111a..0000000 --- a/files/migrations/1698135711_create_logs_table.down.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE log_docker_raw; \ No newline at end of file diff --git a/files/migrations/1698135711_create_logs_table.up.sql b/files/migrations/1_init.sql similarity index 100% rename from files/migrations/1698135711_create_logs_table.up.sql rename to files/migrations/1_init.sql From 8d9149d6cabf113c4b268c73534d4b49b5ace3fb Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 11:41:19 +0300 Subject: [PATCH 2/6] migrate to yaml config --- docker-compose.yml | 2 +- files/vector.yaml | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 files/vector.yaml diff --git a/docker-compose.yml b/docker-compose.yml index 07d436e..839f14b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,7 +27,7 @@ services: - '8686:8686' volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - - ./files/vector.toml:/etc/vector/vector.toml:ro + - ./files/vector.yaml:/etc/vector/vector.yaml:ro volumes: clickhouse_data: diff --git a/files/vector.yaml b/files/vector.yaml new file mode 100644 index 0000000..3d4feb4 --- /dev/null +++ b/files/vector.yaml @@ -0,0 +1,43 @@ +api: + enabled: true + address: '0.0.0.0:8686' +sources: + docker: + type: docker_logs + exclude_containers: + - clickhouse + - grafana + - vector +transforms: + ts_and_program: + type: remap + inputs: + - docker + source: |2 + .logdatetime = to_unix_timestamp(now()) + .program = .container_name + emptyprogram: + type: filter + inputs: + - ts_and_program + condition: + type: vrl + source: |2 + .program != "" + dedupe: + type: dedupe + inputs: + - emptyprogram +sinks: + clickhouse: + type: clickhouse + inputs: + - dedupe + compression: gzip + endpoint: 'http://clickhouse:8123' + auth: + strategy: basic + user: default + password: default + database: default + table: log_docker_raw From 94217108cebbeb6356235a8b42161098e5d13563 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 11:41:34 +0300 Subject: [PATCH 3/6] remove toml config --- files/vector.toml | 38 -------------------------------------- 1 file changed, 38 deletions(-) delete mode 100644 files/vector.toml diff --git a/files/vector.toml b/files/vector.toml deleted file mode 100644 index a53054a..0000000 --- a/files/vector.toml +++ /dev/null @@ -1,38 +0,0 @@ -[api] -enabled = true -address = "0.0.0.0:8686" - -[sources.docker] -type = "docker_logs" -exclude_containers = [ "clickhouse", "grafana", "vector" ] - -[transforms.ts_and_program] -type = "remap" -inputs = [ "docker" ] -source = ''' - .logdatetime = to_unix_timestamp(now()) - .program = .container_name -''' - -[transforms.emptyprogram] -type = "filter" -inputs = [ "ts_and_program" ] -condition.type = "vrl" -condition.source = ''' - .program != "" -''' - -[transforms.dedupe] -type = "dedupe" -inputs = [ "emptyprogram" ] - -[sinks.clickhouse] -type = "clickhouse" -inputs = [ "dedupe"] -compression = "gzip" -endpoint = "http://clickhouse:8123" -auth.strategy = "basic" -auth.user = "default" -auth.password = "default" -database = "default" -table = "log_docker_raw" \ No newline at end of file From c56388638256f41cb4a72e03ef2725061a5e3ffe Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 12:53:24 +0300 Subject: [PATCH 4/6] update readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5f27228..9ccae69 100644 --- a/README.md +++ b/README.md @@ -8,8 +8,8 @@ This demo project can aggregate logs from Docker containers and store them in Cl Obviously, you'll need Docker: -1. `make migrate` (you can totally use `clickhouse-client` inside container if migrator hangs up). -2. Navigate to `http://localhost:3000`, use `admin:admin` as credentials. -3. Create your own dashboard or import those I provided (`dashboards/` directory). +1. `make all` +2. Navigate to `http://grafana.test` or `http://localhost:3000`, use `admin:admin` as credentials. +3. Create your own dashboard or import those I provided (`dashboards/` directory). Replace data source UUID with correct one if needed. 4. Run any Docker project with structured JSON logs. -5. Done. \ No newline at end of file +5. Done. From 4c014604cec43573dba45b4e2d919b456b222c52 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Wed, 15 Nov 2023 15:34:53 +0300 Subject: [PATCH 5/6] fix error graph --- dashboards/Logs + Structured via Query.json | 110 ++++++++++++++++---- 1 file changed, 87 insertions(+), 23 deletions(-) diff --git a/dashboards/Logs + Structured via Query.json b/dashboards/Logs + Structured via Query.json index 8479a28..e011654 100644 --- a/dashboards/Logs + Structured via Query.json +++ b/dashboards/Logs + Structured via Query.json @@ -18,7 +18,7 @@ "editable": true, "fiscalYearStartMonth": 0, "graphTooltip": 0, - "id": 3, + "id": 1, "links": [], "liveNow": false, "panels": [ @@ -38,7 +38,7 @@ { "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "description": "", "fieldConfig": { @@ -47,6 +47,7 @@ "mode": "palette-classic" }, "custom": { + "axisBorderShow": false, "axisCenteredZero": false, "axisColorMode": "series", "axisLabel": "", @@ -156,6 +157,22 @@ "operator": "LIKE", "type": "String", "value": "$filter1" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter2" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter3" } ], "limit": 5000, @@ -174,10 +191,10 @@ }, "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "queryType": "builder", - "rawSql": "SELECT $__timeInterval(logdatetime) as time, count() FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( program = ${program:singlequote} ) AND ( message LIKE '%$filter1%' ) GROUP BY time ORDER BY time ASC LIMIT 5000", + "rawSql": "SELECT $__timeInterval(logdatetime) as time, count() FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( program = ${program:singlequote} ) AND ( message LIKE '%$filter1%' ) AND ( message LIKE '%$filter2%' ) AND ( message LIKE '%$filter3%' ) GROUP BY time ORDER BY time ASC LIMIT 5000", "refId": "A" } ], @@ -187,14 +204,16 @@ { "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "fieldConfig": { "defaults": { "color": { - "mode": "palette-classic" + "fixedColor": "red", + "mode": "fixed" }, "custom": { + "axisBorderShow": false, "axisCenteredZero": false, "axisColorMode": "text", "axisLabel": "", @@ -229,13 +248,9 @@ "thresholds": { "mode": "absolute", "steps": [ - { - "color": "green", - "value": null - }, { "color": "red", - "value": 80 + "value": null } ] } @@ -311,11 +326,61 @@ }, "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, - "queryType": "builder", - "rawSql": "SELECT $__timeInterval(logdatetime) as time FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( priority = 'error' ) AND ( message LIKE '%$filter1%' ) GROUP BY time ORDER BY time ASC LIMIT 5000", - "refId": "A" + "format": 1, + "meta": { + "builderOptions": { + "database": "default", + "fields": [ + "priority" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "restrictToFields": [ + { + "label": "logdatetime", + "name": "logdatetime", + "picklistValues": [], + "type": "DateTime" + } + ], + "type": "datetime" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "priority", + "operator": "=", + "type": "String", + "value": "error" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter1" + } + ], + "limit": 5000, + "metrics": [], + "mode": "trend", + "orderBy": [], + "table": "log_docker_raw", + "timeField": "logdatetime", + "timeFieldType": "DateTime" + } + }, + "queryType": "sql", + "rawSql": "SELECT $__timeInterval(logdatetime) as time, count() FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( visitParamExtractString(message, 'level') = 'ERROR' ) AND ( program = ${program:singlequote} ) AND ( message LIKE '%$filter1%' ) AND ( message LIKE '%$filter2%' ) AND ( message LIKE '%$filter3%' ) GROUP BY time ORDER BY time ASC LIMIT 5000\n\n", + "refId": "A", + "selectedFormat": 4 } ], "title": "Total errors", @@ -337,7 +402,7 @@ { "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "fieldConfig": { "defaults": { @@ -622,7 +687,7 @@ "showHeader": true, "sortBy": [] }, - "pluginVersion": "10.1.5", + "pluginVersion": "10.2.1", "targets": [ { "builderOptions": { @@ -674,7 +739,7 @@ }, "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "format": 1, "meta": { @@ -766,7 +831,7 @@ { "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "fieldConfig": { "defaults": { @@ -936,7 +1001,7 @@ }, "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "format": 1, "meta": { @@ -962,7 +1027,6 @@ ], "refresh": "", "schemaVersion": 38, - "style": "dark", "tags": [], "templating": { "list": [ @@ -974,7 +1038,7 @@ }, "datasource": { "type": "grafana-clickhouse-datasource", - "uid": "f70e773b-26c3-4b74-9a45-291fab27524b" + "uid": "ef7b4f5b-7011-411b-88c2-4b2681b8ddbe" }, "definition": "SELECT DISTINCT program FROM default.log_docker_raw WHERE logdatetime > now() - interval 6 hours;", "hide": 0, @@ -1085,6 +1149,6 @@ "timezone": "", "title": "Logs + Structured via Query", "uid": "b445eb43-25d1-4112-b628-3b8acf037f10", - "version": 8, + "version": 6, "weekStart": "" } \ No newline at end of file From 3a8a0fb79830bac9077656b29df3c50ef2e26298 Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Sun, 28 Jan 2024 17:53:56 +0300 Subject: [PATCH 6/6] zaplog --- .../Logs + Structured via Query (zaplog).json | 1063 +++++++++++++++++ 1 file changed, 1063 insertions(+) create mode 100644 dashboards/Logs + Structured via Query (zaplog).json diff --git a/dashboards/Logs + Structured via Query (zaplog).json b/dashboards/Logs + Structured via Query (zaplog).json new file mode 100644 index 0000000..1f67cf0 --- /dev/null +++ b/dashboards/Logs + Structured via Query (zaplog).json @@ -0,0 +1,1063 @@ +{ + "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": 1, + "links": [], + "liveNow": false, + "panels": [ + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 3, + "panels": [], + "title": "Total & Errors", + "type": "row" + }, + { + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "description": "", + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "series", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "hue", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": 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 + } + ] + }, + "unit": "recps", + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 1 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "timezone": [ + "Europe/Moscow" + ], + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "builderOptions": { + "database": "default", + "fields": [ + "priority", + "logdatetime" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "restrictToFields": [ + { + "label": "logdatetime", + "name": "logdatetime", + "picklistValues": [], + "type": "DateTime" + } + ], + "type": "datetime" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "program", + "operator": "=", + "type": "String", + "value": "${program:singlequote}" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter1" + } + ], + "limit": 5000, + "metrics": [ + { + "aggregation": "count", + "alias": "", + "field": "" + } + ], + "mode": "trend", + "orderBy": [], + "table": "log_docker_raw", + "timeField": "logdatetime", + "timeFieldType": "DateTime" + }, + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "queryType": "builder", + "rawSql": "SELECT $__timeInterval(logdatetime) as time, count() FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( program = ${program:singlequote} ) AND ( message LIKE '%$filter1%' ) GROUP BY time ORDER BY time ASC LIMIT 5000", + "refId": "A" + } + ], + "title": "Total messages", + "type": "timeseries" + }, + { + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": 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 + } + ] + }, + "unitScale": true + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 1 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "targets": [ + { + "builderOptions": { + "database": "default", + "fields": [ + "priority" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "restrictToFields": [ + { + "label": "logdatetime", + "name": "logdatetime", + "picklistValues": [], + "type": "DateTime" + } + ], + "type": "datetime" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "priority", + "operator": "=", + "type": "String", + "value": "error" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter1" + } + ], + "limit": 5000, + "metrics": [], + "mode": "trend", + "orderBy": [], + "table": "log_docker_raw", + "timeField": "logdatetime", + "timeFieldType": "DateTime" + }, + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "queryType": "builder", + "rawSql": "SELECT $__timeInterval(logdatetime) as time FROM \"default\".\"log_docker_raw\" WHERE $__timeFilter(logdatetime) AND ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( priority = 'error' ) AND ( message LIKE '%$filter1%' ) GROUP BY time ORDER BY time ASC LIMIT 5000", + "refId": "A" + } + ], + "title": "Total errors", + "type": "timeseries" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 9 + }, + "id": 6, + "panels": [], + "title": "Structured logs", + "type": "row" + }, + { + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "continuous-GrYlRd" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "displayName": "Priority", + "mappings": [ + { + "options": { + "DEBUG": { + "color": "dark-green", + "index": 0 + }, + "ERROR": { + "color": "dark-red", + "index": 3 + }, + "INFO": { + "color": "dark-blue", + "index": 1 + }, + "WARN": { + "color": "dark-yellow", + "index": 2 + } + }, + "type": "value" + } + ], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + } + ] + }, + "unit": "string", + "unitScale": true + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "logdatetime" + }, + "properties": [ + { + "id": "custom.width", + "value": 196 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "host" + }, + "properties": [ + { + "id": "custom.width", + "value": 132 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "program" + }, + "properties": [ + { + "id": "custom.width", + "value": 210 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "priority" + }, + "properties": [ + { + "id": "custom.width", + "value": 71 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "time" + }, + "properties": [ + { + "id": "custom.width", + "value": 266 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "level" + }, + "properties": [ + { + "id": "custom.width", + "value": 80 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "handler" + }, + "properties": [ + { + "id": "custom.width", + "value": 217 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "msg" + }, + "properties": [ + { + "id": "custom.width", + "value": 1307 + }, + { + "id": "custom.inspect", + "value": true + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Message" + }, + "properties": [ + { + "id": "custom.width", + "value": 639 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Context" + }, + "properties": [ + { + "id": "custom.cellOptions", + "value": { + "type": "color-text" + } + }, + { + "id": "custom.inspect", + "value": true + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "connection" + }, + "properties": [ + { + "id": "custom.width", + "value": 220 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "account" + }, + "properties": [ + { + "id": "custom.width", + "value": 223 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Context" + }, + "properties": [ + { + "id": "custom.cellOptions", + "value": { + "type": "json-view" + } + }, + { + "id": "custom.inspect", + "value": true + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Message" + }, + "properties": [ + { + "id": "custom.inspect", + "value": true + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Priority" + }, + "properties": [ + { + "id": "custom.cellOptions", + "value": { + "type": "color-text" + } + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "Handler" + }, + "properties": [ + { + "id": "custom.cellOptions", + "value": { + "type": "json-view" + } + } + ] + } + ] + }, + "gridPos": { + "h": 27, + "w": 24, + "x": 0, + "y": 10 + }, + "id": 7, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "enablePagination": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true, + "sortBy": [ + { + "desc": false, + "displayName": "Priority" + } + ] + }, + "pluginVersion": "10.3.1", + "targets": [ + { + "builderOptions": { + "database": "default", + "fields": [ + "message" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "restrictToFields": [ + { + "label": "logdatetime", + "name": "logdatetime", + "picklistValues": [], + "type": "DateTime" + } + ], + "type": "datetime" + } + ], + "limit": 100, + "mode": "list", + "orderBy": [], + "table": "log_docker_raw" + }, + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "format": 1, + "hide": false, + "meta": { + "builderOptions": { + "database": "default", + "fields": [ + "message" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "restrictToFields": [ + { + "label": "logdatetime", + "name": "logdatetime", + "picklistValues": [], + "type": "DateTime" + } + ], + "type": "datetime" + } + ], + "limit": 100, + "mode": "list", + "orderBy": [], + "table": "log_docker_raw" + } + }, + "queryType": "sql", + "rawSql": "SELECT\n visitParamExtractString(message, 'timestamp') as time,\n visitParamExtractString(message, 'level') as level,\n visitParamExtractString(message, 'handler') as handler,\n visitParamExtractString(message, 'message') as msg,\n visitParamExtractRaw(message, 'context') as context\nFROM \"default\".\"log_docker_raw\"\nWHERE ( logdatetime >= $__fromTime AND logdatetime <= $__toTime )\n AND IF('Any' IN (${priority}), 1 = 1, level IN (${priority}))\n AND ( program = ${program:singlequote} )\n AND ( message LIKE '%$filter1%' )\n AND ( message LIKE '%$filter2%' )\n AND ( message LIKE '%$filter3%' )\n AND ( msg <> '' )\nORDER BY logdatetime DESC LIMIT 5000", + "refId": "A", + "selectedFormat": 4 + } + ], + "title": "Structured logs output", + "transformations": [ + { + "id": "organize", + "options": { + "excludeByName": {}, + "includeByName": {}, + "indexByName": {}, + "renameByName": { + "account": "Account", + "connection": "Connection", + "context": "Context", + "handler": "Handler", + "level": "Priority", + "msg": "Message", + "raw": "Raw", + "time": "TS" + } + } + } + ], + "type": "table" + }, + { + "collapsed": false, + "gridPos": { + "h": 1, + "w": 24, + "x": 0, + "y": 37 + }, + "id": 1, + "panels": [], + "title": "Logs", + "type": "row" + }, + { + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "custom": { + "align": "auto", + "cellOptions": { + "type": "auto" + }, + "inspect": false + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unitScale": true + }, + "overrides": [ + { + "matcher": { + "id": "byName", + "options": "logdatetime" + }, + "properties": [ + { + "id": "custom.width", + "value": 196 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "host" + }, + "properties": [ + { + "id": "custom.width", + "value": 132 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "program" + }, + "properties": [ + { + "id": "custom.width", + "value": 210 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "priority" + }, + "properties": [ + { + "id": "custom.width", + "value": 71 + } + ] + }, + { + "matcher": { + "id": "byName", + "options": "message" + }, + "properties": [ + { + "id": "custom.cellOptions", + "value": { + "type": "json-view" + } + }, + { + "id": "custom.inspect", + "value": true + } + ] + } + ] + }, + "gridPos": { + "h": 27, + "w": 24, + "x": 0, + "y": 38 + }, + "id": 2, + "options": { + "cellHeight": "sm", + "footer": { + "countRows": false, + "fields": "", + "reducer": [ + "sum" + ], + "show": false + }, + "showHeader": true, + "sortBy": [] + }, + "pluginVersion": "10.3.1", + "targets": [ + { + "builderOptions": { + "database": "default", + "fields": [ + "host", + "program", + "logdatetime", + "priority", + "message" + ], + "filters": [ + { + "condition": "AND", + "filterType": "custom", + "key": "logdatetime", + "operator": "WITH IN DASHBOARD TIME RANGE", + "type": "DateTime", + "value": "TODAY" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "program", + "operator": "=", + "type": "String", + "value": "${program:singlequote}" + }, + { + "condition": "AND", + "filterType": "custom", + "key": "message", + "operator": "LIKE", + "type": "String", + "value": "$filter1" + } + ], + "limit": 5000, + "metrics": [], + "mode": "list", + "orderBy": [ + { + "dir": "DESC", + "name": "logdatetime" + } + ], + "table": "log_docker_raw", + "timeField": "logdatetime", + "timeFieldType": "DateTime" + }, + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "format": 1, + "meta": { + "builderOptions": { + "fields": [], + "limit": 100, + "mode": "list" + } + }, + "queryType": "builder", + "rawSql": "SELECT \"host\", \"program\", \"logdatetime\", \"priority\", \"message\" FROM \"default\".\"log_docker_raw\" WHERE ( logdatetime >= $__fromTime AND logdatetime <= $__toTime ) AND ( program = ${program:singlequote} ) AND ( message LIKE '%$filter1%' ) ORDER BY logdatetime DESC LIMIT 5000", + "refId": "A", + "selectedFormat": 4 + } + ], + "title": "Panel Title", + "type": "table" + } + ], + "refresh": "", + "schemaVersion": 39, + "tags": [], + "templating": { + "list": [ + { + "current": { + "selected": false, + "text": "telegram-mg_telegram-1", + "value": "telegram-mg_telegram-1" + }, + "datasource": { + "type": "grafana-clickhouse-datasource", + "uid": "b98b9382-2c99-41c0-bb27-dfd7033d71fa" + }, + "definition": "SELECT DISTINCT program FROM default.log_docker_raw WHERE logdatetime > now() - interval 6 hours;", + "hide": 0, + "includeAll": false, + "label": "Program", + "multi": false, + "name": "program", + "options": [], + "query": "SELECT DISTINCT program FROM default.log_docker_raw WHERE logdatetime > now() - interval 6 hours;", + "refresh": 1, + "regex": "", + "skipUrlSync": false, + "sort": 1, + "type": "query" + }, + { + "current": { + "selected": false, + "text": [ + "Any" + ], + "value": [ + "Any" + ] + }, + "hide": 0, + "includeAll": false, + "label": "Priority", + "multi": true, + "name": "priority", + "options": [ + { + "selected": true, + "text": "Any", + "value": "Any" + }, + { + "selected": false, + "text": "DEBUG", + "value": "DEBUG" + }, + { + "selected": false, + "text": "INFO", + "value": "INFO" + }, + { + "selected": false, + "text": "WARN", + "value": "WARN" + }, + { + "selected": false, + "text": "ERROR", + "value": "ERROR" + } + ], + "query": "Any,DEBUG,INFO,WARN,ERROR", + "queryValue": "", + "skipUrlSync": false, + "type": "custom" + }, + { + "current": { + "selected": false, + "text": "", + "value": "" + }, + "hide": 0, + "label": "Filter #1", + "name": "filter1", + "options": [ + { + "selected": true, + "text": "*", + "value": "*" + } + ], + "query": "", + "skipUrlSync": false, + "type": "textbox" + }, + { + "current": {}, + "hide": 0, + "name": "filter2", + "options": [], + "query": "", + "skipUrlSync": false, + "type": "textbox" + }, + { + "current": {}, + "hide": 0, + "name": "filter3", + "options": [], + "query": "", + "skipUrlSync": false, + "type": "textbox" + } + ] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Logs + Structured via Query (zaplog)", + "uid": "b445eb43-25d1-4112-b628-3b8acf037f10", + "version": 6, + "weekStart": "" +} \ No newline at end of file