在Kibana中,从数据输入到图表创建
我根据下一页的参考资料向Elasticsearch(7.9.1)投入了数据。
假设已安装和运行了Kibana和Elasticsearch。
确认运行
Kibana是一种数据可视化工具。
$ sudo systemctl status kibana
● kibana.service - Kibana
Loaded: loaded (/etc/systemd/system/kibana.service; disabled; vendor prese>
Active: active (running) since Tue 2021-10-12 07:29:49 JST; 4h 30min ago
“弹性搜索”
$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
Loaded: loaded (/lib/systemd/system/elasticsearch.service; disabled; vendo>
Active: active (running) since Tue 2021-10-12 07:29:02 JST; 4h 34min ago
请访问 http://localhost:5601
确认 Elasticsearch 的版本
$ curl localhost:9200
{
"name" : "iwata",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "R92Wu-uxTl2gad2cs6OkIg",
"version" : {
"number" : "7.15.0",
"build_flavor" : "default",
"build_type" : "deb",
"build_hash" : "79d65f6e357953a5b3cbcc5e2c7c21073d89aa29",
"build_date" : "2021-09-16T03:05:29.143308416Z",
"build_snapshot" : false,
"lucene_version" : "8.9.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
設定文件 (shè
server.port: 5601
server.host: "localhost"
-Xms512m
-Xmx512m
添加认证
我参考了这个页面。
安全功能的启用方式。
关闭Elasticsearch和Kibana。
更改设置文件
(省略)
xpack.security.enabled: true
启动 Elasticsearch。
创建密码
sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords auto
在生成的密码出现后,请记下来。
(省略)
elasticsearch.username: "elastic"
elasticsearch.password: "abcdeZyhkZgU29e0r4fp"
启动Kibana。
确认
$ curl -u elastic:abcdeZyhkZgU29e0r4fp http://localhost:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
127.0.0.1 67 95 15 0.54 1.47 2.17 cdfhilmrstw * iwata
请访问 http://localhost:5601
数据输入
创建索引
curl -H "Content-Type: application/json" -X PUT \
-u elastic:abcdeZyhkZgU29e0r4fp \
"http://127.0.0.1:9200/temperature_humidity?pretty" -d '
{
"mappings" : {
"properties" : {
"temperature" : {"type" : "double"},
"humidity" : {"type" : "double"},
"timestamp" : {"type" : "date"}
}
}
}'
确认指数
curl -H "Content-Type: application/json" -X GET \
-u elastic:abcdeZyhkZgU29e0r4fp \
"http://127.0.0.1:9200/temperature_humidity?pretty"
数据输入
#! /usr/bin/python
#
# insert_elastic_auth.py
#
# Oct/14/2021
# -------------------------------------------------------------------------
import datetime
import time
import math
import sys
import json
import requests
from requests.auth import HTTPBasicAuth
# -------------------------------------------------------------------------
url_base = "http://localhost:9200/temperature_humidity/_doc"
#
#icount = 0
#while True:
for icount in range(60):
key = str(icount)
url = url_base + "/" + key
sys.stderr.write("icount = %d\n" % icount)
now = datetime.datetime.now()
ttx = int(now.timestamp())
print(ttx)
deg = (icount % 36) * 10
rad = math.pi * deg / 180.0
diff_temp = 5.0 * math.sin(rad)
temperature = 25.0 + diff_temp
diff_humi = 20.0 * math.sin(rad)
humidity = 70.0 + diff_humi
es_body = {
'timestamp' : ttx,
'temperture' : temperature,
'humidity' : humidity,
'icount' : icount,
}
json_str = json.dumps(es_body)
print(json_str)
#
headers = {'content-type': 'application/json'}
rr=requests.put(url,data=json_str,headers=headers,auth=HTTPBasicAuth('elastic', 'abcdeZyhkZgU29e0r4fp'))
print(rr)
#
time.sleep(1)
print(es_body)
#
# -------------------------------------------------------------------------
统计数据的数量
$ curl -u elastic:abcdeZyhkZgU29e0r4fp \
'localhost:9200/temperature_humidity/_count?q=*'
{"count":17,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0}}
获取数据
curl -X GET -u elastic:abcdeZyhkZgU29e0r4fp \
http://localhost:9200/temperature_humidity/_search | jq .hits.hits
在Kibana的Management->Dev Tools中确认数据。
确认索引
创建图表
使用仪表板创建图表