Server requirements
Minimum server requirements for Mistats installation:
- Processor: 4 cores with a frequency of more than 3.5 GHz
- RAM: 8GB
- ROM: 60 GB
Installation
To work MiStats you need to have the following software versions:
- Smarty >= 2.0
- ClickHouse >= 24
Note 1: ClickHouse requires support for SSE 4.2 CPU instructions
Note 2: recommended OS for ClickHouse — Debian 11
Before starting the installation, we recommend checking the time settings on the server. It is necessary that the established time zone on the server for MiStats coincides with the time zones on the servers on which Smarty and MongoDB are deployed.
You can check the time zone using the following command:
timedatectl | grep 'Time zone'
If the servers have different values of Time zone, then you can change it as follows (as an example, the time zone of Moscow is given: GMT+3):
timedatectl set-timezone Europe/Moscow
Check that the time zone has been changed:
$ timedatectl | grep 'Time zone'
Time zone: Europe/Moscow (MSK, +0300)
Installation of ClickHouse
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg pwgen python3-pip python-is-python3
curl -fsSL 'https://packages.clickhouse.com/rpm/lts/repodata/repomd.xml.key' | sudo gpg --dearmor -o /usr/share/keyrings/clickhouse-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] https://packages.clickhouse.com/deb stable main" | sudo tee \
/etc/apt/sources.list.d/clickhouse.list
sudo apt-get update
sudo apt-get install -y clickhouse-server clickhouse-client
sudo service clickhouse-server start
MiStats installation
Download the package is available in the Operator's Personal Account. After a successful download, you need to unpack the package and set the desired dependencies:
sudo dpkg -i mistats-*.deb pip install -r /usr/share/microimpuls/mistats/backend/requirements.txt
Next, you should configure the connection between Mistats and Clickhouse, the CLI opening command for Clickhouse:
ifClickhousemiStats are on the same serverclickhouse-client# if ClickHouse is on a dedicated server clickhouse-client --host --secure --port 9940 --user --password
Creation of DB and user:
create database smarty_stats;
export CHPASSWORD='pwgen -s 16'
echo $CHPASSWORD
echo "create user smarty identified by '$CHPASSWORD';" | clickhouse-client -d smarty_stats -u default --password
echo "create role smarty;" | clickhouse-client -d smarty_stats -u default --password
echo "grant all on smarty_stats.* to smarty;" | clickhouse-client -d smarty_stats -u default --password
echo "grant smarty to smarty;" | clickhouse-client -d smarty_stats -u default --password
sed -i -e 's/CH_PASSWORD = None/'"CH_PASSWORD = \"$CHPASSWORD\\""'/g' /usr/share/microimpuls/mistats/backend/settings/configuration.py
After all the actions, you need to edit the file /usr/share/microimpuls/mistats/backend/settings/configuration.py as follows:
CH_HOST = "localhost" # IP ClickHouse CH_PORT = None #ClickHouse Port CH_DATABASE = "smarty_stats" CH_USER = "smarty" # Account name CH_PASSWORD = $CHPASSWORD PORT = 8095 # The server host port to which statistics will be sent HOST = "0.0.0.0" # IP of the server host to which the statistics will be sent UVICORN_WORKERS = 2 # Number of Workshops LOG_LEVEL = "info" # Logging level
The following is the initialization of ClickHouse:
python /usr/share/microimpuls/mistats/backend/commands/init_db.py
Note 3: if there is an error at launch “No module named Clickhouse” a command must be executed at the terminalexport PYTHONPATH="/usr/share/microimpuls/mistats/backend"
And the actual launch of MiStats:
python /usr/share/microimpuls/mistats/backend/run.py
Next, you need to check whether there is a MiStats service in the system as a command:
sudo systemctl status mistat.service
If the service is not running, it should be started:
sudo systemctl start mistat.service
If the service was not found at all, then create a file for the background work of the process mistats.service file /etc/systemd/system with the following contents:
[Unit] Description=MiStats service After=network.target. [Service] Type=simple ExecStart=/usr/bin/python /usr/share/microimpuls/mistats/backend/run.py [Install] WantedBy=multi-user.target
After creating a service file, run commands:
sudo systemctl daemon reload sudo systemctl enable mistat.service
Configure the connection to MiStats on the Smarty side
In the Smarty configuration file in the section INSTALLED_APPS you need to add a parameter viewstats if the module viewstats not previously configured) and make sure that the license key allows the use of this module.
Next, you need to add connection options to MiStats to the configuration:
# адрес MiStats VIEWSTATS_MISTATS_BASE_URL = 'http://127.0.0.1:8000' # Количество записей в Redis, по достижении которого данные выгружаются в MiStats VIEWSTATS_BUFFER_MAX_COUNT = 2500000
To apply the settings, you need to restart the uWSGI:
sudo service uwsgi restart
Last step — add management commands to the crown to send data from Smarty to MiStats (recommended interval — 5 minutes):
smarty_manage push_stats --settings=settings.