Request demo
  1. Docs
  2. MiStats
  3. Parameters and commands

Parameters and commands

By default, the service parameters are set in /etc/microimpuls/mistats/configuration.yaml. License - in /etc/microimpuls/mistats/license.yaml.

Environment variables

Some MiStats global server parameters can be redefined into environment variables in the file /etc/microimpuls/mistats.env.

  • MISTATS CONFIG PATH The path to the MiStats configuration. By default /etc/microimpuls/mistats/configuration.yaml.
  • MISTATS LICENSE PATH - a path to the license file. By default /etc/microimpuls/mistats/license.yaml.

Example:

MISTATS CONFIG PATH=/etc/microimpuls/mistats/configuration.yaml
MISTATS LICENSE PATH=/etc/microimpuls/mistats/license.yaml

MiStats base

Connect to a separate MiStats database on MySQL or PostgreSQL. Section MISTATS DATABASE.

  • HOST - base host.
  • PORT - base port.
  • NAME - base name.
  • USER - user.
  • PASSWORD - password.
  • DRIVER MySQL or PostgreSQL driver. For MySQL, the installation example is mysql.

Example for MySQL:

MISTATS DATABASE:
HOST: 127.0.0. 1st
PORT: 3306
NAME: mistats
USER: mistats
PASSWORD: .
DRIVER: mysql

ClickHouse

Section CLICKHOUSE.

  • HOST - ClickHouse host.
  • PORT - ClickHouse port. For a client on the same server, port 9000 is indicated in the installation example.
  • DATABASE - base name. In the installation example, this smarty stats.
  • USER - user.
  • PASSWORD - password.
  • READ POOL SIZE, WRITE POOL SIZE the size of the pools of connections for reading and writing.
  • READ COMPRESSION Compress when reading from ClickHouse.
  • TABLES TO CLEAR dictionary "table name: maximum age of rows in days" for cleaning.

Example:

CLICKHOUSE:
HOST: 127.0.0. 1st
Port: 9000
DATABASE: smarty stats
USER: smart
PASSWORD: 

Redis and queue

Redis is needed for the task queue. If established mistats-videoIt also accumulates video viewing tags until they are moved to permanent storage in ClickHouse. Section MISTATS REDIS.

  • HOST - Redis host.
  • PORT - Port Redis.
  • DBB - Redis base number.

Example:

MISTATS REDIS:
HOST: 127.0.0. 1ST
PORT: 6379
DB: 0

API

Section MISTATSexcept SMARTY. URL.

  • MISTATS.HOST The address at which the API receives requests.
  • MISTATS. PORT - API port. Default 8095.
  • MISTATS. UVICORN WORKERS The number of Uvicorn worker processes.
  • MISTATS.DEBUG - start the service in debugging mode.
  • SMARTY. URL - Smarty's basic URL. According to it, MiStats checks authkey video viewing tags. The default value is calculated for Smarty on the same server and port 8000. The actual URL of Smarty is recorded in the config.

Example:

MISTATS:
HOST: 0.0.0. 0
PORT: 8095
UVICORN WORKERS: 1
Smarty:
URL: http://127.0.0.1:8000

CORS

Its setting is required to send video tags directly from the client portal to the MiStats API. Section CORS.

  • ENABLED - includes CORS. By default true. To turn off the CORS, put falsely.
  • ALLOWED HOSTS - a list of portal sources from which requests are allowed. By default []: sources not permitted. ["*"] any source allows.
  • RESPONSES CACHE SECONDS How many seconds does the browser remember the CORS response and not ask for permission before each request? The recommended value is not set, you can not specify the parameter for installation.

Example:

CORS:
ENABLED: true
ALLOWED HOSTS:
- https://tv.example.com

License

File /etc/microimpuls/mistats/license.yaml. The content is generated in the personal account of the operator, it must be copied in its entirety.

Example:

KEY: "..."
client id:"
client name: "
valid until: 31.12.2026
features
...

Logs

Paths to files - section LOGS.

  • LOGS.LEVEL & #8212; logging level name: DEBUG, INFO, WARNING, ERROR, CRITICAL. By default: INFO
  • LOGS.MISTATS. ERROR FILE PATH - mistakes.
  • LOGS.MISTATS.ACCESS FILE PATH - access to the API.
  • LOGS.MISTATS.MISTATS FILE PATH - the main service log.
  • LOGS.MISTATS. COMMANDS FILE PATH - teams.
  • LOGS.DATABASE.LOGS ENABLED Logging SQL queries. By default falsely.
  • LOGS.DATABASE.LOGS FILE PATH - SQL request file. Write when LOGS ENABLED equal true.
  • LOGS.DATABASE.SLOW QUERY WARNING MS A threshold in milliseconds after which a slow request is written in a warning. It works if the value is greater than 0.

Example:

LOGS:
MISTATS:
ERROR FILE PATH: 
ACCESS FILE PATH: .
MISTATS FILE PATH: .
COMMANDS FILE PATH: 
DATABASE:
LOGS ENABLED: false

Authorization

Television tags from client devices first enter Smarty, and then unload from there to MiStats through the API /stats/push/which requires authorization with a token. Which token Smarty sends is set by the Smarty parameters below. On the MiStats side, this is a section AUTH.

  • AUTH.API.ENABLED This includes checking the API token. For production, leave it on.
  • AUTH.API.TOKENS dictionary of permissible tokens and service names.

JWT is required for MiStats admin.

  • AUTH. JWT.ENABLED This includes JWT authentication.
  • AUTH.JWT.SECRET KEY - JWT signature secret.
  • AUTH.JWT.ALGORITHM - JWT signature algorithm. By default HS256.
  • AUTH.JWT.ACCESS TOKEN EXPIRATION TIME the lifetime of the access token, in seconds.
  • AUTH.JWT.REFRESH TOKEN EXPIRATION TIME lifetime of the refresh token, in seconds.

Example:

AUTH:
API:
TOKENS:
: smarty
JWT:
ALGORITHM: HS256

Video viewing

The parameters are relevant for the installed package mistats-video. Tags are first accumulated in Redis, after which the scheduler at intervals VIDEO STATS COMPRESSOR. CALL INTERVAL SECONS queues up compression of completed intervals and their recording in ClickHouse.

  • VIDEO STATS COMPRESSOR. MAXIMUM MINUTES BETWEEN VIDEO CHECKPOINTS After how many minutes without new labels, the viewing is considered complete. By default 5. It should not be less than the interval push_stat_interval portal.
  • VIDEO STATS COMPRESSOR. PUSH CHUNK SIZE The size of the pack that the unfinished tags return to Redis. By default 1000.
  • VIDEO STATS COMPRESSOR. CHECKPOINTS TO PROCESS LIMIT How many labels are taken from Redis in one iteration of compression By default 10000.
  • VIDEO STATS COMPRESSOR. CALL INTERVAL SECONS - compression start interval, in seconds. By default 600.
  • VIDEO STATS COMPRESSOR. TIME LIMIT SECONDS The maximum time of one iteration of compression, in seconds. By default 60.
  • VIDEO STATS COMPRESSOR.RETRIES COUNT Number of repeated attempts in case of compression error. By default 2.
  • VIDEO STATS COMPRESSOR.RETRIES AFTER SECONDS pause before the next attempt, in seconds. By default 5.
  • VIDEO STATS COMPRESSOR.DONT RETRY AFTER SECONDS After how many seconds in the queue or at work do not repeat. By default 540.
  • SMARTY.VIDEO STATS AUTH ENABLED Check authkey in video viewing requests. Checking's on SMARTY. URL.
  • SMARTY. AUTH CACHE TTL how many seconds is a successful authkey check cached.
  • VIDEO STATS. COMPLETE VIEW MIN PERCENT The minimum percentage of duration from which viewing is considered complete. For a movie, it's a fraction of one movie per account, for a series, it's a fraction of each episode.

Example:

VIDEO STATS COMPRESSOR:
MAXIMUM MINUTES BETWEEN VIDEO CHECKPOINTS: 5
PUSH CHUNK SIZE: 1000
CHECKPOINTS TO PROCESS LIMIT: 10,000
CALL INTERVAL SECONDS: 600
TIME LIMIT SECONDS: 60
RETRIES COUNT: 2
RETRIES AFTER SECONDS: 5
DONT RETRY AFTER SECONDS: 540

Reports

  • VIDEO STATS REPORTS. TIME LIMIT SECONDS maximum time to generate a video report, in seconds.
  • VIDEO STATS REPORTS. AGE LIMIT SECONDS how many seconds can the task of such a report live in line.
  • SMART STATS. PROGRAM RATING LIMIT how many programs are included in the report program ratings report. Meaning null removes the restriction.
  • SMARTY STATS REPORTS TIME LIMIT SECONDS Maximum generation time of Smarty Stats report, in seconds.
  • SMARTY STATS REPORTS AGE LIMIT SECONDS how many seconds can the task of such a report live in line.

Smarty base

Section SMARTY DATABASE Connect to the Smarty database.

  • HOST, PORT, NAME, USER, PASSWORD - address, database name, user and password.
  • DRIVER - base driver.
  • SSL ENABLED - SSL when connected. Relevant to the driver mysql.

Task line

Section DRAMATIQ — queue configuration dramatiq.

  • MISTATS.PROCESS COUNT & #8212; number of Mistats queue processes. Default 2.
  • MISTATS.THREADS COUNT & #8212; number of threads per process. Default 8.
  • MISTATS.WORKER SHUTDOWN TIMEOUT SECONDS & #8212; how many seconds to wait for the workman to stop? Default is 75.

Smarty options related to MiStats

IN INSTALLED_APPS must be a module viewstatsThe Smarty license must contain it. After editing the config, you need to restart uWSGI.

Television tags from client devices first enter Smarty, and then unload from there to MiStats by the management team push stats.

  • VIEWSTATS MISTATS BASE URL MiStats API address, same host and port as MISTATS.HOST and MISTATS. PORT.
  • VIEWSTATS BUFFER MAX COUNT How many tags does Smarty store in its Redis before uploading them to MiStats? In the example installation 2500000.
  • VIEWSTATS MAXIMUM MINUTES BETWEEN INTERVALS How many minutes without continuing the TV viewing label is considered complete. Recommended value: 5as many minutes as in push_stat_interval by default. If the portal interval is increased, this value is raised and not left less than a new interval in minutes.
  • VIEWSTATS MISTATS USE NEW AUTH Selects the unloading authorization scheme in MiStats. Included sends a token from VIEWSTATS MISTATS API TOKEN headlined X-API-Token. Turned off uses VIEWSTATS MISTATS ACCESS TOKEN.
  • VIEWSTATS MISTATS API TOKEN - API token for the new scheme. The default value coincides with the record in AUTH.API.TOKENS on the MiStats side.
  • VIEWSTATS MISTATS ACCESS TOKEN token of the previous authorization scheme.

Portal

  • push_stat_interval - the interval of sending tags by the portal, in milliseconds. By default 300000That's 5 minutes. With the same period put cron push stats. Description of the parameter - in portal settings.
  • mistats api url MiStats API address for video viewing tags. It's for the device. An extra slash at the end of the address is acceptable. Video viewing tags go to this API directly, bypassing the Smarty API.

Teams

Utility mistats manage put together mistat-base into /usr/local/bin. mistat manage help it only shows commands of packets installed.

  • venv install creates an environment in /usr/share/microimpuls/venvs/mistats.
  • requirements - addictive.
  • venv remove - removes the environment.
  • version - displays packet, build and interpreter versions.
  • pip it causes the pip of the current environment.
  • start, stop, restart, status - manage services mistats, mistats queue and mistats scheduler.
  • migrate clickhouse - rolls migration ClickHouse. Flag -dry-run it shows unused migrations and does not change the base.
  • migrate mistats db - rolls migration base MiStats. Flag -dry-run it works the same way.
  • ttl --days N Specifies the storage period of data in ClickHouse tables, in days. Launched from root: sudo mistats manage ttl --days N.
  • cleanup Deletes lines that have already expired. Launched from root: sudo mistats manage cleanup.
  • compress videostats - once puts in line compression of video viewing labels, without waiting for the scheduler interval. We need to run mistats queue.
  • check - checks the interpreter, configuration, availability of Redis, ClickHouse and MiStats databases, migration status.
  • queue status - shows the status of the queue and the planner.
  • create user — creates a user in admin. Mandatory options: login, name, available-client. Optional: email, inactive (if — is transmitted; an inactive user will be created), superuser (If transferred, the user will have advanced features in the admin). The password is set interactively after the script is called.

Smarty teams that work with MiStats data:

  • push stats Uploads completed TV viewing tags from Smarty to MiStats. The cron interval coincides with push_stat_interval.

Selections and sorting by television are described in integration with MiStats:

  • create_channel_sorting_by_popularity - creates sorting channels by tv viewing.
  • create_channel_election_by_popularity - creates a selection of popular tv channels.
  • create_epg_election_by_popularity - creates a selection of popular television programs.
  • create vodpvr selection by popularity - creates a selection of popular films archive video library on television.
  • create video election by popularity - creates a selection of popular films and TV series on video viewing. The team is in Smarty 2.12. Description: In integration with Smarty.

Ready to launch your video service?

Request a personal demo and learn how Microimpuls can help your business

Functional cookies are required to submit the form — SmartCaptcha protection will not load without them.