假设我们使用 ES 对天气指标进行监控,天气有晴天(fine)、阴天 (cloudy)、雨天(rainy)共三种,天气温度在 -10 度到 40 度之间,城市名假设有上海、北京、广州、合肥、南京、成都、重庆、苏州、宁波、天津、南京这几个城市。
加载 ES 客户端
from elasticsearch import Elasticsearch
from datetime import datetime
import random
import time
def get_es_instance():
ES_API="localhost:9200"
es = Elastic
定义一个造数据的方法,随机生成不同的天气、温度、时间戳、城市、数据。
时间戳生成方式
先定义一个开始时间点,在 2020 年 1 月 1 号。
datetime_str = '01/01/20 13:55:26'
time_falg = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S')
利用时间戳,time.time() 会生成当前时间的时间戳,今天的时间戳,随机减去一段时间,就可以生成随机的时间数据。
<