-
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(website-analytics): add page with download statistics
Create https://admin.quick-lint-js.com/analytics/ which hosts two charts sourced from Apache access logs: daily unique downloaders and weekly unique downloaders.
- Loading branch information
Showing
39 changed files
with
2,907 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
41 changes: 41 additions & 0 deletions
41
...ructure/quick-lint-js-web-2/roles/analytics/files/quick-lint-js-website-analytics.service
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
[Unit] | ||
Description = Collect logs and update website analytics (https://admin.quick-lint-js.com/analytics/) | ||
|
||
[Service] | ||
Type = oneshot | ||
|
||
ExecStart = node src/import-apache-logs.mjs | ||
ExecStart = node src/import-matomo-logs.mjs | ||
ExecStart = node src/make-charts.mjs | ||
|
||
WorkingDirectory = /home/qljs-analytics/quick-lint-js-website-analytics/ | ||
User = qljs-analytics | ||
|
||
Restart = no | ||
TimeoutStartSec = 180min | ||
|
||
# Don't hinder user HTTP requests. | ||
Nice = 15 | ||
CPUSchedulingPolicy = batch | ||
IOSchedulingClass = idle | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
29 changes: 29 additions & 0 deletions
29
...structure/quick-lint-js-web-2/roles/analytics/files/quick-lint-js-website-analytics.timer
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
[Unit] | ||
Description = Collect logs and update website analytics regularly | ||
|
||
[Timer] | ||
OnCalendar = hourly | ||
RandomizedDelaySec = 10min | ||
|
||
Unit = quick-lint-js-website-analytics.service | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
27 changes: 27 additions & 0 deletions
27
infrastructure/quick-lint-js-web-2/roles/analytics/meta/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
dependencies: | ||
- acl | ||
- apache | ||
- matomo | ||
- nodejs | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
45 changes: 45 additions & 0 deletions
45
infrastructure/quick-lint-js-web-2/roles/analytics/tasks/install_website_analytics.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
- name: Create directory for quick-lint-js-website-analytics | ||
ansible.builtin.file: | ||
path: /home/qljs-analytics/quick-lint-js-website-analytics-{{ website_analytics_npm_package.stat.checksum }}/ | ||
owner: qljs-analytics | ||
group: qljs-analytics | ||
state: directory | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
- name: Copy quick-lint-js-website-analytics code | ||
ansible.builtin.unarchive: | ||
src: roles/analytics/temp/quick-lint-js-website-analytics.tar.gz | ||
dest: /home/qljs-analytics/quick-lint-js-website-analytics-{{ website_analytics_npm_package.stat.checksum }}/ | ||
unsafe_writes: true # Optimization. | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
- name: Install quick-lint-js-website-analytics machine-specific dependencies | ||
ansible.builtin.command: | ||
cmd: yarn install --production | ||
chdir: /home/qljs-analytics/quick-lint-js-website-analytics-{{ website_analytics_npm_package.stat.checksum }}/ | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
114 changes: 114 additions & 0 deletions
114
infrastructure/quick-lint-js-web-2/roles/analytics/tasks/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
- name: Create qljs-analytics user | ||
ansible.builtin.user: | ||
name: qljs-analytics | ||
home: /home/qljs-analytics | ||
create_home: true | ||
# Give the user read access to /var/log/apache2/. | ||
# FIXME(strager): This is probably insecure. 'adm' sounds like a | ||
# high-privilege group. | ||
groups: ["adm"] | ||
append: true | ||
become: true | ||
|
||
- name: Set up quick-lint-js-website-analytics code build (local) | ||
local_action: | ||
module: ansible.builtin.command | ||
chdir: ../../website/analytics/ | ||
cmd: yarn install --frozen-lockfile --dev | ||
|
||
- name: Build quick-lint-js-website-analytics code (local) | ||
local_action: | ||
module: ansible.builtin.command | ||
chdir: ../../website/analytics/ | ||
cmd: yarn run package ../../infrastructure/quick-lint-js-web-2/roles/analytics/temp/quick-lint-js-website-analytics.tar.gz | ||
|
||
- name: Compute quick-lint-js-website-analytics version (local) | ||
local_action: | ||
module: ansible.builtin.stat | ||
checksum_algorithm: sha1 | ||
get_attributes: false | ||
get_mime: false | ||
path: roles/analytics/temp/quick-lint-js-website-analytics.tar.gz | ||
register: website_analytics_npm_package | ||
|
||
- name: Check if quick-lint-js-website-analytics is installed | ||
ansible.builtin.stat: | ||
path: /home/qljs-analytics/quick-lint-js-website-analytics-{{ website_analytics_npm_package.stat.checksum }}/node_modules/better-sqlite3/build/Release/better_sqlite3.node | ||
register: website_analytics_installed_check | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
- name: Install quick-lint-js-website-analytics | ||
ansible.builtin.include_tasks: | ||
file: install_website_analytics.yml | ||
when: not website_analytics_installed_check.stat.exists | ||
|
||
- name: Create symlink pointing to the desired version of quick-lint-js-website-analytics | ||
ansible.builtin.file: | ||
src: /home/qljs-analytics/quick-lint-js-website-analytics-{{ website_analytics_npm_package.stat.checksum }}/ | ||
dest: /home/qljs-analytics/quick-lint-js-website-analytics | ||
owner: qljs-analytics | ||
group: qljs-analytics | ||
state: link | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
- name: Copy quick-lint-js-website-analytics config file | ||
ansible.builtin.template: | ||
src: quick-lint-js-website-analytics-config.json.j2 | ||
dest: /home/qljs-analytics/quick-lint-js-website-analytics/config.json | ||
owner: qljs-analytics | ||
group: qljs-analytics | ||
mode: "0600" | ||
become: true | ||
become_user: qljs-analytics | ||
|
||
- name: Create admin.quick-lint-js.com directory for quick-lint-js-website-analytics | ||
ansible.builtin.file: | ||
path: /var/www/admin.quick-lint-js.com/analytics/ | ||
owner: qljs-analytics | ||
group: www-data | ||
state: directory | ||
become: true | ||
# NOTE(strager): /var/www/ is root-owned, so we cannot become_user: qljs-analytics. | ||
|
||
- name: Install quick-lint-js-website-analytics services | ||
ansible.builtin.copy: | ||
src: "{{ item }}" | ||
dest: "/etc/systemd/system/{{ item }}" | ||
owner: root | ||
group: root | ||
mode: "0644" | ||
become: true | ||
loop: | ||
- quick-lint-js-website-analytics.service | ||
- quick-lint-js-website-analytics.timer | ||
|
||
- name: Start quick-lint-js-website-analytics services | ||
ansible.builtin.service: | ||
name: quick-lint-js-website-analytics.timer | ||
state: started | ||
enabled: yes | ||
become: true | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
3 changes: 3 additions & 0 deletions
3
infrastructure/quick-lint-js-web-2/roles/analytics/temp/.gitignore
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This directory is a staging area for 'yarn run package' in | ||
# ../../website/analytics. See ../tasks/main.yml. | ||
/quick-lint-js-website-analytics.tar.gz |
12 changes: 12 additions & 0 deletions
12
...ck-lint-js-web-2/roles/analytics/templates/quick-lint-js-website-analytics-config.json.j2
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"db.file": "/home/qljs-analytics/analytics.sqlite3", | ||
"chart.directory": "/var/www/admin.quick-lint-js.com/analytics/", | ||
|
||
"apache2.log_files": "/var/log/apache2/matomo_analytics.log*", | ||
|
||
"matomo_analytics.db_host": "localhost", | ||
"matomo_analytics.db_socket": null, | ||
"matomo_analytics.db_user": "matomo_analytics", | ||
"matomo_analytics.db_password": "{{ matomo_db_password }}", | ||
"matomo_analytics.db_database": "matomo_analytics" | ||
} |
Binary file not shown.
23 changes: 23 additions & 0 deletions
23
infrastructure/quick-lint-js-web-2/roles/nodejs/meta/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
dependencies: [] | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
51 changes: 51 additions & 0 deletions
51
infrastructure/quick-lint-js-web-2/roles/nodejs/tasks/main.yml
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
# Copyright (C) 2020 Matthew Glazar | ||
# See end of file for extended copyright information. | ||
|
||
# https://github.com/nodesource/distributions#ubuntu-versions | ||
- name: Install NodeSource GPG key | ||
ansible.builtin.copy: | ||
src: nodesource.gpg | ||
dest: /etc/apt/keyrings/nodesource.gpg | ||
owner: root | ||
group: root | ||
mode: '0644' | ||
become: true | ||
|
||
# https://github.com/nodesource/distributions#ubuntu-versions | ||
- name: Install NodeSource apt repository (Node.js 20.x) | ||
ansible.builtin.apt_repository: | ||
repo: "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" | ||
state: present | ||
filename: nodesource | ||
become: true | ||
|
||
- name: Install Node.js | ||
ansible.builtin.apt: | ||
name: | ||
- nodejs | ||
state: present | ||
become: true | ||
|
||
- name: Install Yarn | ||
ansible.builtin.command: | ||
cmd: npm install --global --no-save yarn | ||
become: true | ||
|
||
# quick-lint-js finds bugs in JavaScript programs. | ||
# Copyright (C) 2020 Matthew Glazar | ||
# | ||
# This file is part of quick-lint-js. | ||
# | ||
# quick-lint-js is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# quick-lint-js is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with quick-lint-js. If not, see <https://www.gnu.org/licenses/>. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Keep this file in sync with .npmignore. | ||
|
||
/node_modules/ | ||
|
||
/config.json | ||
|
||
# Described by /config.example.json: | ||
/analytics.sqlite3 | ||
/analytics.sqlite3-shm | ||
/analytics.sqlite3-wal | ||
/dist/ | ||
|
||
# Created by 'npm pack': | ||
/quick-lint-js-website-analytics-0.0.0.tgz |
Oops, something went wrong.