嗨,据我所知,接口数据在写入方面并没有那么重,以至于需要按时间分区。它每小时仅更改一次,因此无需每小时保存最新版本的数据。另外我会假设你想以某种方式查询这个我不知道怎么做,所以我只会为接口提出一些一般性的建议,并将威胁作为时间序列数据的流:
create table interface(
iface_name text primary key,
iface_id int,
host text,
stamp timestamp
);
insert into interface(iface_name, iface_id, host, stamp) values ('Fa0/0', 19, '192.168.2.6', '2017-01-19 03:00:00');
insert into interface(iface_name, iface_id, host, stamp) values ('Fa0/1', 20, '192.168.2.6', '2017-01-19 03:00:00');
insert into interface(iface_name, iface_id, host, stamp) values ('Gi0/3', 20, '192.168.157.38', '2017-01-19 03:00:00');
通常这是与 cassandra 的反模式:
cqlsh:test> select * from interface;
iface_name | host | iface_id | stamp
------------+----------------+----------+---------------------------------
Fa0/0 | 192.168.2.6 | 19 | 2017-01-19 02:00:00.000000+0000
Gi0/3 | 192.168.157.38 | 20 | 2017-01-19 02:00:00.000000+0000
Fa0/1 | 192.168.2.6 | 20 | 2017-01-19 02:00:00.000000+0000
但据我所知,你没有那么多接口
所以基本上任何多达数千的东西都可以。在最坏的情况下,您可能想要
使用令牌功能从分区中获取数据,但问题是这会节省你
空间很大,您不需要按小时保存。
我也会简单地将这张表保存在内存中,然后在数据进入时丰富数据。
如果有更新,请更新内存缓存......但也将写入内容写入 cassandra。
如果出现故障,则只需从接口表恢复并继续。
基本上你的流量信息会变成
{
'stamp' : '2017-01-19 01:37:22'
'host' : '192.168.2.6',
'ip_src' : '10.29.78.3',
'ip_dst' : '8.8.4.4',
'iface_in' : 19,
'iface_out' : 20,
'iface_name' : 'key put from in memory cache',
}
这就是您将获得最大性能的方式现在节省流量只是
然后,时间序列数据,考虑到您正在访问集群
每秒有数千个,当你按时间分区时,你
每秒至少获得 7000 列(如果不是更多列)(使用模型
我在这里提议)通常你会想要多达 100 000 列
在单个分区内,这表示您的分区超出
理想的尺寸在 20 秒甚至更少,所以我什至建议使用
随机桶(插入时只使用定义范围内的一些数字
比方说 10):
create table flow(
time_with_minute text,
artificial_bucket int,
stamp timeuuid,
host text,
ip_src text,
ip_dst text,
iface_in int,
iface_out int,
iface_name text,
primary key((time_with_minute, artificial_bucket), stamp)
);
当想要随时间推移获取流时,您只需使用
一个时间戳加上同时进行 10 个查询或一个一个查询来访问所有数据。这里有各种技术,您只需要详细说明您的用例即可。
插入类似于:
insert into flow(time_with_minute, artificial_bucket, stamp, host, ip_src, ip_dst, iface_in, iface_out, iface_name)
values ('2017-01-19 01:37', 1, now(), '192.168.2.6', '10.29.78.3', '8.8.4.4', 19, 20, 'Fa0/0');
我现在只是举个例子,用https://github.com/apache/cassandra/blob/cassandra-2.1/src/java/org/apache/cassandra/utils/UUIDGen.java
使用插入流的时间生成 timeuuid。我也将 1 插入到人工桶中,在这里你将插入随机数,范围至少为 0-10。有些人,根据负载随机插入多个桶,甚至60个或更多。这完全取决于写入的重量。如果你只是每分钟一分钟,集群中的一组节点就会很热,并且会切换。拥有热节点通常不是一个好主意。
使用 cassandra,您正在编写您需要的信息,而不是在做
写入过程中的任何连接或类似的东西。将数据保存在您需要的内存中
用您需要的信息标记数据,然后直接插入而不进行非规范化。
您还可以以关系方式对解决方案进行建模,然后告诉您您希望如何
访问数据,然后我们可以深入了解。