工作中需要采集日志到hbase中,fluentd提供了插件fluentd-hbase,地址为https://github.com/Furyu/fluent-plugin-hbase
不过插件只支持固定表插入数据,而工作中需求是根据日志中接口名动态创建表,对应接口插入数据,hbase中的timestamp需要使用20120522151215格式,需要对hbase插件进行二次开发,动态表创建插入数据很容易实现,修改插件中的write函数即可,timestamp格式因为没有找到函数接口,只好修改thrift接口函数
hbase插件使用的是massive_record对hbase进行操作,因此找到该操作中的row.save函数进行修改
vim /usr/lib64/fluent/ruby/lib/ruby/gems/1.9.1/gems/massive_record-0.2.2/lib/massive_record/adapters/thrift/row.rb
修改attr_accessor :id, :column_families, :columns, :new_record, :table 为
attr_accessor :id, :column_families, :columns, :new_record, :table ,:timestamp
修改 @table.client.mutateRow(@table.name, id.to_s.dup.force_encoding(Encoding::BINARY), mutations).nil?
为
if @timestamp.nil?
@table.client.mutateRow(@table.name, id.to_s.dup.force_encoding(Encoding::BINARY), mutations).nil?
else
@table.client.mutateRowTs(@table.name, id.to_s.dup.force_encoding(Encoding::BINARY), mutations,@timestamp).nil?
即可。