es = Elasticsearch(hosts=[{‘host‘: "elb-elasticsearch.cn-north-1.elb.amazonaws.com.cn", ‘port‘: "9200"}], http_auth=("username", "password")) t = datetime.fromtimestamp(int(1529986664), pytz.timezone(‘Asia/Shanghai‘))print(t) data = { "region":"cn", "env":"dev", "product":"reliability", "service":"devops", "objectType":"ec2", "endpoint":"cn-dev-reliability-devops-ec2-172.31.116.5", "metric":"tcp_syn_sent", "value":800,"timestamp":t, "begintime":t, "starttime":0, "endtime":0, "step":60, "counterType":"COUNTER", "tag":"{aaa==1,bbb=2}", "dataSource":"transfer", "kinesis":"true" } es.index(index="kinesis-2015.06.26", doc_type="testdata", body=data) 注释:
"timestamp":t, 传入时间参数 不要对时间格式化,否则会报错,也许跟我用的elk时间戳配置有关,如果遇到类似问题可以注意下。
原文地址:https://www.cnblogs.com/songfucai/p/9233390.html
时间: 2024-11-08 21:41:43