From 86b98e8c168e28f2a80e516c1b0a695fa3f413dd Mon Sep 17 00:00:00 2001 From: Jurajk Date: Sat, 20 Dec 2025 21:58:52 +0100 Subject: [PATCH] clean up stats --- .env.example | 4 - docs/grafana-integration.md | 173 ------------------ docs/tracking-api.md | 164 ----------------- go.mod | 28 +-- go.sum | 138 +++----------- ...3_cleanup_ignored_tracking_events.down.sql | 5 + ...003_cleanup_ignored_tracking_events.up.sql | 10 + prometheus.yml | 68 ------- src/main.go | 54 +----- src/metrics.go | 20 -- src/tracking/tracking-store.go | 3 + 11 files changed, 58 insertions(+), 609 deletions(-) delete mode 100644 docs/grafana-integration.md delete mode 100644 docs/tracking-api.md create mode 100644 migrations/tracking/000003_cleanup_ignored_tracking_events.down.sql create mode 100644 migrations/tracking/000003_cleanup_ignored_tracking_events.up.sql delete mode 100644 prometheus.yml delete mode 100644 src/metrics.go diff --git a/.env.example b/.env.example index efc7639..bfc5cce 100644 --- a/.env.example +++ b/.env.example @@ -7,7 +7,3 @@ BUILD_NUMBER=prod-v1.0 # Grafana settings GRAFANA_PASSWORD=admin - -# Optional: Custom Prometheus retention -# PROMETHEUS_RETENTION_TIME=30d -# PROMETHEUS_RETENTION_SIZE=10GB diff --git a/docs/grafana-integration.md b/docs/grafana-integration.md deleted file mode 100644 index ad8f095..0000000 --- a/docs/grafana-integration.md +++ /dev/null @@ -1,173 +0,0 @@ -# Grafana Integration Guide - -This guide shows how to visualize your application metrics with Grafana using **real Prometheus**. - -## Why Prometheus? - -We've replaced custom tracking with actual Prometheus because: -- ✅ **Industry standard** - Battle-tested metrics collection -- ✅ **Rich ecosystem** - Thousands of existing dashboards -- ✅ **Better performance** - Optimized time-series storage -- ✅ **Less code** - No custom database or API endpoints -- ✅ **Standard metrics** - HTTP requests, response times, etc. - -## Available Metrics - -### Automatic Metrics (from echo-contrib/prometheus) -- `http_requests_total` - Total HTTP requests by method/status/endpoint -- `http_request_duration_seconds` - Request duration histogram -- `http_request_size_bytes` - Request size histogram -- `http_response_size_bytes` - Response size histogram - -### Custom Application Metrics -- `knet_page_views_total{route="/"}` - Page views by route -- `knet_page_views_total{route="/draw"}` - Draw page views -- `knet_box_clicks_total{position="1"}` - Box clicks by position -- `knet_websocket_connections` - Active WebSocket connections - -## Authentication - -The `/metrics` endpoint uses **Basic Authentication** in production: -- **Username:** `api` (or set via `API_USERNAME` environment variable) -- **Password:** Your API token (set via `API_TOKEN` environment variable) - -**Example:** -```bash -curl -u api:your-api-token http://your-server:54321/metrics -``` - -## Grafana Setup - -### Prometheus Data Source (Recommended) - -1. **Add Prometheus Data Source** in Grafana -2. **Set URL** to: `http://your-server:54321` -3. **Set Basic Auth**: Username: `api`, Password: `your-api-token` -4. **Set Scrape Interval**: 15s (Prometheus scrapes our `/metrics` endpoint) - -That's it! Grafana will automatically discover all available metrics. - -### Sample Dashboard Queries - -**Traffic Overview:** -```promql -# Total requests per minute -rate(http_requests_total[1m]) * 60 - -# Page views -knet_page_views_total - -# Request duration 95th percentile -histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m])) - -# Error rate -rate(http_requests_total{status=~"4.."}[5m]) / rate(http_requests_total[5m]) * 100 -``` - -**Application Metrics:** -```promql -# Box interactions -rate(knet_box_clicks_total[5m]) - -# Active WebSocket connections -knet_websocket_connections - -# Most popular pages -topk(10, rate(knet_page_views_total[1h])) -``` - -## Dashboard Examples - -### 1. HTTP Overview Panel -- **Metric:** `rate(http_requests_total[1m]) * 60` -- **Type:** Graph -- **Title:** "Requests per Minute" - -### 2. Response Time Panel -- **Metric:** `histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))` -- **Type:** Single Stat -- **Title:** "95th Percentile Response Time" - -### 3. Page Views Panel -- **Metric:** `knet_page_views_total` -- **Type:** Graph -- **Title:** "Page Views by Route" - -### 4. Box Clicks Heatmap -- **Metric:** `rate(knet_box_clicks_total[5m])` -- **Type:** Graph -- **Title:** "Box Clicks per Second" - -## Environment Variables - -Set these for production: -```bash -export API_TOKEN="your-secure-api-token" -export API_USERNAME="api" # Optional, defaults to "api" -export BUILD_NUMBER="prod-v1.0" # Enables production mode -``` - -## Benefits of This Approach - -1. **Standard Prometheus** - Works with all Grafana features -2. **Rich Metrics** - HTTP performance + custom business metrics -3. **No Database** - Prometheus handles storage and retention -4. **Better Performance** - Optimized time-series queries -5. **Alerting Ready** - Use Prometheus AlertManager -6. **Ecosystem** - Tons of existing dashboards and tools - -## Persistent Storage Setup - -### Option 1: Docker Compose (Recommended) - -For persistent metrics storage, run a Prometheus server alongside your app: - -```bash -# 1. Copy your API token to .env -cp .env.example .env -# Edit .env and set your API_TOKEN - -# 2. Start the full monitoring stack -docker-compose up -d - -# 3. Access services -# - Your app: http://localhost:54321 -# - Prometheus: http://localhost:9090 -# - Grafana: http://localhost:3000 (admin/admin) -``` - -**What this gives you:** -- ✅ **Persistent metrics** - Data survives restarts -- ✅ **30-day retention** - Configurable in docker-compose.yml -- ✅ **Grafana pre-configured** - Points to Prometheus automatically -- ✅ **Production ready** - Proper volumes and networking - -### Option 2: Standalone Prometheus - -If you prefer to run Prometheus separately: - -```bash -# 1. Update prometheus.yml with your API token -# 2. Start Prometheus -prometheus --config.file=prometheus.yml --storage.tsdb.path=./prometheus_data - -# 3. Configure Grafana to point to http://localhost:9090 -``` - -### Grafana Data Source Configuration - -With persistent Prometheus: -1. **Add Prometheus Data Source** in Grafana -2. **Set URL** to: `http://prometheus:9090` (Docker) or `http://localhost:9090` (standalone) -3. **No authentication needed** - Prometheus handles the API token -4. **Query retention**: Up to 30 days of historical data - -## Quick Start - -1. **Start your server:** `./tmp/main` -2. **Test metrics:** `curl -u api:your-token http://localhost:54321/metrics` -3. **Add Prometheus data source** in Grafana: `http://localhost:54321` -4. **Create dashboard** with queries like `http_requests_total` -5. **Enjoy real-time metrics!** 📊 - -Your analytics are now powered by industry-standard Prometheus! � diff --git a/docs/tracking-api.md b/docs/tracking-api.md deleted file mode 100644 index 35a2c03..0000000 --- a/docs/tracking-api.md +++ /dev/null @@ -1,164 +0,0 @@ -# Tracking API Documentation - -The tracking service provides analytics about endpoint usage with time-based filtering. - -## Authentication - -In production, all tracking endpoints require Bearer token authentication: -``` -Authorization: Bearer -``` - -## Endpoints - -### GET /api/tracking/stats - -Get endpoint statistics with optional time period filtering. - -**Query Parameters:** -- `period` (optional): `day`, `week`, `month`, `year`, `all` (default: `all`) - -**Examples:** -```bash -# Get all-time stats -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/stats - -# Get last week's stats -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/stats?period=week - -# Get last 30 days -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/stats?period=month -``` - -**Response:** -```json -{ - "stats": [ - { - "endpoint": "/", - "method": "GET", - "hit_count": 245, - "unique_users": 89, - "last_access": "2025-08-13T10:30:00Z", - "first_access": "2025-08-06T14:22:00Z" - } - ], - "period": "week", - "total_endpoints": 8 -} -``` - -### GET /api/tracking/summary - -Get overall tracking summary for a time period. - -**Query Parameters:** -- `period` (optional): `day`, `week`, `month`, `year`, `all` (default: `all`) - -**Examples:** -```bash -# Get today's summary -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/summary?period=day - -# Get yearly summary -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/summary?period=year -``` - -**Response:** -```json -{ - "period": "day", - "total_hits": 1247, - "total_endpoints": 12, - "total_unique_users": 234, - "oldest_visit": "2025-08-13T00:15:00Z", - "newest_visit": "2025-08-13T23:45:00Z", - "tracking_active": true -} -``` - -### GET /api/tracking/trends - -Get visit trends over time with configurable granularity. - -**Query Parameters:** -- `granularity` (optional): `hour`, `day`, `week`, `month` (default: `day`) -- `period` (optional): `24h`, `7d`, `30d`, `1y` (default: `7d`) - -**Examples:** -```bash -# Hourly trends for last 24 hours -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/trends?granularity=hour&period=24h - -# Daily trends for last 30 days -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/trends?granularity=day&period=30d - -# Weekly trends for last year -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/trends?granularity=week&period=1y -``` - -**Response:** -```json -{ - "trends": [ - { - "time_bucket": "2025-08-13", - "hits": 567, - "unique_users": 123, - "unique_endpoints": 8 - }, - { - "time_bucket": "2025-08-12", - "hits": 445, - "unique_users": 98, - "unique_endpoints": 7 - } - ], - "granularity": "day", - "period": "7d" -} -``` - -### GET /api/tracking/visits - -Get recent individual visits with optional filtering. - -**Query Parameters:** -- `limit` (optional): Number of visits to return (default: `50`) - -**Example:** -```bash -curl -H "Authorization: Bearer $API_TOKEN" /api/tracking/visits?limit=20 -``` - -**Response:** -```json -{ - "visits": [ - { - "user_hash": "a1b2c3d4e5f6...", - "endpoint": "/boxes", - "method": "GET", - "ip_address": "192.168.1.100", - "user_agent": "Mozilla/5.0...", - "referer": "https://google.com", - "timestamp": "2025-08-13T15:30:00Z" - } - ], - "count": 20 -} -``` - -## Benefits of This Approach - -1. **No Duplication**: Single source of truth in `user_visits` table -2. **Flexible Querying**: Any time period can be queried on-demand -3. **Rich Analytics**: Detailed trends and user behavior insights -4. **Efficient Storage**: Only raw visits stored, stats calculated in real-time -5. **Historical Analysis**: Can analyze any historical period without pre-aggregation - -## Performance Considerations - -- Indexes are created on `timestamp`, `endpoint`, and `user_hash` for fast queries -- For very high traffic, consider adding materialized views for common time periods -- The SQLite database handles thousands of requests efficiently with proper indexing diff --git a/go.mod b/go.mod index e4d4e58..387ca0c 100644 --- a/go.mod +++ b/go.mod @@ -4,40 +4,28 @@ go 1.25 require ( github.com/golang-migrate/migrate/v4 v4.19.1 - github.com/labstack/echo-contrib v0.17.4 - github.com/labstack/echo/v4 v4.13.4 + github.com/labstack/echo/v4 v4.14.0 github.com/labstack/gommon v0.4.2 github.com/mileusna/useragent v1.3.5 - github.com/prometheus/client_golang v1.23.2 - golang.org/x/net v0.47.0 - modernc.org/sqlite v1.40.1 + golang.org/x/net v0.48.0 + modernc.org/sqlite v1.41.0 ) require ( - github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/kr/text v0.2.0 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/ncruces/go-strftime v1.0.0 // indirect - github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.67.4 // indirect - github.com/prometheus/procfs v0.19.2 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + github.com/stretchr/testify v1.11.1 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - go.yaml.in/yaml/v2 v2.4.3 // indirect - golang.org/x/crypto v0.45.0 // indirect - golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 // indirect - golang.org/x/sys v0.38.0 // indirect - golang.org/x/text v0.31.0 // indirect + golang.org/x/crypto v0.46.0 // indirect + golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 // indirect + golang.org/x/sys v0.39.0 // indirect + golang.org/x/text v0.32.0 // indirect golang.org/x/time v0.14.0 // indirect - google.golang.org/protobuf v1.36.10 // indirect modernc.org/libc v1.67.1 // indirect modernc.org/mathutil v1.7.1 // indirect modernc.org/memory v1.11.0 // indirect diff --git a/go.sum b/go.sum index 0ae77d7..906a4e7 100644 --- a/go.sum +++ b/go.sum @@ -1,40 +1,19 @@ -github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= -github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= -github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= -github.com/golang-migrate/migrate/v4 v4.19.0 h1:RcjOnCGz3Or6HQYEJ/EEVLfWnmw9KnoigPSjzhCuaSE= -github.com/golang-migrate/migrate/v4 v4.19.0/go.mod h1:9dyEcu+hO+G9hPSw8AIg50yg622pXJsoHItQnDGZkI0= github.com/golang-migrate/migrate/v4 v4.19.1 h1:OCyb44lFuQfYXYLx1SCxPZQGU7mcaZ7gH9yH4jSFbBA= github.com/golang-migrate/migrate/v4 v4.19.1/go.mod h1:CTcgfjxhaUtsLipnLoQRWCrjYXycRz/g5+RWDuYgPrE= -github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= -github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs= github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= -github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= -github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/labstack/echo-contrib v0.17.4 h1:g5mfsrJfJTKv+F5uNKCyrjLK7js+ZW6HTjg4FnDxxgk= -github.com/labstack/echo-contrib v0.17.4/go.mod h1:9O7ZPAHUeMGTOAfg80YqQduHzt0CzLak36PZRldYrZ0= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA= github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ= +github.com/labstack/echo/v4 v4.14.0 h1:+tiMrDLxwv6u0oKtD03mv+V1vXXB3wCqPHJqPuIe+7M= +github.com/labstack/echo/v4 v4.14.0/go.mod h1:xmw1clThob0BSVRX1CRQkGQ/vjwcpOMjQZSZa9fKA/c= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= @@ -45,119 +24,64 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mileusna/useragent v1.3.5 h1:SJM5NzBmh/hO+4LGeATKpaEX9+b4vcGg2qXGLiNGDws= github.com/mileusna/useragent v1.3.5/go.mod h1:3d8TOmwL/5I8pJjyVDteHtgDGcefrFUX4ccGOMKNYYc= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= -github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= -github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w= github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= -github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= -github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= -github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= -github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9ZoGs= -github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA= -github.com/prometheus/common v0.67.1 h1:OTSON1P4DNxzTg4hmKCc37o4ZAZDv0cfXLkOt0oEowI= -github.com/prometheus/common v0.67.1/go.mod h1:RpmT9v35q2Y+lsieQsdOh5sXZ6ajUGC8NjZAmr8vb0Q= -github.com/prometheus/common v0.67.4 h1:yR3NqWO1/UyO1w2PhUvXlGQs/PtFmoveVO0KZ4+Lvsc= -github.com/prometheus/common v0.67.4/go.mod h1:gP0fq6YjjNCLssJCQp0yk4M8W6ikLURwkdd/YKtTbyI= -github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg= -github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is= -github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0= -github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw= -github.com/prometheus/procfs v0.19.2 h1:zUMhqEW66Ex7OXIiDkll3tl9a1ZdilUOd/F6ZXw4Vws= -github.com/prometheus/procfs v0.19.2/go.mod h1:M0aotyiemPhBCM0z5w87kL22CxfcH05ZpYlu+b4J7mw= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= -github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= -github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo= github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= -go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= -go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= -go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI= -go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU= -go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= -go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= -golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= -golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= -golang.org/x/crypto v0.43.0 h1:dduJYIi3A3KOfdGOHX8AVZ/jGiyPa3IbBozJ5kNuE04= -golang.org/x/crypto v0.43.0/go.mod h1:BFbav4mRNlXJL4wNeejLpWxB7wMbc79PdRGhWKncxR0= golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= -golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b h1:DXr+pvt3nC887026GRP39Ej11UATqWDmWuS99x26cD0= -golang.org/x/exp v0.0.0-20250819193227-8b4c13bb791b/go.mod h1:4QTo5u+SEIbbKW1RacMZq1YEfOBqeXa19JeshGi+zc4= -golang.org/x/exp v0.0.0-20251017212417-90e834f514db h1:by6IehL4BH5k3e3SJmcoNbOobMey2SLpAF79iPOEBvw= -golang.org/x/exp v0.0.0-20251017212417-90e834f514db/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70= +golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU= +golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0= golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39 h1:DHNhtq3sNNzrvduZZIiFyXWOL9IWaDPHqTnLJp+rCBY= golang.org/x/exp v0.0.0-20251125195548-87e1e737ad39/go.mod h1:46edojNIoXTNOhySWIWdix628clX9ODXwPsQuG6hsK0= -golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ= -golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc= -golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA= +golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93 h1:fQsdNF2N+/YewlRZiricy4P1iimyPKZ/xwniHj8Q2a0= +golang.org/x/exp v0.0.0-20251219203646-944ab1f22d93/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU= golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk= -golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= -golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= -golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= -golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= +golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc= +golang.org/x/mod v0.31.0 h1:HaW9xtz0+kOcWKwli0ZXy79Ix+UW/vOfmWI5QVd2tgI= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= -golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= -golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU= +golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY= golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I= +golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k= -golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ= -golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= -golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk= -golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4= -golang.org/x/text v0.30.0 h1:yznKA/E9zq54KzlzBEAWn1NXSQ8DIp/NYMy88xJjl4k= -golang.org/x/text v0.30.0/go.mod h1:yDdHFIX9t+tORqspjENWgzaCVXgk0yYnYuSZ8UzzBVM= +golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk= +golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= -golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE= -golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg= +golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU= +golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY= golang.org/x/time v0.14.0 h1:MRx4UaLrDotUKUdCIqzPC48t1Y9hANFKIRpNx+Te8PI= golang.org/x/time v0.14.0/go.mod h1:eL/Oa2bBBK0TkX57Fyni+NgnyQQN4LitPmob2Hjnqw4= -golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg= -golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s= -golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ= -google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= -google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= -google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE= -google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= -gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ= +golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ= +golang.org/x/tools v0.40.0 h1:yLkxfA+Qnul4cs9QA3KnlFu0lVmd8JJfoq+E41uSutA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -modernc.org/cc/v4 v4.26.4 h1:jPhG8oNjtTYuP2FA4YefTJ/wioNUGALmGuEWt7SUR6s= -modernc.org/cc/v4 v4.26.4/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= -modernc.org/cc/v4 v4.26.5 h1:xM3bX7Mve6G8K8b+T11ReenJOT+BmVqQj0FY5T4+5Y4= modernc.org/cc/v4 v4.27.1 h1:9W30zRlYrefrDV2JE2O8VDtJ1yPGownxciz5rrbQZis= -modernc.org/ccgo/v4 v4.28.1 h1:wPKYn5EC/mYTqBO373jKjvX2n+3+aK7+sICCv4Fjy1A= -modernc.org/ccgo/v4 v4.28.1/go.mod h1:uD+4RnfrVgE6ec9NGguUNdhqzNIeeomeXf6CL0GTE5Q= +modernc.org/cc/v4 v4.27.1/go.mod h1:uVtb5OGqUKpoLWhqwNQo/8LwvoiEBLvZXIQ/SmO6mL0= modernc.org/ccgo/v4 v4.30.1 h1:4r4U1J6Fhj98NKfSjnPUN7Ze2c6MnAdL0hWw6+LrJpc= -modernc.org/fileutil v1.3.28 h1:Vp156KUA2nPu9F1NEv036x9UGOjg2qsi5QlWTjZmtMk= -modernc.org/fileutil v1.3.28/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc= +modernc.org/ccgo/v4 v4.30.1/go.mod h1:bIOeI1JL54Utlxn+LwrFyjCx2n2RDiYEaJVSrgdrRfM= modernc.org/fileutil v1.3.40 h1:ZGMswMNc9JOCrcrakF1HrvmergNLAmxOPjizirpfqBA= +modernc.org/fileutil v1.3.40/go.mod h1:HxmghZSZVAz/LXcMNwZPA/DRrQZEVP9VX0V4LQGQFOc= modernc.org/gc/v2 v2.6.5 h1:nyqdV8q46KvTpZlsw66kWqwXRHdjIlJOhG6kxiV/9xI= modernc.org/gc/v2 v2.6.5/go.mod h1:YgIahr1ypgfe7chRuJi2gD7DBQiKSLMPgBQe9oIiito= +modernc.org/gc/v3 v3.1.1 h1:k8T3gkXWY9sEiytKhcgyiZ2L0DTyCQ/nvX+LoCljoRE= +modernc.org/gc/v3 v3.1.1/go.mod h1:HFK/6AGESC7Ex+EZJhJ2Gni6cTaYpSMmU/cT9RmlfYY= modernc.org/goabi0 v0.2.0 h1:HvEowk7LxcPd0eq6mVOAEMai46V+i7Jrj13t4AzuNks= modernc.org/goabi0 v0.2.0/go.mod h1:CEFRnnJhKvWT1c1JTI3Avm+tgOWbkOu5oPA8eH8LnMI= -modernc.org/libc v1.66.8 h1:/awsvTnyN/sNjvJm6S3lb7KZw5WV4ly/sBEG7ZUzmIE= -modernc.org/libc v1.66.8/go.mod h1:aVdcY7udcawRqauu0HukYYxtBSizV+R80n/6aQe9D5k= -modernc.org/libc v1.66.10 h1:yZkb3YeLx4oynyR+iUsXsybsX4Ubx7MQlSYEw4yj59A= -modernc.org/libc v1.66.10/go.mod h1:8vGSEwvoUoltr4dlywvHqjtAqHBaw0j1jI7iFBTAr2I= modernc.org/libc v1.67.1 h1:bFaqOaa5/zbWYJo8aW0tXPX21hXsngG2M7mckCnFSVk= modernc.org/libc v1.67.1/go.mod h1:QvvnnJ5P7aitu0ReNpVIEyesuhmDLQ8kaEoyMjIFZJA= modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU= @@ -168,12 +92,10 @@ modernc.org/opt v0.1.4 h1:2kNGMRiUjrp4LcaPuLY2PzUfqM/w9N23quVwhKt5Qm8= modernc.org/opt v0.1.4/go.mod h1:03fq9lsNfvkYSfxrfUhZCWPk1lm4cq4N+Bh//bEtgns= modernc.org/sortutil v1.2.1 h1:+xyoGf15mM3NMlPDnFqrteY07klSFxLElE2PVuWIJ7w= modernc.org/sortutil v1.2.1/go.mod h1:7ZI3a3REbai7gzCLcotuw9AC4VZVpYMjDzETGsSMqJE= -modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek= -modernc.org/sqlite v1.38.2/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E= -modernc.org/sqlite v1.39.1 h1:H+/wGFzuSCIEVCvXYVHX5RQglwhMOvtHSv+VtidL2r4= -modernc.org/sqlite v1.39.1/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE= modernc.org/sqlite v1.40.1 h1:VfuXcxcUWWKRBuP8+BR9L7VnmusMgBNNnBYGEe9w/iY= modernc.org/sqlite v1.40.1/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE= +modernc.org/sqlite v1.41.0 h1:bJXddp4ZpsqMsNN1vS0jWo4IJTZzb8nWpcgvyCFG9Ck= +modernc.org/sqlite v1.41.0/go.mod h1:9fjQZ0mB1LLP0GYrp39oOJXx/I2sxEnZtzCmEQIKvGE= modernc.org/strutil v1.2.1 h1:UneZBkQA+DX2Rp35KcM69cSsNES9ly8mQWD71HKlOA0= modernc.org/strutil v1.2.1/go.mod h1:EHkiggD70koQxjVdSBM3JKM7k6L0FbGE5eymy9i3B9A= modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= diff --git a/migrations/tracking/000003_cleanup_ignored_tracking_events.down.sql b/migrations/tracking/000003_cleanup_ignored_tracking_events.down.sql new file mode 100644 index 0000000..8bfd8e7 --- /dev/null +++ b/migrations/tracking/000003_cleanup_ignored_tracking_events.down.sql @@ -0,0 +1,5 @@ +-- This migration is irreversible as we're deleting historical data +-- If needed, you would need to restore from a backup + +-- No-op down migration since we can't restore deleted tracking events +SELECT 1; diff --git a/migrations/tracking/000003_cleanup_ignored_tracking_events.up.sql b/migrations/tracking/000003_cleanup_ignored_tracking_events.up.sql new file mode 100644 index 0000000..75c7a70 --- /dev/null +++ b/migrations/tracking/000003_cleanup_ignored_tracking_events.up.sql @@ -0,0 +1,10 @@ +-- Remove tracking events that match current ignored patterns + +-- Remove visits to ignored paths +DELETE FROM user_visits WHERE + 'path' = '/tracking' OR + 'path' = '/metrics' OR + 'path' LIKE '/css/%' OR + 'path' LIKE '/js/%' OR + 'path' = '/boxes/ws' OR + 'path' LIKE '%favicon%'; \ No newline at end of file diff --git a/prometheus.yml b/prometheus.yml deleted file mode 100644 index 38cde9d..0000000 --- a/prometheus.yml +++ /dev/null @@ -1,68 +0,0 @@ -# Prometheus configuration for knet application -global: - scrape_interval: 15s # How often to scrape targets - evaluation_interval: 15s # How often to evaluate rules - - # Attach these labels to any time series or alerts when communicating with - # external systems (federation, remote storage, Alertmanager). - external_labels: - monitor: 'knet-monitor' - -# Alertmanager configuration (optional) -alerting: - alertmanagers: - - static_configs: - - targets: - # - alertmanager:9093 - -# Load rules once and periodically evaluate them according to the global 'evaluation_interval'. -rule_files: - # - "first_rules.yml" - # - "second_rules.yml" - -# A scrape configuration containing exactly one endpoint to scrape: -scrape_configs: - # The job name is added as a label `job=` to any timeseries scraped from this config. - - job_name: 'knet-app' - - # metrics_path defaults to '/metrics' - # scheme defaults to 'http'. - - # How often to scrape this target - scrape_interval: 15s - - # Timeout for scraping - scrape_timeout: 10s - - # Use HTTPS to connect to the target - scheme: https - - # Basic authentication for protected endpoints - basic_auth: - username: 'api' - password: 'your-default-token' # This should match your API_TOKEN env var - - static_configs: - - targets: ['knet.sk'] # Your knet application - labels: - instance: 'knet-prod' - environment: 'production' - - # Only scrape metrics endpoint - metrics_path: /metrics - - # Optional: Add custom headers - # headers: - # X-Custom-Header: value - - # Optional: Monitor Prometheus itself - - job_name: 'prometheus' - static_configs: - - targets: ['localhost:9090'] - -# Storage configuration -# Prometheus stores data in ./data by default -# You can customize with command line flags: -# --storage.tsdb.path=/prometheus -# --storage.tsdb.retention.time=15d -# --storage.tsdb.retention.size=10GB diff --git a/src/main.go b/src/main.go index 6bd5498..7dd66d4 100644 --- a/src/main.go +++ b/src/main.go @@ -4,16 +4,12 @@ import ( "html/template" "io" "net/http" - "os" "strings" "time" - "github.com/labstack/echo-contrib/prometheus" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "github.com/labstack/gommon/log" - promclient "github.com/prometheus/client_golang/prometheus" - "github.com/prometheus/client_golang/prometheus/promhttp" "knet.sk/src/boxes" "knet.sk/src/draw" "knet.sk/src/tracking" @@ -50,46 +46,16 @@ func newPage(boxes []boxes.Box) Page { var ( e = echo.New() - - // Custom Prometheus metrics - boxClicks = promclient.NewCounterVec( - promclient.CounterOpts{ - Name: "knet_box_clicks_total", - Help: "Total number of box clicks by position", - }, - []string{"position"}, - ) - - activeConnections = promclient.NewGauge( - promclient.GaugeOpts{ - Name: "knet_websocket_connections", - Help: "Current number of active WebSocket connections", - }, - ) - - pageViews = promclient.NewCounterVec( - promclient.CounterOpts{ - Name: "knet_page_views_total", - Help: "Total page views by route", - }, - []string{"route"}, - ) ) func init() { // Register custom metrics - promclient.MustRegister(boxClicks) - promclient.MustRegister(activeConnections) - promclient.MustRegister(pageViews) + } func main() { e.Renderer = NewTemplates() - // Setup Prometheus metrics - p := prometheus.NewPrometheus("knet", nil) - p.Use(e) - e.Logger.SetLevel(log.DEBUG) e.Use(middleware.Logger()) if util.IsProd() { @@ -103,24 +69,11 @@ func main() { e.Use(tracking.EchoWithConfig(tracking.TrackingConfig{ IgnorePaths: []string{"/tracking", "/metrics", "/css/*", "/js/*", "/boxes/ws", "*favicon*"}, - IgnoreUserAgents: []string{"*Prometheus*", "*UptimeRobot*", "NetworkingExtension*"}, + IgnoreUserAgents: []string{}, })) trackingGroup := e.Group("/tracking") trackingGroup.GET("", tracking.BasicTrackingHandler) - // Prometheus metrics endpoint (standard /metrics) - metricsGroup := e.Group("/metrics") - if util.IsProd() { - metricsGroup.Use(middleware.BasicAuth(func(username, password string, c echo.Context) (bool, error) { - expectedToken := os.Getenv("API_TOKEN") - if expectedToken == "" { - return false, nil - } - return username == "api" && password == expectedToken, nil - })) - } - metricsGroup.GET("", echo.WrapHandler(promhttp.Handler())) - e.GET("/health", func(c echo.Context) error { return c.Render(200, "health", Page{ BuildNumber: util.GetBuildNumber(), @@ -144,13 +97,11 @@ func main() { e.GET("/", func(c echo.Context) error { // Track page view - pageViews.WithLabelValues("/").Inc() return c.Render(200, "index", newPage(boxes.GetBoxes())) }) e.GET("/timer", func(c echo.Context) error { // Track page view - pageViews.WithLabelValues("/timer").Inc() return c.Render(200, "timer", Page{ BuildNumber: util.GetBuildNumber(), Integrity: util.CalculateAssetIntegrities(), @@ -161,7 +112,6 @@ func main() { e.GET("/draw", func(c echo.Context) error { // Track page view - pageViews.WithLabelValues("/draw").Inc() return draw.Page(c) }) e.GET("/draw/ws", draw.InitWs) diff --git a/src/metrics.go b/src/metrics.go deleted file mode 100644 index 2cdf100..0000000 --- a/src/metrics.go +++ /dev/null @@ -1,20 +0,0 @@ -package main - -import ( - "github.com/prometheus/client_golang/prometheus" -) - -// GetActiveConnections returns the current number of active WebSocket connections -// This function will be called by Prometheus to get the current gauge value -func GetActiveConnections() prometheus.GaugeFunc { - return prometheus.NewGaugeFunc( - prometheus.GaugeOpts{ - Name: "knet_websocket_connections_active", - Help: "Current number of active WebSocket connections", - }, - func() float64 { - // This will be implemented to call boxes.GetConnectionCount() - return 0 // Placeholder for now - }, - ) -} diff --git a/src/tracking/tracking-store.go b/src/tracking/tracking-store.go index 8bff132..ddbd731 100644 --- a/src/tracking/tracking-store.go +++ b/src/tracking/tracking-store.go @@ -2,6 +2,7 @@ package tracking import ( "database/sql" + "log" "sync" "time" @@ -54,6 +55,8 @@ func StartTrackingService() *TrackingService { if err := trackingService.initDB(); err != nil { panic(err) } + } else { + log.Println("Tracking database migrations applied successfully.") } }