我設計下表來存儲服務器警報:造型卡桑德拉表
create table IF NOT EXISTS host_alerts(
unique_key text,
host_id text,
occur_time timestamp,
clear_time timestamp,
last_occur timestamp,
alarm_name text,
primary key (unique_key,host_id,clear_time)
);
讓我們輸入一些數據:
truncate host_alerts;
insert into host_alerts(unique_key,host_id,alarm_name,
clear_time,occur_time,last_occur
)
values('1','server-1','disk failure',
'1970-01-01 00:00:00+0530','2015-07-01 00:00:00+0530','2015-07-01 00:01:00+0530');
insert into host_alerts(unique_key,host_id,alarm_name,
clear_time,occur_time,last_occur
)
values('1','server-1','disk failure',
'1970-01-01 00:00:00+0530','2015-07-01 00:00:00+0530','2015-07-01 00:02:00+0530');
insert into host_alerts(unique_key,host_id,alarm_name,
clear_time,occur_time,last_occur
)
values('1','server-1','disk failure',
'2015-07-01 00:02:00+0530','2015-07-01 00:00:00+0530','2015-07-01 00:02:00+0530');
查詢我的應用程序將運行是:
//All alarms which are **not cleared** for host_id
select * from host_alerts where host_id = 'server-1' and clear_time = '1970-01-01 00:00:00+0530';
//All alarms which are cleared for host_id
select * from host_alerts where host_id = 'server-1' and clear_time > '2015-07-01 00:00:00+0530';
//All alarms between first occurrence
select * from host_alerts where host_id = 'server-1'
and occur_time > '2015-07-01 00:02:00+0530'and occur_time < '2015-07-01 00:05:00+0530';
我不知道我是否應該準備更多的表格示例:host_alerts_by_hostname 或host_alerts_by_cleartime等等,或者乾脆添加集羣索引。 作爲唯一的ID是唯一的獨特列,但我需要從另一列retrive數據
不清零報警:「1970-01-01 00:00:00 + 0530」清除事件有一定的日期值。
HOST_ID是服務器名稱
occur_time是當事件已發生。
last_occur是當事件再次reoccured時間。
alarm_name是什麼與系統happend。
如何建模我的表,以便我可以執行這些查詢和基於unique_id更新?與我已經嘗試選擇是不可能的,並在upsert期間爲同一個unique_key創建新行。
非常感謝你的回答unique_key是在rdbms中生成的隨機密鑰。 cassandra是否具有自動複製表間數據的功能?我需要每次檢查clear_time字段,它是否會減慢性能?另外,第三個我認爲你的意思是happen_time? – kinkajou
我該如何爲每秒100-1000次報警? – kinkajou
Cassandra 3.0將支持物化視圖,以將數據從一個表傳播到另一個表,但該版本暫時不可用。我不明白你每次檢查clear_time的意思。您希望避免在Cassandra中寫入之前進行讀取,因爲它會大大降低事務吞吐量。 –