Built-in ClickHouse database

In iBatyr Monitor there is an option to include the ClickHouse database.

Enabling ClickHouse allows you to create a hybrid operating mode for iBatyr Monitor: frequently used data is stored in ClickHouse, and other data is stored in PostgreSQL.

In practice, this hybrid mode can improve performance even on databases with hundreds of millions of records. During the pilot project, the speed of working with real data increased up to 50 times.

Additionally, ClickHouse requires:

  • hard disk space - about 50% of the Postgresql database size;

  • RAM, the consumption of which depends on the size of the database and the load.

Enabling the ClickHouse database

By default, iBatyr Monitor works with a PostgreSQL database. To enable ClickHouse and work in hybrid mode, run the command:

sudo ibatyr clickhouse-install

Note

During installation, the system will ask for a password for the ClickHouse database. Leave it blank.

To set a password or configure ClickHouse to work on another server, contact technical support service.

The installation script will download ClickHouse and install it on the system. After installation, the process of migrating the necessary data from Postgresql to ClickHouse will begin.

After installing ClickHouse and launching iBatyr Monitor in hybrid mode, the data in the constructor and some events will appear with a delay of 5-10 minutes from real time. At the same time, the overall performance of the system will increase. This will be especially noticeable if the iBatyr Monitor server is located on HDD drives.

The migration process on a large database may take some time. To track the progress of the migration, open the Administration section → Server status. This page will display the name of the policy and the number of events that have not yet been processed by this policy.

By default, policy processing runs once every 5 minutes. The page is automatically updated as soon as the number of events that need to be migrated to ClickHouse approaches zero. You can use the web interface to work with the new database.

After the migration is complete, an additional menu for switching the database operating mode will appear in the web interface:

Illustration 1 — Built-in ClickHouse database

Also in Menu → About the program you can see that the current database has changed from Postgresql to ClickHouse.

Illustration 2 — Built-in ClickHouse database

Note

On large databases (from 10 GB), the migration process to the hybrid operating mode can take up to several hours of objective time. During migration, events and reports may not be displayed in the administrator web interface.

Setting up SSL for ClickHouse

Username and Password

If a password was set or the user name was changed during ClickHouse installation, the block CLICKHOUSE = in the configuration file must look like:

CLICKHOUSE = {
    'URL': 'clickhouses://user:password@ip-address:port/ibatyr'
}

To set up a secure connection to the ClickHouse database:

  1. Configure ClickHouse to use OpenSSL.

  2. On the iBatyr Monitor server, open the configuration file /etc/ibatyr/config/.

  3. In the CLICKHOUSE = block, specify the server IP address and port for connection in the following form:

    CLICKHOUSE = {
         'URL': 'clickhouses://ip-address:port/ibatyr'
    }
    

If you do not specify the port number for connection, then port 9440 will be used - the default port for a secure connection.

Note

Please note that in the CLICKHOUSE = block you must specify the clickhouses scheme for a secure connection. The clickhouse scheme is used for an unsecured connection.

Disabling the ClickHouse database

To disable the hybrid mode of the iBatyr Monitor database, stop the Cliskhouse service:

sudo service clickhouse-server stop && sudo service ibatyr restart

To completely remove the database from the system, remove the ClickHouse package:

sudo service clickhouse-server stop && sudo apt-get -y purge clickhouse-server && sudo service ibatyr restart

If there is no connection to the ClickHouse database, iBatyr Monitor will work with PostgreSQL.

Allocating more memory for ClickHouse

To allocate additional memory to the database, open the file /etc/clickhouse-server/users.xml and in the line

<max_memory_usage>10000000000</max_memory_usage>

specify the size of memory in bytes that needs to be allocated for ClickHouse.

After increasing the database size, restart ibatyr services:

sudo service clickhouse-server restart
sudo ibatyr restart

Estimation of resources consumed by the ClickHouse database

To determine how much space is occupied by the database, run the following query:

sudo du -sm /var/lib/clickhouse/

The given figure will indicate the size of the ClickHouse database in megabytes.

To determine how much RAM the new database takes up, run the command:

sudo ps -aux | grep -i clickhouse-server | awk '{print $5}'

Advanced commands for managing ClickHouse in iBatyr Monitor