Configuring Managed Service for ClickHouse® for Graphite
You can use Yandex Managed Service for ClickHouse® to store Graphite
The GraphiteMergeTree
Note
If thinning, aggregation, or averaging, are not required, you can use any ClickHouse® table engine
To configure a database to work with Graphite:
- Set up your environment.
- Create a cluster.
- Register the rollup configuration in the cluster.
- Create and configure a virtual machine.
- Connect your virtual machine to the database.
- Create a GraphiteMergeTree table.
- Configure Graphite.
If you no longer need the resources you created, delete them.
Set up your environment
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The cost of maintaining your ClickHouse® database for Graphite includes:
- Fee for the cluster computing resources, storage, and backups (see Yandex Managed Service for ClickHouse® pricing).
- Fee for a running VM managing the database (see Yandex Compute Cloud pricing).
Create a cluster
- Create a Managed Service for ClickHouse® cluster with your preferred configuration with the
db1database and public access to all of its hosts. Save the database name, username, and password. - In the management console
, select Managed Service for ClickHouse® and navigate to your new cluster. Save the cluster ID from the Overview tab. - In the top-right corner, click Connect. In the Shell tab, save the
--hostvalue from the Sample connection string field, e.g.,rc1a-2sqal8f0********.mdb.yandexcloud.net. This is the cluster host’s FQDN you will need later on.
Register the rollup configuration in the cluster
Register the rollup configuration in your cluster for thinning, then aggregating or averaging Graphite data:
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Prepare the
graphite-rollup.yamlfile describingrollupparameters, e.g.:name: test_rollup patterns: - regexp: click_cost function: max retention: - age: 86400 precision: 60 -
Run this command:
yc managed-clickhouse cluster add-graphite-rollup <cluster_ID> --rollup-file-name <yaml_file_path>Where:
<cluster_ID>: Cluster ID.--rollup-file-name: Path tographite-rollup.yaml.
For more information about the
managed-clickhouse cluster add-graphite-rollupcommand, see the CLI reference.
Use the REST API update method, providing the required rollup parameters in the request body:
"graphiteRollup": [
{
"name": "test_rollup",
"patterns": [
{
"regexp": "click_cost",
"function": "max",
"retention": [
{
"age": "86400",
"precision": "60"
}
]
}
]
}
]
Create and configure a virtual machine
-
Create a Linux VM in your cluster’s cloud network.
-
Connect to the VM over SSH.
-
Add the ClickHouse® DEB repository
:sudo apt update && sudo apt install -y apt-transport-https ca-certificates dirmngr && \ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E0C56BD4 && \ echo "deb https://packages.clickhouse.com/deb stable main" | sudo tee \ /etc/apt/sources.list.d/clickhouse.list -
Install the dependencies and the
clickhouse-clientapplication:sudo apt update && sudo apt install -y clickhouse-client -
Download the
clickhouse-clientconfiguration file:mkdir -p ~/.clickhouse-client && \ wget "https://storage.yandexcloud.net/doc-files/clickhouse-client.conf.example" \ --output-document ~/.clickhouse-client/config.xml -
Get an SSL certificate:
sudo mkdir --parents /usr/local/share/ca-certificates/Yandex/ && \ sudo wget "https://storage.yandexcloud.net/cloud-certs/RootCA.pem" \ --output-document /usr/local/share/ca-certificates/Yandex/RootCA.crt && \ sudo chmod 655 /usr/local/share/ca-certificates/Yandex/RootCA.crt && \ sudo update-ca-certificates
Connect your virtual machine to the database
-
If using security groups for your cloud network, configure them to allow all required traffic between your cluster and VM.
-
Run the ClickHouse® CLI, replacing the following placeholders with your saved values:
<host_FQDN>,<DB_name>,<DB_user_name>, and<DB_user_password>.clickhouse-client --host <host_FQDN> \ --secure \ --user <DB_user_name> \ --database <DB_name> \ --password <DB_user_password> \ --port 9440
Create a table using the GraphiteMergeTree engine
To create a GraphiteMergeTreerollup section as a parameter:
CREATE TABLE GraphiteTable
(
Path String,
Time DateTime,
Value Int64,
Version UInt64
)
ENGINE = GraphiteMergeTree('test_rollup')
PARTITION BY Time
ORDER BY cityHash64(Version, Path)
Configure Graphite
Configure Graphite to store metrics in your ClickHouse® cluster. The ClickHouse® server will automatically handle data thinning based on your configured retention rules.
-
Install
carbon-clickhouseutility on your Graphite server:wget https://github.com/go-graphite/carbon-clickhouse/releases/download/v0.11.2/carbon-clickhouse_0.11.2_amd64.deb && \ sudo apt-get install $(pwd)/carbon-clickhouse_0.11.2_amd64.deb -
Configure
carbon-clickhouse. -
Run
carbon-clickhouse:sudo systemctl enable carbon-clickhouse && \ sudo systemctl start carbon-clickhouse -
Install
graphite-clickhouse:wget https://github.com/go-graphite/graphite-clickhouse/releases/download/v0.13.2/graphite-clickhouse_0.13.2_amd64.deb && \ sudo apt-get install $(pwd)/graphite-clickhouse_0.13.2_amd64.deb -
Configure
graphite-clickhouse. -
Run
graphite-clickhouse:sudo systemctl enable graphite-clickhouse && \ sudo systemctl start graphite-clickhouseFor more information on configuring Graphite, see these guides
.
How to delete the resources you created
To remove the rollup configuration from your cluster:
- Delete all the tables that use this configuration.
- Run the
yc managed-clickhouse cluster remove-graphite-rollupcommand.
For more information about this command, see the CLI reference.
Alert
Removing the rollup configuration without first deleting its dependent tables may result in cluster failure.
Delete the resources you no longer need to avoid paying for them:
ClickHouse® is a registered trademark of ClickHouse, Inc