Database Reference
In-Depth Information
Metrics with Cassandra
As shown in the examples in this section, Cassandra is highly amenable
to capturing metric data using atomic counters. The one thing it lacks is
the ability to perform any form of server-side aggregation. In this case,
the recommended strategy is to produce all aggregates at write time
using batch updates.
To produce aggregates at both the customer level and at the system
level, use two tables for aggregation:
cqlsh:metrics> CREATE TABLE customer_counts (
customer_id INT,
metric TEXT,
ts TIMESTAMP,
value COUNTER,
PRIMARY KEY ( (customer_id,metric) , ts) )
WITH CLUSTERING ORDER BY (ts DESC);
cqlsh:metrics> CREATE TABLE system_counts (
metric TEXT,
ts TIMESTAMP,
value COUNTER, PRIMARY KEY ( metric , ts) )
WITH CLUSTERING ORDER BY (ts DESC);
To update each table, a BATCH command is used. This is not a
transaction, but it does allow Cassandra to perform an efficient update:
cqlsh:metrics> BEGIN COUNTER BATCH
... UPDATE customer_counts
SET value = value + 1
WHERE customer_id = 1
AND metric = 'impressions'
AND ts = '2013-12-01T00:00:00';
... UPDATE system_counts
SET value = value + 1
WHERE metric = 'impressions'
 
Search WWH ::




Custom Search