View counts across nodes
From Exponential 6.0.15 the view counter (ezview_counter, $node.view_count) counts the page views of every node
that serves an installation, of every host of a siteaccess and of every web server in front, not only the access log
of the node it runs on. One node copies every node's logs and counts the copies; each copy keeps a resume state of
its own, and a node that takes over after a failover goes on where the other one stopped, without counting a line
twice.
This page is for administrators of a cluster (several web servers behind a load balancer) or of a server with several access logs per site. The whole setup, with every setting, the scheduling (Plesk, systemd, cron), rotation and troubleshooting, is in the guide View counts in a cluster.
In short
| Before 6.0.15 | From 6.0.15 | |
|---|---|---|
| Logs per siteaccess | one (StorageDir/LogFileName) | as many as needed (LogFiles[]) |
| Nodes | the node the cronjob runs on | every node of Nodes[], copied by exp:viewcount:collect |
| Who counts | every node that runs the cronjob | the node PrimaryCommand names |
| A state moved to another disk | read again from the first line | goes on from where it stopped (by the log's first line) |
| Existing settings | unchanged; a setting of an older form is read and noted |
What is new
logfile.ini [AccessLogFileSettings] LogFiles[]: more access logs of a siteaccess.logfile.ini [ViewCountSettings] Nodes[],NodeName,MirrorDir,PrimaryCommand,RemoteShell.exp:viewcount:collect(bin/php/expviewcountcollect.php): takes over the state of the node that counted before and copies every node's logs toMirrorDir/<node>/<path>(local logs with PHP, remote ones with rsync over ssh).exp:viewcount:updatereads the copies in cluster mode and runs only on the counting node (--forceanyway).- The cronjob parts
view_count_nodes(both),view_count_collectandview_count_copies(each half). - The log reader knows a log by its first line as well as by its inode (the event
moved), and the state of a copy is named by its path below the state folder, so a state fits every node. runcronjobs.phpand the two commands change to the installation when a hosting panel starts them elsewhere.
Settings
# settings/override/logfile.ini.append.php
[ViewCountSettings]
Nodes[]
Nodes[]=web1
Nodes[]=web2
PrimaryCommand=/usr/local/bin/xsh lb:site:primary www.example.com --is-me -q
# settings/siteaccess/site/logfile.ini.append.php
[AccessLogFileSettings]
StorageDir=/var/www/vhosts/system/www.example.com/logs
LogFileName=access_ssl_log
LogFiles[]=/var/log/vcc/example/site-access.logphp runcronjobs.php -q -s site view_count_nodes # every 15 minutes, on every nodeLimits
- The nodes are reached over
RemoteShell(ssh) and rsync as the user the run is for; it needs a key and read access to the logs, or the copy runs as root (view_count_collect) and the count as the site user (view_count_copies). - Lines a rotation takes away before they were copied are lost when the rotated file cannot be recognized
(Plesk's append to
.webstatand truncate); keep the interval short. - Older rotations are counted once by hand (
--log-filewith a--state-dirof their own).
Tests
tests/tests/kernel/classes/viewcount/expViewCountCollectorTest.php (several nodes and hosts, a log that grows, a
rotation, a state taken over from another node, the counting node) and expViewCountConfigurationTest.php (old
settings only, new only, both, the older form of LogFileName, Nodes[]), DB-less.
Related: View count statistics · Clustering overview · exp:viewcount:collect