Server Handbook live check: run log ------------------------------------------------------------------------------ Tool https://serverhandbook.com/tools/ojs-statistics-charts Check scripts/live/checks/tool-ojs-statistics-charts.mjs (sha256 356cd5cebe634ddeee1146b8952dc26e2fc05e4b3c7db5302ad2cda3fc3995ed) Ran at 2026-12-05T09:10:25Z (306 s) Result PASS, all 28 claims held Tested on System Ubuntu 26.04.1 LTS Kernel 7.0.0-44-generic Package nginx 1.28.3-2ubuntu1.14 Package mariadb-server 1:11.8.6-5ubuntu0.1 Package php-fpm 2:8.5+99ubuntu1 Package ojs 3.5.0.6 Setup A fresh Ubuntu 26.04 server (4 GB of memory) with OJS 3.5.0.6 installed as lesson 1 of the OJS course installs it (Nginx, PHP-FPM, MariaDB, the files folder in /var/www/files; done by the check before the first step shown; the site name journal.example.com points to it through an /etc/hosts line, as your DNS would), reached over SSH as a sudo user. The journal holds two back issues (five articles, four PDFs) imported with importExport.php. Every version above was read from the server at run time. Passwords used on the throwaway test server are shown as [password]. How we test: https://serverhandbook.com/how-we-test ------------------------------------------------------------------------------ What the steps changed on the server (recorded before the first step and after the last) Packages added (0) Packages upgraded (22) bsdextrautils 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 bsdutils 1:2.41.3-3ubuntu2.2 -> 1:2.41.3-3ubuntu2.4 fdisk 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 git 1:2.53.0-1ubuntu1.1 -> 1:2.53.0-1ubuntu1.2 git-man 1:2.53.0-1ubuntu1.1 -> 1:2.53.0-1ubuntu1.2 libblkid1 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 libfdisk1 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 liblastlog2-2 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 libmount1 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 libnghttp2-14 1.68.0-2ubuntu0.2 -> 1.68.0-2ubuntu0.3 libsasl2-2 2.1.28+dfsg1-9ubuntu3 -> 2.1.28+dfsg1-9ubuntu3.1 libsasl2-modules 2.1.28+dfsg1-9ubuntu3 -> 2.1.28+dfsg1-9ubuntu3.1 libsasl2-modules-db 2.1.28+dfsg1-9ubuntu3 -> 2.1.28+dfsg1-9ubuntu3.1 libslang2 2.3.3-5build1 -> 2.3.3-5ubuntu0.1 libsmartcols1 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 libuuid1 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 login 1:4.16.0-2+really2.41.3-3ubuntu2.2 -> 1:4.16.0-2+really2.41.3-3ubuntu2.4 mount 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 rsync 3.4.1+ds1-7ubuntu0.3 -> 3.5.2+ds1-2ubuntu0.26.04.1 util-linux 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 util-linux-extra 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 uuid-runtime 2.41.3-3ubuntu2.2 -> 2.41.3-3ubuntu2.4 Packages removed (0) Services enabled at boot (0) Services disabled (1) chrony.service Listening sockets opened (0) Listening sockets closed (2) udp 127.0.0.1:323 chronyd udp [::1]:323 chronyd Files added in /etc (0) Files changed in /etc (0) Files removed from /etc (2) /etc/systemd/system/chronyd.service /etc/systemd/system/multi-user.target.wants/chrony.service Disk used on / (includes logs written during the run): +81.9 MB ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ Claims (28), each with what the run saw ------------------------------------------------------------------------------ 1. ok a bare Ubuntu 26.04 server box (web-server) starts 2. ok the tool refuses a report in another language, an .xlsx saved over a CSV and a header with no rows, and skips each broken row with its reason (local check: all pass) | PASS articles: read as the articles report, every row counted | PASS articles: totals [78,43] equal Python's sums [78,43] | PASS issues: read as the issues report, every row counted | PASS issues: totals [105,18] equal Python's sums [105,18] | PASS country: read as the country report, every row counted | PASS country: totals [121,70] equal Python's sums [121,70] | PASS timeline: read as the timeline report, every row counted | PASS timeline: totals [121] equal Python's sums [121] | PASS the Urdu and Chinese titles survive | PASS a quoted title with a comma and "" quotes is one cell | PASS articles sorted by total, most viewed first | PASS timeline in date order with the empty month kept | PASS a region report is read as regions, not merged into its country | PASS refused: an empty file | PASS refused: a binary file (an .xlsx saved over it) | PASS refused: a report in another language (French headers) | PASS refused: a header with no rows | PASS row skipped: a total that is not abstract + files | PASS row skipped: a number Excel turned into "1,204" | PASS row skipped: a row with a missing cell | PASS row skipped: a date Excel rewrote as 3/1/2026 | PASS row skipped: the same article twice | | all checks pass 3. ok (setup) the site name points to this server 4. ok (setup) Nginx, MariaDB, PHP-FPM and the PHP extensions 5. ok (setup) database and user ojs 6. ok (setup) OJS 3.5.0-6 from pkp.sfu.ca into /var/www/ojs 7. ok (setup) cache/, public/, config.inc.php for www-data 8. ok (setup) the Nginx server block 9. ok (setup) /var/www/files for www-data, mode 750 10. ok (setup) the web installer (posted with curl) 11. ok (setup) config.inc.php root:www-data 640 (the installer set allowed_hosts) 12. ok (setup) OJS is installed and its sign-in page answers | installed = On | 200 13. ok (setup) the journal "Example Journal" (/example) created through the API | {"_href":"http:\/\/journal.example.com\/index.php\/example\/api\/v1\/contexts\/1","abbreviation":{"en":""},"about":{"en":""},"acronym":{"en":"EJ"},"additionalHomeContent":{"en":""},"agencies":null,"announcementsIntroduction":{"en":""},"authorGuidelines":{"en":"

Authors are invited to make a submission to this journal. All submissions will be assessed by an editor to determine whether they meet the aims and scope of this journal. Those considered to be a good fit will be sent for peer review before determining whether they will be accepted or rejected.<\/p>

Before making a submission, autho 14. ok (setup) the sample back issues imported (two issues, five articles, four PDFs) | The import completed successfully. The following items were imported: 15. ok (setup) geo statistics set to country, region and city through the site settings API | "enableGeoUsageStats":"country+region+city" 16. ok OJS trusts X-Forwarded-For, geo statistics go to city level, and the geo database is in place (IPGeoDB.mmdb) | trust_x_forwarded_for = On | setting_name setting_value | enableGeoUsageStats country+region+city | keepDailyUsageStats 0 | total 120M | -rw-r--r-- 1 www-data www-data 120M Dec 5 09:12 IPGeoDB.mmdb 17. ok every visit answered 200 (45 requests) | 45 200 18. ok OJS logged 45 usage events in today’s log, with the country it found for the address | 45 usage_events_20261205.log | {'country': 'BR', 'region': 'SP', 'city': 'Pinheiros', 'userAgent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'} 19. ok UsageStatsLoader processed the day’s log (archived as usage_events_20261205.log) and no job is left | 2026-12-06 | Running [APP\tasks\UsageStatsLoader] .................................................................. 47.07ms DONE | | queue empty after 1 run(s) of jobs.php run | We have 0 queued jobs | usage_events_20261205.log 20. ok the metrics tables hold every scripted visit: 18 article page views, 16 downloads, 11 issue page views | submission_id abstract_views file_views | 1 7 4 | 2 5 4 | 3 3 0 | 4 2 4 | 5 1 4 | issue_id toc_views downloads | 1 4 0 | 2 7 0 | country region city total uniq | AU NSW Sydney 2 2 | BR SP Pinheiros 6 4 | JP 14 Fujisawa (Endō) 9 5 | NL Amsterdam (Amsterdam-Centrum) 4 4 | US CA Berkeley (North Berkeley) 7 5 | US CA Mountain View 5 4 | ZA WC Cape Town 1 1 21. ok and the geo table has views from more than one country | submission_id abstract_views file_views | 1 7 4 | 2 5 4 | 3 3 0 | 4 2 4 | 5 1 4 | issue_id toc_views downloads | 1 4 0 | 2 7 0 | country region city total uniq | AU NSW Sydney 2 2 | BR SP Pinheiros 6 4 | JP 14 Fujisawa (Endō) 9 5 | NL Amsterdam (Amsterdam-Centrum) 4 4 | US CA Berkeley (North Berkeley) 7 5 | US CA Mountain View 5 4 | ZA WC Cape Town 1 1 22. ok the stats API gave seven CSV reports (articles, files, timeline, countries, regions, cities, issues) | == articles.csv | | ID,Title,Authors,"Date Published",Total,"Abstract Views","File Views",PDF,HTML,Other | 1,"Soil moisture in dry seasons","Khan et al.",2019-06-30,11,7,4,4,0,0 | 2,"Groundwater recharge on terraced farms",Lopez,2019-06-30,9,5,4,4,0,0 | 4,"Water use in Punjab villages",احمد,2019-12-31,6,2,4,4,0,0 | 5,"Irrigation water in rice fields",王芳,2019-12-31,5,1,4,4,0,0 | 3,"Rainfall records 1990 to 2020: a review",Plato,2019-06-30,3,3,0,0,0,0 | == cities.csv | | City,Region,Country,Total,Unique | "Fujisawa (Endō)",Kanagawa,Japan,9,5 | "Berkeley (North Berkeley)",California,"United States",7,5 | Pinheiros,"São Paulo",Brazil,6,4 | "Mountain View",California,"United States",5,4 | "Amsterdam (Amsterdam-Centrum)",unknown,Netherlands,4,4 | Sydney,"New South Wales",Australia,2,2 | "Cape Town","Western Cape","South Africa",1,1 | == countries.csv | | Country,Total,Unique | "United States",12,9 | Japan,9,5 | Brazil,6,4 | Netherlands,4,4 | Australia,2,2 | "South Africa",1,1 | == files.csv | | "Article ID","Article Title","File ID","File Name",Type,"File Views" | 5,"Irrigation water in rice fields",4,论文-2.pdf,"Primary File",4 | 1,"Soil moisture in dry seasons",1,soil-moisture.pdf,"Primary File",4 | 2,"Groundwater recharge on terraced farms",2,groundwater.pdf,"Primary File",4 | 4,"Water use in Punjab villages",3,تحقیق-۱.pdf,"Primary File",4 | == issues.csv | | ID,"Issue identification",Total,Views,Downloads | 2,"Vol. 3 No. 2 (2019)",7,7,0 | 1,"Vol. 3 No. 1 (2019)",4,4,0 | == regions.csv | | Region,Country,Total,Unique | California,"United States",12,9 | Kanagawa,Japan,9,5 | "São Paulo",Brazil,6,4 | unknown,Netherlands,4,4 | "New South Wales",Australia,2,2 | "Western Cape","South Africa",1,1 | == timeline.csv | | Date,Label,Total | 2026-12,"December 2026",18 23. ok the tool reads all seven as the right report, every row counted, none skipped | {"articles":{"kind":"articles","totals":[18,16],"rows":5,"skipped":0},"cities":{"kind":"city","totals":[34,25],"rows":7,"skipped":0},"countries":{"kind":"country","totals":[34,25],"rows":6,"skipped":0},"files":{"kind":"files","totals":[16],"rows":4,"skipped":0},"issues":{"kind":"issues","totals":[11,0],"rows":2,"skipped":0},"regions":{"kind":"region","totals":[34,25],"rows":6,"skipped":0},"timeline":{"kind":"timeline","totals":[18],"rows":1,"skipped":0}} 24. ok articles: the tool’s abstract views and downloads, per article and in total (18, 16), equal metrics_submission | {"articles":{"kind":"articles","totals":[18,16],"rows":5,"skipped":0},"cities":{"kind":"city","totals":[34,25],"rows":7,"skipped":0},"countries":{"kind":"country","totals":[34,25],"rows":6,"skipped":0},"files":{"kind":"files","totals":[16],"rows":4,"skipped":0},"issues":{"kind":"issues","totals":[11,0],"rows":2,"skipped":0},"regions":{"kind":"region","totals":[34,25],"rows":6,"skipped":0},"timeline":{"kind":"timeline","totals":[18],"rows":1,"skipped":0}} 25. ok files: 16 downloads in the tool, as in metrics_submission; timeline: 18 views this month | {"articles":{"kind":"articles","totals":[18,16],"rows":5,"skipped":0},"cities":{"kind":"city","totals":[34,25],"rows":7,"skipped":0},"countries":{"kind":"country","totals":[34,25],"rows":6,"skipped":0},"files":{"kind":"files","totals":[16],"rows":4,"skipped":0},"issues":{"kind":"issues","totals":[11,0],"rows":2,"skipped":0},"regions":{"kind":"region","totals":[34,25],"rows":6,"skipped":0},"timeline":{"kind":"timeline","totals":[18],"rows":1,"skipped":0}} 26. ok countries, regions and cities: the tool’s total and unique equal metrics_submission_geo_monthly | {"articles":{"kind":"articles","totals":[18,16],"rows":5,"skipped":0},"cities":{"kind":"city","totals":[34,25],"rows":7,"skipped":0},"countries":{"kind":"country","totals":[34,25],"rows":6,"skipped":0},"files":{"kind":"files","totals":[16],"rows":4,"skipped":0},"issues":{"kind":"issues","totals":[11,0],"rows":2,"skipped":0},"regions":{"kind":"region","totals":[34,25],"rows":6,"skipped":0},"timeline":{"kind":"timeline","totals":[18],"rows":1,"skipped":0}} | [{"country":"AU","region":"NSW","city":"Sydney","total":2,"uniq":2},{"country":"BR","region":"SP","city":"Pinheiros","total":6,"uniq":4},{"country":"JP","region":"14","city":"Fujisawa (Endō)","total":9,"uniq":5},{"country":"NL","region":"","city":"Amsterdam (Amsterdam-Centrum)","total":4,"uniq":4},{"country":"US","region":"CA","city":"Berkeley (North Berkeley)","total":7,"uniq":5},{"country":"US","region":"CA","city":"Mountain View","total":5,"uniq":4},{"country":"ZA","region":"WC","city":"Cape Town","total":1,"uniq":1}] 27. ok issues: table of contents views per issue equal metrics_issue (4 and 7) | {"articles":{"kind":"articles","totals":[18,16],"rows":5,"skipped":0},"cities":{"kind":"city","totals":[34,25],"rows":7,"skipped":0},"countries":{"kind":"country","totals":[34,25],"rows":6,"skipped":0},"files":{"kind":"files","totals":[16],"rows":4,"skipped":0},"issues":{"kind":"issues","totals":[11,0],"rows":2,"skipped":0},"regions":{"kind":"region","totals":[34,25],"rows":6,"skipped":0},"timeline":{"kind":"timeline","totals":[18],"rows":1,"skipped":0}} | [[1,4,0],[2,7,0]] 28. ok (tested on) the box reports its OS, kernel and the version of 4 package(s) | PRETTY_NAME="Ubuntu 26.04.1 LTS" | VIRT=none | KERNEL=7.0.0-44-generic | PKG mariadb-server 1:11.8.6-5ubuntu0.1 | PKG nginx 1.28.3-2ubuntu1.14 | PKG php-fpm 2:8.5+99ubuntu1 | ojs: 3.5.0.6 ------------------------------------------------------------------------------ Commands and what they printed (6) ------------------------------------------------------------------------------ $ sudo sed -i 's/^trust_x_forwarded_for = Off/trust_x_forwarded_for = On/' /var/www/ojs/config.inc.php $ sudo grep -E '^trust_x_forwarded_for' /var/www/ojs/config.inc.php $ sudo mariadb -B ojs -e "SELECT setting_name, setting_value FROM site_settings WHERE setting_name IN ('enableGeoUsageStats', 'keepDailyUsageStats')" $ sudo ls -lh /var/www/files/usageStats/ trust_x_forwarded_for = On setting_name setting_value enableGeoUsageStats country+region+city keepDailyUsageStats 0 total 120M -rw-r--r-- 1 www-data www-data 120M Dec 5 09:12 IPGeoDB.mmdb $ IPS=(8.8.8.8 1.1.1.1 9.9.9.9 193.0.6.139 202.12.27.33 196.216.2.1 200.160.2.3) $ UA='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' $ GALLEYS=$(sudo mariadb -B ojs -e "SELECT p.submission_id, g.galley_id, g.submission_file_id FROM publication_galleys g JOIN publications p ON p.publication_id = g.publication_id ORDER BY 1" | tail -n +2 | tr '\t' '/') $ for i in 0 1 2 3 4 5 6; do $ get() { curl -s -o /dev/null -w "%{http_code}\n" -A "$UA" -H "X-Forwarded-For: ${IPS[$i]}" "$1"; } $ for s in $(seq 1 $((i % 5 + 1))); do get http://journal.example.com/index.php/example/article/view/$s; done $ if [ $((i % 2)) -eq 0 ]; then for g in $GALLEYS; do get http://journal.example.com/index.php/example/article/download/$g; done; fi $ if [ $i -lt 4 ]; then get http://journal.example.com/index.php/example/issue/view/1; fi $ get http://journal.example.com/index.php/example/issue/view/2 $ done | sort | uniq -c 45 200 $ sudo sh -c 'cd /var/www/files/usageStats/usageEventLogs && wc -l *.log' $ sudo sh -c 'tail -n 1 /var/www/files/usageStats/usageEventLogs/*.log' | python3 -c "import json,sys; e=json.loads(sys.stdin.read()); print({k: e[k] for k in ('country', 'region', 'city', 'userAgent')})" 45 usage_events_20261205.log {'country': 'BR', 'region': 'SP', 'city': 'Pinheiros', 'userAgent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'} $ sudo timedatectl set-ntp false && sudo date -s '+1 day' > /dev/null && date -u +%Y-%m-%d $ cd /var/www/ojs && sudo -u www-data php lib/pkp/tools/scheduler.php test --name='APP\tasks\UsageStatsLoader' 2>&1 | tail -n 3 $ for pass in 1 2 3 4 5 6 7 8 9 10; do sudo -u www-data php lib/pkp/tools/jobs.php run > /dev/null 2>&1; sudo -u www-data php lib/pkp/tools/jobs.php total 2>&1 | grep -q "We have 0 queued jobs" && break; done $ echo "queue empty after $pass run(s) of jobs.php run" $ sudo -u www-data php lib/pkp/tools/jobs.php total 2>&1 | grep -o "We have [0-9]* queued jobs" $ sudo ls /var/www/files/usageStats/archive/ 2026-12-06 Running [APP\tasks\UsageStatsLoader] .................................................................. 47.07ms DONE queue empty after 1 run(s) of jobs.php run We have 0 queued jobs usage_events_20261205.log $ sudo mariadb -B ojs -e "SELECT submission_id, SUM(IF(assoc_type = 1048585, metric, 0)) AS abstract_views, SUM(IF(assoc_type = 515, metric, 0)) AS file_views FROM metrics_submission GROUP BY submission_id ORDER BY 1" $ sudo mariadb -B ojs -e "SELECT issue_id, SUM(IF(issue_galley_id IS NULL, metric, 0)) AS toc_views, SUM(IF(issue_galley_id IS NULL, 0, metric)) AS downloads FROM metrics_issue GROUP BY issue_id ORDER BY 1" $ sudo mariadb -B ojs -e "SELECT country, region, city, SUM(metric) AS total, SUM(metric_unique) AS uniq FROM metrics_submission_geo_monthly GROUP BY country, region, city ORDER BY 1, 2, 3" submission_id abstract_views file_views 1 7 4 2 5 4 3 3 0 4 2 4 5 1 4 issue_id toc_views downloads 1 4 0 2 7 0 country region city total uniq AU NSW Sydney 2 2 BR SP Pinheiros 6 4 JP 14 Fujisawa (Endō) 9 5 NL Amsterdam (Amsterdam-Centrum) 4 4 US CA Berkeley (North Berkeley) 7 5 US CA Mountain View 5 4 ZA WC Cape Town 1 1 $ J=/tmp/j; rm -f $J $ LOGIN=$(curl -sL -c $J -b $J -o $J.html -w '%{url_effective}' http://journal.example.com/index.php/index/login) $ T=$(grep -oP 'name="csrfToken" value="\K[^"]+' $J.html) $ curl -s -c $J -b $J -o /dev/null --data-urlencode csrfToken=$T --data-urlencode username=admin --data-urlencode password='[password]' $LOGIN/signIn $ X=$(curl -sL -c $J -b $J http://journal.example.com/index.php/example/management/settings/website | grep -oP ' `sudo mariadb -B ojs -e "${sql}"` // public resolvers and registries' own addresses, in several countries; the server's geo database decides which const IPS = ['8.8.8.8', '1.1.1.1', '9.9.9.9', '193.0.6.139', '202.12.27.33', '196.216.2.1', '200.160.2.3'] const UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36' // sign in as the site admin (the form's CSRF token), keep the cookie in /tmp/j, the API's token in $X const SIGN_IN = [ 'J=/tmp/j; rm -f $J', `LOGIN=$(curl -sL -c $J -b $J -o $J.html -w '%{url_effective}' http://${SITE}/index.php/index/login)`, `T=$(grep -oP 'name="csrfToken" value="\\K[^"]+' $J.html)`, `curl -s -c $J -b $J -o /dev/null --data-urlencode csrfToken=$T --data-urlencode username=admin --data-urlencode password='${ADMIN_PASS}' $LOGIN/signIn`, `X=$(curl -sL -c $J -b $J ${H}/management/settings/website | grep -oP ' bareBox(ctx, async ({ sudoUser }) => { const sh = sudoUser() const { run, L } = sh // hidden, on this computer: the tool's own refusals, and the sample back issues to give the journal content const local = execFileSync('npx', ['tsx', TOOL], { encoding: 'utf8' }) ctx.check('the tool refuses a report in another language, an .xlsx saved over a CSV and a header with no rows, and skips each broken row with its reason (local check: all pass)', /all checks pass/.test(local) && !/^FAIL/m.test(local), local) const dir = mkdtempSync(join(tmpdir(), 'ojs-stats-')) const pdfs = join(dir, 'pdfs') execFileSync('mkdir', [pdfs]) for (const f of FILES) writeFileSync(join(pdfs, f), `%PDF-1.4\n% ${f}\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n2 0 obj << /Type /Pages /Kids [] /Count 0 >> endobj\ntrailer << /Root 1 0 R >>\n%%EOF\n`) const xml = join(dir, 'back-issues.xml') execFileSync('npx', ['tsx', IMPORTER, `--out=${xml}`, `--files=${pdfs}`], { encoding: 'utf8' }) installOjs(ctx, sh, { dbPass: DB_PASS, adminPass: ADMIN_PASS }) ctx.secret(ADMIN_PASS) createJournal(ctx, sh, { adminPass: ADMIN_PASS }) if (!putFile(xml, '/tmp/back-issues.xml')) throw new Error('could not copy the XML to the box') const imp = L(`cd /var/www/ojs && sudo -u www-data php tools/importExport.php NativeImportExportPlugin import /tmp/back-issues.xml example admin 2>&1 | grep -v 'PHP Notice: tempnam' | head -n 1`, 600000) if (!ctx.check('(setup) the sample back issues imported (two issues, five articles, four PDFs)', /The import completed successfully/.test(imp), imp)) throw new Error('setup failed: import') // ── statistics settings: geo to city level (Administration > Site Settings > Statistics), the proxy header ── const geo = L(`${SIGN_IN}\nXS=$(curl -sL -c $J -b $J http://${SITE}/index.php/index/admin/settings | grep -oP ' /dev/null && date -u +%Y-%m-%d", "cd /var/www/ojs && sudo -u www-data php lib/pkp/tools/scheduler.php test --name='APP\\tasks\\UsageStatsLoader' 2>&1 | tail -n 3", // the loader queues a chain of jobs: run the queue until it is empty, as the jobs worker would 'for pass in 1 2 3 4 5 6 7 8 9 10; do sudo -u www-data php lib/pkp/tools/jobs.php run > /dev/null 2>&1; sudo -u www-data php lib/pkp/tools/jobs.php total 2>&1 | grep -q "We have 0 queued jobs" && break; done', 'echo "queue empty after $pass run(s) of jobs.php run"', 'sudo -u www-data php lib/pkp/tools/jobs.php total 2>&1 | grep -o "We have [0-9]* queued jobs"', 'sudo ls /var/www/files/usageStats/archive/', ].join('\n'), { id: 'usage-stats-loader', timeout: 900000 }, ) ctx.check(`UsageStatsLoader processed the day’s log (archived as usage_events_${day.replaceAll('-', '')}.log) and no job is left`, load.out.includes(`usage_events_${day.replaceAll('-', '')}.log`) && /We have 0 queued jobs/.test(load.out) && !/failed/i.test(load.out), load.out) const metrics = run( [ DB('SELECT submission_id, SUM(IF(assoc_type = 1048585, metric, 0)) AS abstract_views, SUM(IF(assoc_type = 515, metric, 0)) AS file_views FROM metrics_submission GROUP BY submission_id ORDER BY 1'), DB('SELECT issue_id, SUM(IF(issue_galley_id IS NULL, metric, 0)) AS toc_views, SUM(IF(issue_galley_id IS NULL, 0, metric)) AS downloads FROM metrics_issue GROUP BY issue_id ORDER BY 1'), DB('SELECT country, region, city, SUM(metric) AS total, SUM(metric_unique) AS uniq FROM metrics_submission_geo_monthly GROUP BY country, region, city ORDER BY 1, 2, 3'), ].join('\n'), { id: 'metrics-tables' }, ) // three result sets, each after its header line const [subOut, issueOut, geoOut] = metrics.out.split(/^(?:submission_id|issue_id|country)\t.*$/m).slice(1) const nums = (text) => [...(text ?? '').matchAll(/^(\d+)\t(\d+)\t(\d+)$/gm)].map((m) => m.slice(1).map(Number)) const subs = nums(subOut) const absum = subs.reduce((n, r) => n + r[1], 0) const filesum = subs.reduce((n, r) => n + r[2], 0) const issues = nums(issueOut) const geoRows = [...(geoOut ?? '').matchAll(/^([A-Z]{2})\t([^\t]*)\t([^\t]*)\t(\d+)\t(\d+)$/gm)].map((m) => ({ country: m[1], region: m[2], city: m[3], total: Number(m[4]), uniq: Number(m[5]) })) ctx.check('the metrics tables hold every scripted visit: 18 article page views, 16 downloads, 11 issue page views', absum === 18 && filesum === 16 && issues.reduce((n, r) => n + r[1], 0) === 11, metrics.out) ctx.check('and the geo table has views from more than one country', new Set(geoRows.map((r) => r.country)).size > 1, metrics.out) // ── the reports, as Statistics > Download report gets them, read by the tool ────────── const month = `${day.slice(0, 7)}-01` const q = { timeline: `?dateStart=${month}&dateEnd=${day}`, default: `?dateStart=${month}&dateEnd=${day}` } const dl = run( [ SIGN_IN, 'mkdir -p /tmp/reports && cd /tmp/reports', ...REPORTS.map(([n, p]) => `curl -s -b $J -H 'Accept: text/csv' -o ${n}.csv '${H}/api/v1/${p}${q[n] ?? q.default}'`), 'for f in *.csv; do echo "== $f"; cat $f; done', ].join('\n'), { id: 'reports' }, ) ctx.check('the stats API gave seven CSV reports (articles, files, timeline, countries, regions, cities, issues)', (dl.out.match(/^== \w+\.csv$/gm) ?? []).length === 7, dl.out) const local2 = join(dir, 'reports') execFileSync('mkdir', [local2]) for (const [n] of REPORTS) writeFileSync(join(local2, `${n}.csv`), Buffer.from(L(`base64 -w0 /tmp/reports/${n}.csv`).trim(), 'base64')) const read = Object.fromEntries( execFileSync('npx', ['tsx', TOOL, ...readdirSync(local2).map((f) => `--read=${join(local2, f)}`)], { encoding: 'utf8' }) .trim() .split('\n') .map((l) => JSON.parse(l)) .map((r) => [r.file.split('/').pop().replace('.csv', ''), r]), ) const said = JSON.stringify(Object.fromEntries(Object.entries(read).map(([k, r]) => [k, r.error ?? { kind: r.report.kind, totals: r.report.totals, rows: r.report.rowsRead, skipped: r.report.skipped.length }]))) ctx.check('the tool reads all seven as the right report, every row counted, none skipped', REPORTS.every(([n]) => read[n]?.report && !read[n].report.skipped.length) && ['articles', 'files', 'timeline', 'country', 'region', 'city', 'issues'].every((k, i) => read[REPORTS[i][0]].report.kind === k), said) const R = (n) => read[n]?.report ?? { totals: [], bars: [] } const perArticle = subs.every(([id, a, f]) => R('articles').bars.some((b) => b[0] === String(id) && b[2] === a && b[3] === f)) ctx.check('articles: the tool’s abstract views and downloads, per article and in total (18, 16), equal metrics_submission', R('articles').totals.join() === `${absum},${filesum}` && perArticle, said) ctx.check('files: 16 downloads in the tool, as in metrics_submission; timeline: 18 views this month', R('files').totals.join() === String(filesum) && R('timeline').totals.join() === String(absum), said) const sum = (k) => geoRows.reduce((n, r) => n + r[k], 0) ctx.check('countries, regions and cities: the tool’s total and unique equal metrics_submission_geo_monthly', ['countries', 'regions', 'cities'].every((n) => R(n).totals.join() === `${sum('total')},${sum('uniq')}`) && R('countries').bars.length === new Set(geoRows.map((r) => r.country)).size, `${said}\n${JSON.stringify(geoRows)}`) ctx.check('issues: table of contents views per issue equal metrics_issue (4 and 7)', R('issues').totals.join() === `${issues.reduce((n, r) => n + r[1], 0)},${issues.reduce((n, r) => n + r[2], 0)}` && issues.every(([id, v]) => R('issues').bars.some((b) => b[0] === String(id) && b[2] === v)), `${said}\n${JSON.stringify(issues)}`) ctx.stepsDone() L('sudo timedatectl set-ntp true') const { packages, extra } = basePackages() reportBox(ctx, L, `${baseSetup(RELEASE)} The journal holds two back issues (five articles, four PDFs) imported with importExport.php.`, packages, extra) }) export default check