python—向es发送日志信息数据

python向es发送日志信息

# pip install elasticsearch
# pip install CMRESHandler
# pip install requests

import logging
from cmreslogging.handlers import CMRESHandler

handler = CMRESHandler(hosts=[{'host': 'x.x.x.x',
                               'port': 9200}],
                       auth_type=CMRESHandler.AuthType.BASIC_AUTH,
                       auth_details=('username','pwd'),
                       es_index_name='index',
                       ea_additional_fields={'xxx':'sss','www':'aaaa'})

log = logging.getLogger('ES')
log.setLevel(logging.INFO)
log.addHandler(handler)
log.info('Hello World!')

API参数:
es_index_name: es中的索引
ea_additional_fields:es对应索引下的属性和值

posted @ 2022-05-12 15:13  酷酷的排球  阅读(280)  评论(0编辑  收藏  举报