update dashboard, several fixes

This commit is contained in:
Pavel 2024-09-26 12:47:00 +03:00
parent c9f0ac9595
commit e770437dec
4 changed files with 181 additions and 185 deletions

View File

@ -1,6 +1,6 @@
# Grafana Clickhouse Docker Log Aggregation # Grafana Clickhouse Docker Log Aggregation
This demo project can aggregate logs from Docker containers and store them in Clickhouse. In the `dashboards` directory you can find dashboard examples for specific log format. `Logs + Structured via Query` is recommended. This demo project can aggregate logs from Docker containers and store them in Clickhouse. In the `dashboards` directory you can find dashboard examples for specific log format. `Logs + Structured via Query` is recommended because the other one is deprecated now.
**Note**: dashboards are tuned for structured logging (JSON log records). **Note**: dashboards are tuned for structured logging (JSON log records).
@ -8,8 +8,8 @@ This demo project can aggregate logs from Docker containers and store them in Cl
Obviously, you'll need Docker: Obviously, you'll need Docker:
1. `make migrate` (you can totally use `clickhouse-client` inside container if migrator hangs up). 1. `make migrate` (use `clickhouse-client` inside container and execute migration SQL directly if migrator doesn't work).
2. Navigate to `http://localhost:3000`, use `admin:admin` as credentials. 2. Navigate to `http://grafana.test` or `http://localhost:3000` (if you did not configure Traefik locally), use `admin:admin` as credentials.
3. Create your own dashboard or import those I provided (`dashboards/` directory). 3. Import [Logs + Structured via Query](dashboards/Logs + Structured via Query.json) dashboard.
4. Run any Docker project with structured JSON logs. 4. Run any Docker project with structured JSON logs.
5. Done. 5. Done.

53
compose.yml Normal file
View File

@ -0,0 +1,53 @@
services:
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
depends_on:
- clickhouse
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: clickhouse/clickhouse-server:24
environment:
- CLICKHOUSE_DB=default
- CLICKHOUSE_USER=default
- CLICKHOUSE_PASSWORD=default
- CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT=1
ports:
- '8123:8123'
ulimits:
nofile:
soft: 262144
hard: 262144
cap_add:
- NET_ADMIN
- SYS_NICE
- IPC_LOCK
healthcheck:
test: wget --no-verbose --tries=1 --spider http://localhost:8123/ping || exit 1
interval: 10s
timeout: 5s
retries: 5
volumes:
- clickhouse_data:/var/lib/clickhouse
vector:
image: timberio/vector:latest-alpine
ports:
- '8686:8686'
depends_on:
- clickhouse
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./files/vector.yaml:/etc/vector/vector.yaml:ro
volumes:
clickhouse_data:
driver: local
grafana_data:
driver: local

View File

@ -53,6 +53,7 @@
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line", "drawStyle": "line",
"fillOpacity": 0, "fillOpacity": 0,
"gradientMode": "hue", "gradientMode": "hue",
@ -202,6 +203,7 @@
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line", "drawStyle": "line",
"fillOpacity": 0, "fillOpacity": 0,
"gradientMode": "none", "gradientMode": "none",
@ -338,6 +340,7 @@
}, },
{ {
"datasource": { "datasource": {
"default": true,
"type": "grafana-clickhouse-datasource", "type": "grafana-clickhouse-datasource",
"uid": "c029a1fb-9305-40f9-ad75-bd648c3138b4" "uid": "c029a1fb-9305-40f9-ad75-bd648c3138b4"
}, },
@ -389,106 +392,6 @@
"unit": "string" "unit": "string"
}, },
"overrides": [ "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": { "matcher": {
"id": "byName", "id": "byName",
@ -498,6 +401,10 @@
{ {
"id": "custom.width", "id": "custom.width",
"value": 658 "value": 658
},
{
"id": "custom.inspect",
"value": true
} }
] ]
}, },
@ -510,7 +417,7 @@
{ {
"id": "custom.cellOptions", "id": "custom.cellOptions",
"value": { "value": {
"type": "color-text" "type": "json-view"
} }
}, },
{ {
@ -522,59 +429,43 @@
{ {
"matcher": { "matcher": {
"id": "byName", "id": "byName",
"options": "connection" "options": "Handler"
},
"properties": [
{
"id": "custom.width",
"value": 220
}
]
},
{
"matcher": {
"id": "byName",
"options": "account"
},
"properties": [
{
"id": "custom.width",
"value": 223
}
]
},
{
"matcher": {
"id": "byName",
"options": "Message"
},
"properties": [
{
"id": "custom.inspect",
"value": true
}
]
},
{
"matcher": {
"id": "byName",
"options": "Priority"
}, },
"properties": [ "properties": [
{ {
"id": "custom.cellOptions", "id": "custom.cellOptions",
"value": { "value": {
"type": "color-text" "type": "json-view"
} }
},
{
"id": "custom.width",
"value": 272
} }
] ]
}, },
{ {
"matcher": { "matcher": {
"id": "byName", "id": "byName",
"options": "Handler" "options": "Account"
}, },
"properties": [ "properties": [
{
"id": "custom.width",
"value": 158
}
]
},
{
"matcher": {
"id": "byName",
"options": "Context"
},
"properties": [
{
"id": "custom.inspect",
"value": true
},
{ {
"id": "custom.cellOptions", "id": "custom.cellOptions",
"value": { "value": {
@ -589,21 +480,101 @@
"options": "TS" "options": "TS"
}, },
"properties": [ "properties": [
{
"id": "unit",
"value": "dateTimeAsIso"
},
{ {
"id": "custom.width", "id": "custom.width",
"value": 172 "value": 176
} }
] ]
}, },
{ {
"matcher": { "matcher": {
"id": "byName", "id": "byName",
"options": "Account" "options": "Stream ID"
}, },
"properties": [ "properties": [
{ {
"id": "custom.width", "id": "custom.width",
"value": 113 "value": 234
}
]
},
{
"matcher": {
"id": "byName",
"options": "Priority"
},
"properties": [
{
"id": "custom.cellOptions",
"value": {
"type": "color-background"
}
},
{
"id": "mappings",
"value": [
{
"options": {
"DEBUG": {
"color": "green",
"index": 0,
"text": "Debug"
},
"ERROR": {
"color": "red",
"index": 2,
"text": "Error"
},
"INFO": {
"color": "blue",
"index": 1,
"text": "Info"
},
"WARN": {
"color": "yellow",
"index": 4,
"text": "Warning"
},
"WARNING": {
"color": "yellow",
"index": 3,
"text": "Warning"
}
},
"type": "value"
},
{
"options": {
"match": "empty",
"result": {
"color": "transparent",
"index": 5,
"text": "(not set)"
}
},
"type": "special"
}
]
},
{
"id": "custom.width",
"value": 118
}
]
},
{
"matcher": {
"id": "byName",
"options": "Connection"
},
"properties": [
{
"id": "custom.width",
"value": 250
} }
] ]
} }
@ -630,7 +601,7 @@
"showHeader": true, "showHeader": true,
"sortBy": [] "sortBy": []
}, },
"pluginVersion": "10.4.1", "pluginVersion": "11.2.0",
"targets": [ "targets": [
{ {
"builderOptions": { "builderOptions": {
@ -735,7 +706,7 @@
} }
}, },
"queryType": "sql", "queryType": "sql",
"rawSql": "SELECT \n visitParamExtractString(message, 'datetime') as time,\n visitParamExtractString(message, 'level_name') as level,\n visitParamExtractString(message, 'connection') as connection,\n visitParamExtractString(message, 'account') as account,\n visitParamExtractString(message, 'handler') as handler,\n visitParamExtractString(message, 'message') as msg,\n visitParamExtractRaw(message, 'context') as ctx\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", "rawSql": "SELECT \n visitParamExtractString(message, 'datetime') as t,\n visitParamExtractString(message, 'level_name') as level,\n visitParamExtractString(message, 'connection') as connection,\n visitParamExtractString(message, 'account') as account,\n visitParamExtractString(message, 'handler') as handler,\n visitParamExtractString(message, 'streamId') as stream_id,\n visitParamExtractString(message, 'message') as msg,\n replaceAll(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", "refId": "A",
"selectedFormat": 4 "selectedFormat": 4
} }
@ -751,11 +722,14 @@
"renameByName": { "renameByName": {
"account": "Account", "account": "Account",
"connection": "Connection", "connection": "Connection",
"context": "Context",
"ctx": "Context", "ctx": "Context",
"handler": "Handler", "handler": "Handler",
"level": "Priority", "level": "Priority",
"msg": "Message", "msg": "Message",
"raw": "Raw", "raw": "Raw",
"stream_id": "Stream ID",
"t": "TS",
"time": "TS" "time": "TS"
} }
} }
@ -897,7 +871,7 @@
"showHeader": true, "showHeader": true,
"sortBy": [] "sortBy": []
}, },
"pluginVersion": "10.4.1", "pluginVersion": "11.2.0",
"targets": [ "targets": [
{ {
"builderOptions": { "builderOptions": {
@ -977,9 +951,9 @@
"list": [ "list": [
{ {
"current": { "current": {
"selected": true, "selected": false,
"text": "telegram-mg_telegram-1", "text": "whatsapp-360-dialog-app-1",
"value": "telegram-mg_telegram-1" "value": "whatsapp-360-dialog-app-1"
}, },
"datasource": { "datasource": {
"type": "grafana-clickhouse-datasource", "type": "grafana-clickhouse-datasource",
@ -1094,6 +1068,6 @@
"timezone": "", "timezone": "",
"title": "Logs + Structured via Query", "title": "Logs + Structured via Query",
"uid": "b445eb43-25d1-4112-b628-3b8acf037f10", "uid": "b445eb43-25d1-4112-b628-3b8acf037f10",
"version": 5, "version": 8,
"weekStart": "" "weekStart": ""
} }

View File

@ -1,31 +0,0 @@
version: '3.8'
services:
grafana:
image: grafana/grafana:latest
volumes:
- grafana_data:/var/lib/grafana
ports:
- '3000:3000'
clickhouse:
image: docker.io/bitnami/clickhouse:23
environment:
- CLICKHOUSE_ADMIN_USER=default
- CLICKHOUSE_ADMIN_PASSWORD=default
ports:
- '8123:8123'
volumes:
- clickhouse_data:/bitnami/clickhouse
vector:
image: timberio/vector:latest-alpine
ports:
- '8686:8686'
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./files/vector.yaml:/etc/vector/vector.yaml:ro
volumes:
clickhouse_data:
driver: local
grafana_data:
driver: local