Noctora
Running the agent
Keep php artisan nightwatch:agent running under Supervisor, systemd, Laravel Forge, Docker or another platform.
The agent, php artisan nightwatch:agent, has to run all the time. Your app doesn’t talk to Noctora directly. It hands each request’s data to the agent over a local connection, and the agent sends it on. If the agent stops, monitoring stops.
Restart the agent after you change its NIGHTWATCH_ settings or update laravel/nightwatch, since it keeps running with what it started with.
Supervisor
Section titled “Supervisor”Save this as /etc/supervisor/conf.d/nightwatch-agent.conf:
[program:nightwatch-agent]command=php /path/to/your-app/artisan nightwatch:agentdirectory=/path/to/your-appuser=www-dataautostart=trueautorestart=truestopasgroup=truekillasgroup=trueredirect_stderr=truestdout_logfile=/path/to/your-app/storage/logs/nightwatch-agent.logReplace /path/to/your-app and www-data with your app’s path and user, then load it:
sudo supervisorctl reread && sudo supervisorctl updatesudo supervisorctl status nightwatch-agentThe agent writes to storage/logs/nightwatch-agent.log. If it can’t sign in, the log says why. Restart it with sudo supervisorctl restart nightwatch-agent.
systemd
Section titled “systemd”Save this as /etc/systemd/system/nightwatch-agent.service:
[Unit]Description=Noctora Nightwatch agentAfter=network.target
[Service]User=www-dataWorkingDirectory=/path/to/your-appExecStart=/usr/bin/php /path/to/your-app/artisan nightwatch:agentRestart=alwaysRestartSec=5
[Install]WantedBy=multi-user.targetUse the full path to PHP (which php shows it). Then start it and enable it at boot:
sudo systemctl enable --now nightwatch-agentsudo systemctl status nightwatch-agentjournalctl -u nightwatch-agent -fRestart it with sudo systemctl restart nightwatch-agent.
Laravel Forge
Section titled “Laravel Forge”In your site’s environment settings, add:
NIGHTWATCH_TOKEN=your-environment-tokenNIGHTWATCH_BASE_URL=https://noctora.spectivis.com/appOn the server’s daemons page, add a daemon with the command php artisan nightwatch:agent, your site’s directory (for example /home/forge/your-site.com) and the user the site runs as. Forge starts it and keeps it running.
To report deploys, add this to the end of your deploy script:
$FORGE_PHP artisan nightwatch:deploySee Other records for what Noctora does with deployments.
Docker
Section titled “Docker”Run the agent as its own service from the same image as your app. Every container that runs your app’s code sends to it over the network.
services: app: image: your-app environment: NIGHTWATCH_TOKEN: your-environment-token NIGHTWATCH_INGEST_URI: nightwatch-agent:2407
queue: image: your-app command: php artisan queue:work environment: NIGHTWATCH_TOKEN: your-environment-token NIGHTWATCH_INGEST_URI: nightwatch-agent:2407
nightwatch-agent: image: your-app command: php artisan nightwatch:agent --listen-on=0.0.0.0:2407 restart: unless-stopped environment: NIGHTWATCH_TOKEN: your-environment-token NIGHTWATCH_BASE_URL: https://noctora.spectivis.com/app- The agent listens on port 2407 and signs in with the token and base URL.
- Every container that runs your app’s code, whether web, queue worker or scheduler, sets
NIGHTWATCH_INGEST_URIto the agent’s address. By default the package sends to127.0.0.1:2407, which inside a container is the container itself. - Every container uses the same
NIGHTWATCH_TOKEN.
Don’t publish port 2407 outside the Docker network. From an app container, php artisan nightwatch:status checks that the app reaches the agent. The same layout works in Docker Swarm, Kubernetes and similar: one agent service per Environment.
Serverless and other platforms
Section titled “Serverless and other platforms”The platform has to give you a process that runs all the time, and a network path from your app to it. If it runs background workers next to the web process, run the agent as one and follow the Docker layout.
On function-based platforms, where each request runs in a short-lived function, the agent has nowhere to keep running. Either run the agent on an always-on machine or container in the same private network and point NIGHTWATCH_INGEST_URI at it, or run that part of your app on a server or in containers. Keep the agent’s port private.
To turn monitoring off in an environment such as local development or CI, set NIGHTWATCH_ENABLED=false.
If you cache config
Section titled “If you cache config”The agent reads NIGHTWATCH_BASE_URL from its process environment. Laravel copies .env into that environment, but not once you’ve run php artisan config:cache or php artisan optimize. Then the agent ignores the .env value and tries to send to Laravel Nightwatch instead of Noctora.
Set the base URL on the process itself. Under Supervisor, add this line to the program:
environment=NIGHTWATCH_BASE_URL="https://noctora.spectivis.com/app"Under systemd, add this to the [Service] section, then run sudo systemctl daemon-reload && sudo systemctl restart nightwatch-agent:
Environment=NIGHTWATCH_BASE_URL=https://noctora.spectivis.com/appOn Forge, start the daemon with env NIGHTWATCH_BASE_URL=https://noctora.spectivis.com/app php artisan nightwatch:agent. php artisan nightwatch:deploy reads the variable the same way, so set it for your deploy script too.
Multiple Environments
Section titled “Multiple Environments”Each Environment has its own token, and the token decides where data goes. Give each deployment the token of its own Environment, and the same NIGHTWATCH_BASE_URL:
# production .envNIGHTWATCH_TOKEN=production-environment-token
# staging .envNIGHTWATCH_TOKEN=staging-environment-tokenDon’t share a token between deployments, or their data mixes in one Environment. Owners and Admins add Environments from the Application on the Organization’s Applications tab, and create each one’s token on its Settings page.