mirror of
https://github.com/jhd3197/ServerKit.git
synced 2026-11-09 05:24:49 +09:00
A per-site Analytics tab showing traffic and error analytics, computed on-demand from the site's Apache access log — Docker-correct. Architectural pivot: managed WP sites are wordpress:*-apache containers on localhost:PORT with NO per-site nginx, so the roadmap's "nginx access log" premise does not hold. The official image symlinks Apache's access log to the container's stdout, so `docker logs` is the source. New WpAnalyticsService.get_traffic(container_name, hours) pulls `docker logs --tail 20000 --since <h>` (hard 15s timeout; reads only stdout to separate the access log from the stderr error_log; returncode-checked so a stopped/missing/remote-agent container degrades to an accurate note) and parses the Apache combined log on-demand — no store, collector, or migration. Returns requests, unique visitors, bandwidth, status distribution (2xx/3xx/4xx/5xx), 404s, bot %, error rate, top URLs (grouped by route; query strings stripped so visitor tokens are never surfaced), and a continuous hourly requests/errors series. Route GET /sites/<id>/analytics?hours= (owner/admin-guarded), client getSiteAnalytics, and a new Analytics tab on the site detail (stat cards + a recharts requests/errors AreaChart + status codes + Top URLs) with graceful empty/timeout/unavailable states. Also supplies the 5xx/error-rate signal #27's "error spike" rule needs. Deferred (not in the default access log): PHP fatals (need wp-content/debug.log via a WP_DEBUG toggle, #30), response time / slow pages (need a %D LogFormat), cache hit ratio (#22/#23). History is point-in-time over the retained container log; a persistent time-series collector is a clean follow-up. Review fixes (3-lens): docker-logs timeout + memory cap (single-worker safety); accurate unavailable note via returncode; query-string token stripping. Verified: backend py_compile, frontend lint + build. Not runtime-exercised on a real Docker host (Windows dev). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
React Dashboard Template
A modern React dashboard application boilerplate built with Vite, featuring routing, charts, and a sidebar layout for building data-driven web interfaces.
Features
- React 18 with functional components and hooks
- Vite for fast development and building
- React Router for client-side routing
- Recharts for data visualization
- Lucide React for icons
- ESLint for code linting
- Responsive sidebar layout
- Dashboard page with sample components
Getting Started
Prerequisites
- Node.js 16+ and npm
Installation
- Clone or download this template
- Install dependencies:
npm install
Development
Start the development server:
npm run dev
The app will be available at http://localhost:41921.
Building for Production
Build the app for deployment:
npm run build
The output will be in the dist/ directory.
Preview Production Build
npm run preview
Project Structure
src/
├── App.jsx # Main app with routing
├── main.jsx # Entry point
├── index.css # Global styles
├── components/
│ └── Sidebar.jsx # Navigation sidebar
├── layouts/
│ └── DashboardLayout.jsx # Main layout wrapper
└── pages/
└── Dashboard.jsx # Main dashboard page
Customization
- Modify components in
src/components/ - Add new pages in
src/pages/ - Update routes in
App.jsx - Customize styles in
index.cssor component files
Environment Variables
Create a .env file in the root for environment variables:
VITE_API_URL=https://api.example.com
Access them in code via import.meta.env.VITE_API_URL.
Contributing
See the documentation files for AI agent permissions and guidelines.