我设计了以下表来存储服务器警报:
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是唯一的唯一列,但我需要从其他列中检索数据
未清除警报: &#39; 1970-01-01 00:00:00 + 0530&#39;已清除的事件有一些日期值。
host_id 是服务器名称
occurrence _时间 是事件发生的时间。
last_occur 是事件再次重新修复的时间。
alarm_name 是系统发生的事情。
我如何对我的表进行建模,以便我可以根据unique_id执行这些查询和更新?使用我所尝试的选择是不可能的,并且在upsert期间为同一unique_key创建新行。< / p>