github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/docs/chunks-storage/running-chunks-storage-with-cassandra.md (about) 1 --- 2 title: "Running Cortex chunks storage with Cassandra" 3 linkTitle: "Running Cortex chunks storage with Cassandra" 4 weight: 2 5 slug: running-chunks-storage-with-cassandra 6 --- 7 8 **Warning: the chunks storage is deprecated. You're encouraged to use the [blocks storage](../blocks-storage/_index.md).** 9 10 This guide covers how to run a single local Cortex instance - with the [**chunks storage**](../chunks-storage/_index.md) engine - storing time series chunks and index in Cassandra. 11 12 In this guide we're going to: 13 14 1. Setup a locally running Cassandra 15 2. Configure Cortex to store chunks and index on Cassandra 16 3. Configure Prometheus to send series to Cortex 17 4. Configure Grafana to visualise metrics 18 19 ## Setup a locally running Cassandra 20 21 Run Cassandra with the following command: 22 23 ``` 24 docker run -d --name cassandra --rm -p 9042:9042 cassandra:3.11 25 ``` 26 27 Use Docker to execute the Cassandra Query Language (CQL) shell in the container: 28 29 ``` 30 docker exec -it <container_id> cqlsh 31 ``` 32 33 Create a new Cassandra keyspace for Cortex metrics: 34 35 A keyspace is an object that is used to hold column families, user defined types. A keyspace is like RDBMS database which contains column families, indexes, user defined types. 36 37 ``` 38 CREATE KEYSPACE cortex WITH replication = {'class':'SimpleStrategy', 'replication_factor' : 1}; 39 ``` 40 ## Configure Cortex to store chunks and index on Cassandra 41 42 Now, we have to configure Cortex to store the chunks and index in Cassandra. Create a config file called `single-process-config.yaml`, then add the content below. Make sure to replace the following placeholders: 43 - `LOCALHOST`: Addresses of your Cassandra instance. This can accept multiple addresses by passing them as comma separated values. 44 - `KEYSPACE`: The name of the Cassandra keyspace used to store the metrics. 45 46 `single-process-config.yaml` 47 ``` 48 # Configuration for running Cortex in single-process mode. 49 # This should not be used in production. It is only for getting started 50 # and development. 51 52 # Disable the requirement that every request to Cortex has a 53 # X-Scope-OrgID header. `fake` will be substituted in instead. 54 auth_enabled: false 55 56 server: 57 http_listen_port: 9009 58 59 # Configure the server to allow messages up to 100MB. 60 grpc_server_max_recv_msg_size: 104857600 61 grpc_server_max_send_msg_size: 104857600 62 grpc_server_max_concurrent_streams: 1000 63 64 distributor: 65 shard_by_all_labels: true 66 pool: 67 health_check_ingesters: true 68 69 ingester_client: 70 grpc_client_config: 71 # Configure the client to allow messages up to 100MB. 72 max_recv_msg_size: 104857600 73 max_send_msg_size: 104857600 74 grpc_compression: gzip 75 76 ingester: 77 lifecycler: 78 # The address to advertise for this ingester. Will be autodiscovered by 79 # looking up address on eth0 or en0; can be specified if this fails. 80 address: 127.0.0.1 81 82 # We want to start immediately and flush on shutdown. 83 join_after: 0 84 final_sleep: 0s 85 num_tokens: 512 86 87 # Use an in memory ring store, so we don't need to launch a Consul. 88 ring: 89 kvstore: 90 store: inmemory 91 replication_factor: 1 92 93 # Use cassandra as storage -for both index store and chunks store. 94 schema: 95 configs: 96 - from: 2019-07-29 97 store: cassandra 98 object_store: cassandra 99 schema: v10 100 index: 101 prefix: index_ 102 period: 168h 103 chunks: 104 prefix: chunk_ 105 period: 168h 106 107 storage: 108 cassandra: 109 addresses: LOCALHOST # configure cassandra addresses here. 110 keyspace: KEYSPACE # configure desired keyspace here. 111 ``` 112 113 The latest tag is not published for the Cortex docker image. Visit quay.io/repository/cortexproject/cortex 114 to find the latest stable version tag and use it in the command below (currently it is `v1.10.0`). 115 116 Run Cortex using the latest stable version: 117 118 ``` 119 docker run -d --name=cortex -v $(pwd)/single-process-config.yaml:/etc/single-process-config.yaml -p 9009:9009 quay.io/cortexproject/cortex:v1.10.0 -config.file=/etc/single-process-config.yaml 120 ``` 121 In case you prefer to run the master version, please follow this [documentation](./chunks-storage-getting-started.md) on how to build Cortex from source. 122 123 ### Configure the index and chunk table options 124 125 In order to create index and chunk tables on Cassandra, Cortex will use the default table options of your Cassandra. 126 If you want to configure the table options, use the `storage.cassandra.table_options` property or `cassandra.table-options` flag. 127 This configuration property is just `string` type and this value used as plain text on `WITH` option of table creation query. 128 It is recommended to enclose the value of `table_options` in double-quotes because you should enclose strings of table options in quotes on Cassandra. 129 130 For example, suppose the name of index(or chunk) table is 'test_table'. 131 Details about column definitions of the table are omitted. 132 If no table options configured, then Cortex will generate the query to create a table without a `WITH` clause to use default table options: 133 134 ``` 135 CREATE TABLE IF NOT EXISTS cortex.test_table (...) 136 ``` 137 138 If table options configured with `table_options` as below: 139 140 ``` 141 storage: 142 cassandra: 143 addresses: 127.0.0.1 144 keyspace: cortex 145 table_options: "gc_grace_seocnds = 86400 146 AND comments = 'this is a test table' 147 AND COMPACT STORAGE 148 AND caching = { 'keys': 'ALL', 'rows_per_partition': 1024 }" 149 ``` 150 151 Then Cortex will generate the query to create a table with a `WITH` clause as below: 152 153 ``` 154 CREATE TABLE IF NOT EXISTS cortex.test_table (...) WITH gc_grace_seocnds = 86400 AND comments = 'this is a test table' AND COMPACT STORAGE AND caching = { 'keys': 'ALL', 'rows_per_partition': 1024 } 155 ``` 156 157 Available settings of the table options on Cassandra depend on Cassandra version or storage which is compatible. 158 For details about table options, see the official document of storage you are using. 159 160 **WARNING**: Make sure there are no incorrect options and mistakes. Misconfigured table options may cause a failure in creating a table by [table-manager](../chunks-storage/table-manager.md) at runtime and seriously affect your Cortex. 161 162 ## Configure Prometheus to send series to Cortex 163 164 Now that Cortex is up, it should be running on `http://localhost:9009`. 165 166 Add the following section to your Prometheus configuration file. This will configure the remote write to send metrics to Cortex. 167 168 ``` 169 remote_write: 170 - url: http://localhost:9009/api/v1/push 171 ``` 172 ## Configure Grafana to visualise metrics 173 174 Run grafana to visualise metrics from Cortex: 175 176 ``` 177 docker run -d --name=grafana -p 3000:3000 grafana/grafana 178 ``` 179 180 Add a data source in Grafana by selecting Prometheus as the data source type and use the Cortex URL to query metrics: `http://localhost:9009/prometheus`. 181 182 Finally, You can monitor Cortex's reads & writes by creating the dashboard. If you're looking for ready to use dashboards, you can take a look at Grafana's [Cortex dashboards and alerts](https://github.com/grafana/cortex-jsonnet/) (Jsonnet) or Weaveworks's [Cortex dashboards](https://github.com/weaveworks/cortex-dashboards) (Python).