aboutsummaryrefslogtreecommitdiff
path: root/nixops/modules/websites/commons
diff options
context:
space:
mode:
authorIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 10:23:33 +0200
committerIsmaël Bouya <ismael.bouya@normalesup.org>2019-05-11 10:23:33 +0200
commit9eae2b47b7b315b05a0e010f3003bd875685e260 (patch)
tree43c9cfeb2db393f64743daa4ec87e0fe78ab772e /nixops/modules/websites/commons
parentb7ee93fcdee2509cd4c0caec2c5c59ccff5bab2c (diff)
downloadNix-9eae2b47b7b315b05a0e010f3003bd875685e260.tar.gz
Nix-9eae2b47b7b315b05a0e010f3003bd875685e260.tar.zst
Nix-9eae2b47b7b315b05a0e010f3003bd875685e260.zip
Move webstats outside of nixops
Diffstat (limited to 'nixops/modules/websites/commons')
-rw-r--r--nixops/modules/websites/commons/goaccess.conf99
-rw-r--r--nixops/modules/websites/commons/stats.nix69
2 files changed, 0 insertions, 168 deletions
diff --git a/nixops/modules/websites/commons/goaccess.conf b/nixops/modules/websites/commons/goaccess.conf
deleted file mode 100644
index 4918988..0000000
--- a/nixops/modules/websites/commons/goaccess.conf
+++ /dev/null
@@ -1,99 +0,0 @@
1time-format %H:%M:%S
2date-format %d/%b/%Y
3
4#sur immae.eu
5#log-format %v %h %^[%d:%t %^] "%r" %s %b "%R" "%u" $^
6
7log-format VCOMBINED
8#= %v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
9
10html-prefs {"theme":"bright","layout":"vertical"}
11
12exclude-ip 188.165.209.148
13exclude-ip 178.33.252.96
14exclude-ip 2001:41d0:2:9c94::1
15exclude-ip 2001:41d0:2:9c94::
16exclude-ip 176.9.151.89
17exclude-ip 2a01:4f8:160:3445::
18exclude-ip 82.255.56.72
19
20no-query-string true
21
22keep-db-files true
23load-from-disk true
24db-path @dbPath@
25
26ignore-panel REFERRERS
27ignore-panel KEYPHRASES
28
29static-file .css
30static-file .js
31static-file .jpg
32static-file .png
33static-file .gif
34static-file .ico
35static-file .jpeg
36static-file .pdf
37static-file .csv
38static-file .mpeg
39static-file .mpg
40static-file .swf
41static-file .woff
42static-file .woff2
43static-file .xls
44static-file .xlsx
45static-file .doc
46static-file .docx
47static-file .ppt
48static-file .pptx
49static-file .txt
50static-file .zip
51static-file .ogg
52static-file .mp3
53static-file .mp4
54static-file .exe
55static-file .iso
56static-file .gz
57static-file .rar
58static-file .svg
59static-file .bmp
60static-file .tar
61static-file .tgz
62static-file .tiff
63static-file .tif
64static-file .ttf
65static-file .flv
66#static-file .less
67#static-file .ac3
68#static-file .avi
69#static-file .bz2
70#static-file .class
71#static-file .cue
72#static-file .dae
73#static-file .dat
74#static-file .dts
75#static-file .ejs
76#static-file .eot
77#static-file .eps
78#static-file .img
79#static-file .jar
80#static-file .map
81#static-file .mid
82#static-file .midi
83#static-file .ogv
84#static-file .webm
85#static-file .mkv
86#static-file .odp
87#static-file .ods
88#static-file .odt
89#static-file .otf
90#static-file .pict
91#static-file .pls
92#static-file .ps
93#static-file .qt
94#static-file .rm
95#static-file .svgz
96#static-file .wav
97#static-file .webp
98
99
diff --git a/nixops/modules/websites/commons/stats.nix b/nixops/modules/websites/commons/stats.nix
deleted file mode 100644
index 73595f1..0000000
--- a/nixops/modules/websites/commons/stats.nix
+++ /dev/null
@@ -1,69 +0,0 @@
1{ lib, pkgs, config, mylibs, ... }:
2let
3 cfg = config.services.myWebsites.commons.stats;
4in {
5 options = {
6 services.myWebsites.commons.stats = {
7 enable = lib.mkEnableOption "enable statistics";
8 sites = lib.mkOption {
9 type = lib.types.listOf (lib.types.submodule {
10 options = {
11 conf = lib.mkOption {
12 type = lib.types.nullOr lib.types.path;
13 default = null;
14 };
15 name = lib.mkOption { type = lib.types.string; };
16 };
17 });
18 default = [];
19 description = "Sites to generate stats";
20 };
21 };
22 };
23
24 config = lib.mkIf cfg.enable {
25 users.users.root.packages = [
26 pkgs.goaccess
27 ];
28
29 services.cron = {
30 enable = true;
31 systemCronJobs = let
32 stats = domain: conf: let
33 config = if builtins.isNull conf
34 then pkgs.runCommand "goaccess.conf" {
35 dbPath = "/var/lib/goaccess/${domain}";
36 } "substituteAll ${./goaccess.conf} $out"
37 else conf;
38 d = pkgs.writeScriptBin "stats-${domain}" ''
39 #!${pkgs.stdenv.shell}
40 set -e
41 shopt -s nullglob
42 date_regex=$(LC_ALL=C date -d yesterday +'%d\/%b\/%Y')
43 TMPFILE=$(mktemp)
44 trap "rm -f $TMPFILE" EXIT
45
46 cat /var/log/httpd/access_log-${domain} | sed -n "/\\[$date_regex/ p" > $TMPFILE
47 for i in /var/log/httpd/access_log-${domain}*.gz; do
48 zcat "$i" | sed -n "/\\[$date_regex/ p" >> $TMPFILE
49 done
50 ${pkgs.goaccess}/bin/goaccess $TMPFILE --no-progress -o /var/lib/goaccess/${domain}/index.html -p ${config}
51 '';
52 in "${d}/bin/stats-${domain}";
53 allStats = sites: pkgs.writeScript "stats" ''
54 #!${pkgs.stdenv.shell}
55
56 ${builtins.concatStringsSep "\n" (map (v: stats v.name v.conf) sites)}
57 '';
58 in
59 [
60 "5 0 * * * root ${allStats cfg.sites}"
61 ];
62 };
63
64 system.activationScripts.goaccess = ''
65 mkdir -p /var/lib/goaccess
66 '' +
67 builtins.concatStringsSep "\n" (map (v: "mkdir -p /var/lib/goaccess/${v.name}") cfg.sites);
68 };
69}