Skip to main content

Web Statistics and Analytics Package

Project description

Web Statistics and Analytics

This package produces web statistics and analytical output based on nginx access log files.

PyPI package version number Actions Status License

Downloads Python

Live Examples

Visit the live examples on logikfabrik.com.

Installation

pip install a9x-webstatistics

Requirements on Linux / Unix

  • access log file from web server
    • standard access log file from nginx, freenginx or apache
    • access log file in json format
  • python3.9 onwards
  • optional: maxmind db which need to be download by end user after registration

Deployment on Linux / Unix

#!/bin/sh

export LOG=/usr/local/www/webstats.log
export PATH=/usr/local/www/django5/envpy311/bin:$PATH

python3.11 -m a9x_webstatistics.main \
   --infile /var/log/nginx-access.log \
   --geoip /usr/local/share/GeoIP/GeoLite2-Country.mmdb \
   --domain https://www.logikfabrik.com \
   --statfile /usr/local/www/lf_static/webstatsLF24.json &> $LOG

python3.11 -m a9x_webstatistics.gencockpit \
   --infile /usr/local/www/lf_static/webstatsLF24.json \
   --outfile /usr/local/www/lf_static/webstatsLF24.html &>> $LOG

Cron-Job Entry for Linux / FreeBSD:

#minute hour    mday    month   wday    who     command
13,58   *       *       *       *       dj1     /usr/local/www/cronjobs/cron_webstatistics.sh

Installation on Windows

# install on windows:

## install a virtual env for python
python -m venv c:\temp\webstatsenv

## activate env
c:\temp\webstatsenv\Scripts\activate.bat

## install a9x-webstatistics
pip install a9x-webstatistics
python -m pip install --upgrade pip
python -m pip list

Deployment on Windows

# run
c:
cd \temp
wget -URI https://www.logikfabrik.com/wlog/access.log -OutFile access.log

## active env
c:\temp\webstatsenv\Scripts\activate.bat

## create calculate statistics
## there are no country statistics created as not geoip defined
python -m a9x_webstatistics.main --infile access.log --statfile webstatsLF.json

## create html file for webstatistics
python -m a9x_webstatistics.gencockpit --infile webstatsLF.json --outfile webstatsLF.html

Extended Example

#!/bin/sh

export LOG=/usr/local/www/webstats.log
export PATH=/usr/local/www/django5/envpy311/bin:$PATH

_YEARNUM="$(date +'%Y')";
_MONTHNUM="$(date +'%m')";

# make a archive copy for every month:
cp /usr/local/www/lf_static/webstatsLF24.json /usr/local/www/lf_static/webstatsLF24$_YEARNUM$_MONTHNUM.json
cp /usr/local/www/lf_static/webstatsLF24.html /usr/local/www/lf_static/webstatsLF24$_YEARNUM$_MONTHNUM.html

# updates all packages:
pip install -U `pip list --outdated | awk 'NR > 2 {print $1}'` >> $LOG


python3.11 -m a9x_webstatistics.main \
   --infile /var/log/nginx-access.log \
   --geoip /usr/local/share/GeoIP/GeoLite2-Country.mmdb \
   --domain https://www.logikfabrik.com \
   --statfile /usr/local/www/lf_static/webstatsLF24.json &> $LOG

python3.11 -m a9x_webstatistics.gencockpit \
   --infile /usr/local/www/lf_static/webstatsLF24.json \
   --outfile /usr/local/www/lf_static/webstatsLF24.html &>> $LOG

Supported Access Log Formats

Nginx Combined Format

predefined combined format: access_log /.../logs/nginx-access.log combined;

Nginx Json Format

log_format a9x_logs escape=json '{'
  '"tl":"$time_local",'
  '"ip":"$remote_addr",'                 # must; client IP
  '"rq":"$request_uri",'                 # must; full original request URI (with arguments)
  '"qs":"$query_string",'                # optional
  '"st":"$status",'                      # must; response status code
  '"ru":"$remote_user",'                 # optional; client HTTP username
  '"bs":"$bytes_sent", '                 # must; the number of bytes sent to a client
  '"rf":"$http_referer",'                # optional;
  '"rt":"$upstream_response_time", '     # optional; time spend receiving upstream body
  '"sc":"$scheme", '                     # optional; http or https
  '"ua":"$http_user_agent",'             # optional
  '"cs":"$upstream_cache_status",'       # optional
  '"al":"$http_accept_language",'        # optional
'}';

access_log     /.../log/nginx-access-log.json a9x_logs buffer=1k;

Apache Combined Format

CustomLog /.../log/apache2/apache_access.log combined

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

a9x_webstatistics-1.8.17b0.tar.gz (388.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

a9x_webstatistics-1.8.17b0-py3-none-any.whl (80.3 kB view details)

Uploaded Python 3

File details

Details for the file a9x_webstatistics-1.8.17b0.tar.gz.

File metadata

  • Download URL: a9x_webstatistics-1.8.17b0.tar.gz
  • Upload date:
  • Size: 388.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for a9x_webstatistics-1.8.17b0.tar.gz
Algorithm Hash digest
SHA256 e59bdbfc46f64275617d7707bc8682cb7a38cdcb59d9f7f873a0e87e3a3f41b8
MD5 4887c64b3be34fda422b03cfb8590293
BLAKE2b-256 3a09ec77d4681740d335512eb683f7a30277007d6ee93902a6a70afa8355de30

See more details on using hashes here.

File details

Details for the file a9x_webstatistics-1.8.17b0-py3-none-any.whl.

File metadata

File hashes

Hashes for a9x_webstatistics-1.8.17b0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cf955b027d7afad8ee9079a2e9a12634aa8c2c485680f249c10ffa1b8a5bf2c
MD5 fbbbc75950023083079ccd3e322ab1e1
BLAKE2b-256 1021c313bfee3e602ab453c416f93bc18f8c7e11a2fe2895627e296a278bfb31

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page