|
| 1 | +# JCT with ClickHouse + Vector + Grafana |
| 2 | + |
| 3 | +This is an alternative to ELK for collecting, mining, and visualizing JCT stack events. |
| 4 | + |
| 5 | +## Architecture |
| 6 | + |
| 7 | +``` |
| 8 | +JCT agent --> /tmp/stacks/jct_*.log |
| 9 | + | |
| 10 | + Vector (tail + rename field) |
| 11 | + | |
| 12 | + ClickHouse: default.jct_raw (raw ingest table) |
| 13 | + | |
| 14 | + ClickHouse: default.jct_events_mv (materialized view) |
| 15 | + | |
| 16 | + ClickHouse: default.jct_events (parsed, queryable) |
| 17 | + | |
| 18 | + Grafana dashboards |
| 19 | +``` |
| 20 | + |
| 21 | +JSON parsing happens entirely in ClickHouse via a materialized view — Vector only forwards raw lines. |
| 22 | +This avoids VRL type-system complexity and keeps the Vector config minimal. |
| 23 | + |
| 24 | +## Start the stack |
| 25 | + |
| 26 | +```zsh |
| 27 | +cd /home/msauer/dev/workspace-private/java-code-tracer |
| 28 | +docker compose -f docker-compose-clickhouse.yml up -d |
| 29 | +``` |
| 30 | + |
| 31 | +Grafana: |
| 32 | + |
| 33 | +- URL: `http://localhost:5601` |
| 34 | +- User: `admin` |
| 35 | +- Password: `admin` |
| 36 | + |
| 37 | +Dashboard provisioning: |
| 38 | + |
| 39 | +- Folder: `JCT` |
| 40 | +- Dashboard: `JCT Overview` |
| 41 | +- Panels: |
| 42 | + - Throughput by Minute |
| 43 | + - Top Classes |
| 44 | + - Top Methods |
| 45 | + |
| 46 | +If Grafana was already running before these files were added, restart the stack once: |
| 47 | + |
| 48 | +```zsh |
| 49 | +cd /home/msauer/dev/workspace-private/java-code-tracer |
| 50 | +docker compose -f docker-compose-clickhouse.yml down |
| 51 | +docker compose -f docker-compose-clickhouse.yml up -d |
| 52 | +``` |
| 53 | + |
| 54 | +## Stop and reset |
| 55 | + |
| 56 | +```zsh |
| 57 | +cd /home/msauer/dev/workspace-private/java-code-tracer |
| 58 | +docker compose -f docker-compose-clickhouse.yml down |
| 59 | +docker volume rm java-code-tracer_clickhouse-data java-code-tracer_grafana-data |
| 60 | +``` |
| 61 | + |
| 62 | +## Run your app with JCT (file processor) |
| 63 | + |
| 64 | +Use a file-based config such as `doc/config-sample-application-file.yaml` and write to `/tmp/stacks`. |
| 65 | + |
| 66 | +## Verify ingestion quickly |
| 67 | + |
| 68 | +```zsh |
| 69 | +curl -s "http://localhost:8123/?query=SELECT%20count(*)%20FROM%20default.jct_events" |
| 70 | +``` |
| 71 | + |
| 72 | +Verify dashboard data: |
| 73 | + |
| 74 | +1. Open `http://localhost:5601`. |
| 75 | +2. Go to `Dashboards` and open `JCT / JCT Overview`. |
| 76 | +3. Select time range `Last 15 minutes` and confirm panels are populated. |
| 77 | + |
| 78 | +## Useful ClickHouse queries |
| 79 | + |
| 80 | +Run queries directly: |
| 81 | + |
| 82 | +```zsh |
| 83 | +curl -s "http://localhost:8123/?query=<URL-encoded SQL>" |
| 84 | +``` |
| 85 | + |
| 86 | +Or open the ClickHouse Play UI at `http://localhost:8123/play`. |
| 87 | + |
| 88 | +Top classes in the last 15 minutes: |
| 89 | + |
| 90 | +```sql |
| 91 | +SELECT class_name, count(*) AS hits |
| 92 | +FROM default.jct_events |
| 93 | +WHERE ingest_time >= now() - INTERVAL 15 MINUTE |
| 94 | +GROUP BY class_name |
| 95 | +ORDER BY hits DESC |
| 96 | +LIMIT 30; |
| 97 | +``` |
| 98 | + |
| 99 | +Top methods in the last 15 minutes: |
| 100 | + |
| 101 | +```sql |
| 102 | +SELECT method_name, count(*) AS hits |
| 103 | +FROM default.jct_events |
| 104 | +WHERE ingest_time >= now() - INTERVAL 15 MINUTE |
| 105 | +GROUP BY method_name |
| 106 | +ORDER BY hits DESC |
| 107 | +LIMIT 30; |
| 108 | +``` |
| 109 | + |
| 110 | +Call frequency over time (1-minute buckets): |
| 111 | + |
| 112 | +```sql |
| 113 | +SELECT toStartOfMinute(ingest_time) AS minute, count(*) AS hits |
| 114 | +FROM default.jct_events |
| 115 | +WHERE ingest_time >= now() - INTERVAL 60 MINUTE |
| 116 | +GROUP BY minute |
| 117 | +ORDER BY minute; |
| 118 | +``` |
| 119 | + |
| 120 | +Filter by class prefix: |
| 121 | + |
| 122 | +```sql |
| 123 | +SELECT ingest_time, class_name, method_name, stack_depth, stack |
| 124 | +FROM default.jct_events |
| 125 | +WHERE class_name LIKE 'de.marcelsauer.%' |
| 126 | +ORDER BY ingest_time DESC |
| 127 | +LIMIT 200; |
| 128 | +``` |
| 129 | + |
| 130 | +Explode frames to count hot frames across all stacks: |
| 131 | + |
| 132 | +```sql |
| 133 | +SELECT frame, count(*) AS hits |
| 134 | +FROM default.jct_events |
| 135 | +ARRAY JOIN stack AS frame |
| 136 | +WHERE ingest_time >= now() - INTERVAL 15 MINUTE |
| 137 | +GROUP BY frame |
| 138 | +ORDER BY hits DESC |
| 139 | +LIMIT 50; |
| 140 | +``` |
| 141 | + |
| 142 | +Check raw ingestion count: |
| 143 | + |
| 144 | +```sql |
| 145 | +SELECT count(*) FROM default.jct_raw; |
| 146 | +SELECT count(*) FROM default.jct_events; |
| 147 | +``` |
| 148 | + |
| 149 | +## Troubleshooting |
| 150 | + |
| 151 | +**Dashboard is empty:** |
| 152 | +- Check the Grafana time picker — set it to `Last 15 minutes` or wider. |
| 153 | +- Verify events exist: `SELECT count(*) FROM default.jct_events WHERE ingest_time >= now() - INTERVAL 15 MINUTE` |
| 154 | +- Confirm Vector is running: `docker compose -f docker-compose-clickhouse.yml ps` |
| 155 | + |
| 156 | +**Vector exits on startup:** |
| 157 | +- Check logs: `docker compose -f docker-compose-clickhouse.yml logs vector` |
| 158 | +- Confirm `/tmp/stacks` contains `jct_*.log` files. |
| 159 | + |
| 160 | +**ClickHouse authentication errors (403/516):** |
| 161 | +- Ensure `doc/clickhouse/config/users.d/default-user.xml` is present and mounted. |
| 162 | +- Recreate the stack: `docker compose -f docker-compose-clickhouse.yml down -v && docker compose -f docker-compose-clickhouse.yml up -d` |
| 163 | + |
0 commit comments