[Feat] [4.x] Site Stats#1132
Draft
RichardAnderson wants to merge 4 commits into
Draft
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new GoAccess-based "log_analysis" service that produces per-site web statistics. When installed on a server, a hidden hourly root cron runs GoAccess against per-site Nginx/Caddy access logs, writes JSON reports to /var/lib/goaccess/data/{site_id}/{YYYY-MM}/, and exposes them through a new Site → Stats page with charts, top pages, referrers, status codes, and 404s. Sites get an enable/disable toggle in Settings; site lifecycle events write/cleanup per-site GoAccess configs automatically.
Changes:
- New
GoAccessservice handler (install/uninstall/version + cron-basedmanage()), plus genericcanBeManaged()/manage()onServiceInterface/AbstractServiceand a Re-sync action in the services list. - New
SiteStatsactions/jobs/events/listeners (SyncGoAccessServer,RenderSiteStatsConf,GetSiteStats,WriteSiteStatsConfJob,RefreshSiteStatsJob,CleanupSiteStatsJob,ResyncGoAccessJob,SiteCreated/DeletedEvent), aUpdateSiteStatsenable/disable action, and new controllers/routes (SiteStatsController,LogAnalysisController, stats toggle endpoints). - Frontend stats page with TanStack Query, socket-driven refresh, charts, and a settings toggle dialog; Nginx vhost template now writes a per-primary-domain access log; cron-jobs UI/API/policy now exclude hidden cron jobs while
SyncCronJobsleaves them alone.
Reviewed changes
Copilot reviewed 43 out of 47 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| app/Services/LogAnalysis/GoAccess/GoAccess.php | New GoAccess service handler with cron-based management. |
| app/Services/AbstractService.php, ServiceInterface.php | Adds canBeManaged()/manage() defaults using systemd. |
| app/Actions/Service/Manage.php | Uses canBeManaged() instead of unit() check; error message updated. |
| app/Jobs/Service/ManageJob.php | Delegates start/stop logic to the service handler. |
| app/Providers/ServiceTypeServiceProvider.php | Registers GoAccess as a log_analysis service. |
| app/Actions/SiteStats/SyncGoAccessServer.php | Provisions GoAccess dirs, scripts, per-site configs, and hidden cron. |
| app/Actions/SiteStats/RenderSiteStatsConf.php | Renders shell-var per-site config; rejects unsafe domains. |
| app/Actions/SiteStats/GetSiteStats.php | Reads/parses GoAccess JSON via SSH; caches on status token. |
| app/Actions/Site/UpdateSiteStats.php | Enables/disables stats and dispatches cleanup/write jobs. |
| app/Actions/Site/DeleteSite.php | Dispatches SiteDeletedEvent after row delete. |
| app/Jobs/Site/{WriteSiteStatsConf,RefreshSiteStats,CleanupSiteStats,ResyncGoAccess}Job.php | New queued jobs for stats lifecycle. |
| app/Jobs/Site/CreateJob.php | Dispatches SiteCreatedEvent post-install. |
| app/Events/SiteCreatedEvent.php, SiteDeletedEvent.php | New events. |
| app/Listeners/HandleSiteCreatedStats.php, HandleSiteDeletedStats.php | Wire stats write/cleanup on site lifecycle. |
| app/Providers/AppServiceProvider.php | Registers the new listeners. |
| app/Models/Site.php | statsEnabled() helper. |
| app/Http/Resources/SiteResource.php | Exposes stats_enabled. |
| app/Http/Controllers/SiteStatsController.php, LogAnalysisController.php, SiteSettingController.php | New stats routes + enable/disable endpoints. |
| app/Http/Controllers/CronJobController.php, API/CronJobController.php | Hide hidden cron jobs from listings. |
| app/Policies/CronJobPolicy.php | Denies view/update/delete on hidden cron jobs. |
| app/Actions/CronJob/SyncCronJobs.php | Excludes hidden crons from server-level sync logic. |
| resources/views/ssh/services/log_analysis/goaccess/*.blade.php | GoAccess install/uninstall + run.sh/process.sh Blade templates. |
| resources/views/ssh/services/webserver/nginx/vhost.mustache | Enables per-primary-domain Nginx access log. |
| resources/js/pages/sites/stats.tsx + components/{use-site-stats,stats-chart}.tsx | New stats page, query hook, and chart component. |
| resources/js/pages/site-settings/{index.tsx, components/stats-toggle.tsx} | Settings entry + enable/disable dialog. |
| resources/js/pages/services/components/{columns.tsx, resync-stats.tsx} | Adds Re-sync action for log_analysis services. |
| resources/js/layouts/server/layout.tsx | Adds Site → Stats nav item (gated). |
| resources/js/types/site.d.ts, site-stats.d.ts | Types for new fields/response shape. |
| tests/Feature/SiteStatsTest.php | Comprehensive feature tests for stats. |
| tests/Feature/ServicesTest.php | Adds GoAccess to install data provider. |
Comment on lines
+84
to
+85
| } elseif ($cron->status !== CronjobStatus::READY) { | ||
| $cron->update(['status' => CronjobStatus::READY]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new "Service" -> GoAccess.
When installed, "Stats" appear per site.
Server -> Services -> Install (GoAccess)
Site -> Site Stats -> Refresh
Site -> Settings -> Statistics -> Enable/Disable
Stats updated every hour using GoAccess. Manual refresh via the stats page. Disabling stats on a site stops the logs from being analysed.