- Notifications
You must be signed in to change notification settings - Fork 261
Best Practice
Andrewei edited this page Jan 2, 2018 · 12 revisions
- 可以写多份配置文件
- 可以使用file reader中的
tailx
模式: https://github.com/qiniu/logkit/wiki/File-Reader#tailx%E6%A8%A1%E5%BC%8F
- 在所有
parser
中都有一个label功能,这个功能可以用于填写机器编号,ip,服务名、团队名称等各种各样用于区别logkit数据来源的标签,这些标签会附加在logkit的日志中,便于在大的方向上定位日志来源。 - 如果是在tailx模式下,一个配置文件可以读多个路径,可以使用
datasource_tag
功能,将读取的日志路径作为一个字段记录在日志中
- sender模式(https://github.com/qiniu/logkit/wiki/Senders)中有一个
fault_tolerant
选项,默认是不开启的,开启后会使用磁盘队列进行容错,开启后需要填写容错的磁盘队列存储的位置,同时容错策略(ft_strategy)选择:"always_save", 此时数据就保证不重不漏了。 - 在开启磁盘队列后,数据就可以并发的发送,配置"ft_procs":"2",就是开2个并发发送,速度就能大大提升。
- 如果还嫌不够快怎么办?可以用内存队列替换磁盘队列噢,但是需要说明,使用内存队列在logkit 异常退出时有丢失数据的风险。
- 在有多个sender,并且希望sender之间互不影响的前提下,那么我们建议做成多份配置文件,而不是单份配置文件写多个sender。
- 如果多个reader,并且每个reader都不能遗漏日志,并且还需要删除日志,那么只要每一个reader都应该对应配置一个cleaner,那么多个cleaner会协作,由最后有个读取完成的cleaner来控制日志的删除。
- 在发送到Pandora的过程中,如果数据字段有增加,只要配置sender的
pandora_schema_free
为true即可,会自动识别并更新数据源的schema - 发送到Pandora的数据,类型不能被logkit自动判别怎么办? 此时在配置
pandora_schema_free
的情况下,再配置一下pandora_auto_create
, 只需要填写那些特殊的类型即可,比如jsonstring
,其他字段依旧可以通过pandora_schema_free
自动更新。比如:
"pandora_auto_create":"filedx jsonstring"
- Pandora不接受的字段名称如何处理呢? 在ELK中,常见的就是
@timestamp
,但是@
符号,pandora是不支持的,此时只要使用pandora_schema
字段配置一下pandora的别名即可。同样不支持的符号还包括中划线、竖线等,目前Pandora支持的符号是数字、字母以及下划线。 具体写法如下:
"pandora_schema":"@timestamp timestamp,..."
注意最后要填写,...
表示其他字段都要。因为 pandora_schema 除了别名功能以外,还支持字段的选择,如果不加",..."则表示其他字段都不选。
我们特意写了一个调试grok的教程,欢迎阅读:https://github.com/qiniu/logkit/wiki/Grok-Parser#%E5%A6%82%E4%BD%95%E8%B0%83%E8%AF%95%E6%82%A8%E7%9A%84grok-patterngrokdebug%E7%94%A8%E6%B3%95
如下为一份配置,“#”号标注指带有默认值
{ "name":"exportd.csv", #"batch_len": 1000, #"batch_size": 2097152, "reader":{ "log_path":"/path/to/log", #"meta_path":"./meta/{{.env}}/reader", # defalut: CURRENT_WORK_DIR/meta/<NAME-{hash(NAME)}>/ #"mode":"dir", #"ignore_hidden":"true", #"valid_file_pattern":"*" }, "parser":{ "name":"exportd_csv", "type":"csv", #"csv_splitter":"\t", "csv_schema":"logtype string, service string, timestamp long, tags jsonmap, fields jsonmap,unkown string", "labels":"machine {{.node}}" }, "senders":[{ "name":"pandora_sender", "sender_type":"pandora", "pandora_ak":"<your qiniu access key>", "pandora_sk":"<your qiniu secret key>", "pandora_host":"https://pipeline.qiniu.com", "pandora_repo_name":"<your pandora repo(工作流名称)>", "pandora_region":"nb", "pandora_schema_free":"true", "pandora_enable_logdb":"true", "fault_tolerant":"true", "ft_save_log_path":"./ft_log", "ft_strategy":"always_save", "ft_procs":"2" }] }
如果想把一个没有外网的集群中的日志发往 pandora 平台,只需要一台可以连外网的服务器,结合 logkit
的 http reader
和 http sender
即可做到。 具体方法如下:
- 在没有外网的服务器上,
logkit
都使用 http sender 将数据发往有外网的服务器上的logkit
- 在可以连外网的服务器上配置 http reader 和 pandora sender 将数据转发到 pandora 平台
注意事项:
- 该场景下,
http sender
请使用json
形式发送 - 采集的日志的
logkit
的 reader 中请填写datasource_tag
字段,以便可以标记日志来源, 作为中转的logkit
的pandora sender
中, 请将pandora_extra_info
字段置为false
。
例如,现有三台服务器,分别为服务器A(ip: 10.10.10.2/24), 服务器B(ip: 10.10.10.3/24), 服务器C(ip: 10.10.10.4/24), 其中服务器A和服务器B无法连接外网, 服务器C可以连接外网。现想要把服务器A、B上的日志发送到 pandora 平台,则各个服务器上 logkit 的配置示例如下:
- 服务器A:
{ "name":"serverA", "batch_len": 1000, "batch_size": 2097152, "reader":{ "datasource_tag": "serverA", ... 此处省略 }, "parser":{ ... 此处省略 }, "senders":[{ "name": "serverA_sender" "sender_type":"http", "http_sender_url": "10.10.10.4:4001/logkit/data", "http_sender_gzip": "true", "http_sender_protocol": "json" }] }
- 服务器B:
{ "name":"serverB", "batch_len": 1000, "batch_size": 2097152, "reader":{ "datasource_tag": "serverB", ... 此处省略 }, "parser":{ ... 此处省略 }, "senders":[{ "name": "serverB_sender" "sender_type":"http", "http_sender_url": "10.10.10.4:4001/logkit/data", "http_sender_gzip": "true", "http_sender_protocol": "json" }] }
- 服务器C:
{ "name":"serverC", "batch_len": 1000, "batch_size": 2097152, "reader":{ "mode": "http", "http_service_address": ":4001", "http_service_path": "/logkit/data" }, "parser":{ "type": "json", "name": "serverC_parser" }, "senders":[{ "name":"pandora_sender", "sender_type":"pandora", "pandora_ak":"<your qiniu access key>", "pandora_sk":"<your qiniu secret key>", "pandora_host":"https://pipeline.qiniu.com", "pandora_repo_name":"<your pandora repo(工作流名称)>", "pandora_region":"nb", "pandora_schema_free":"true", "pandora_extra_info": "false" }] }
快速开始 | Pandora | Readers | Parsers | Senders | Download | 七牛智能日志管理平台 | logkit-pro专业版