简体   繁体   English

如何使用 Elastic Search 和 Statsd 配置 Kibana

[英]How to configure Kibana with Elastic Search and Statsd

I am trying to do some metric calculation and store the value of the metric in ElasticSearch and view them via Kibana我正在尝试进行一些指标计算并将指标的值存储在 ElasticSearch 中并通过 Kibana 查看它们

I followed this tutorial https://www.digitalocean.com/community/tutorials/how-to-configure-statsd-to-collect-arbitrary-stats-for-graphite-on-ubuntu-14-04我跟着这个教程https://www.digitalocean.com/community/tutorials/how-to-configure-statsd-to-collect-arbitrary-stats-for-graphite-on-ubuntu-14-04

and it helped me to set up StatsD with graphite UI, Carbon and Whiper as Back-end.它帮助我使用石墨 UI、Carbon 和 Whiper 作为后端来设置 StatsD。

Now I want to use StatsD with ElasticSearch and Kibana as Visualization tool.现在我想将 StatsD 与 ElasticSearch 和 Kibana 一起用作可视化工具。

The issue I am facing is that Kibana has its own aggregation technique and I have already done so using statsd, eg: uniq counts.我面临的问题是 Kibana 有自己的聚合技术,我已经使用 statsd 这样做了,例如:uniq counts。 So I just want to plot the data which I store in Elastic Search and not aggregate it further, Is this possible to view data without aggregating them in Kibana.?所以我只想绘制我存储在 Elastic Search 中的数据而不是进一步聚合它,这是否可以查看数据而不在 Kibana 中聚合它们。?

Kindly Help.请帮助。

Thanks.谢谢。

You can do this via statsd(client) + metricbeat(statsd plugin that runs daemon) and Elasticsearch + Kibana.你可以通过 statsd(client) + metricbeat(statsd plugin that running daemon) 和 Elasticsearch + Kibana 来做到这一点。 Following steps:以下步骤:

set up elasticsearch : https://www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html设置弹性搜索: https : //www.elastic.co/guide/en/elasticsearch/reference/current/rpm.html

rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch

vi /etc/yum.repos.d/elasticsearch.repo and input: vi /etc/yum.repos.d/elasticsearch.repo 并输入:

[elasticsearch]
name=Elasticsearch repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=0
autorefresh=1
type=rpm-md

and install elasticsearch from above configured repo:并从上面配置的 repo 安装 elasticsearch:

sudo yum install --enablerepo=elasticsearch elasticsearch

set up (systemctl) service:设置(systemctl)服务:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable elasticsearch.service

which can be started/stopped as follows:可以按如下方式启动/停止:

sudo systemctl start elasticsearch.service
sudo systemctl stop elasticsearch.service

similarly, set up kibana, by just following : https://www.elastic.co/guide/en/kibana/current/rpm.html同样,设置 kibana,只需遵循: https ://www.elastic.co/guide/en/kibana/current/rpm.html

vi /etc/yum.repos.d/kibana.repo vi /etc/yum.repos.d/kibana.repo

[kibana-7.x]
name=Kibana repository for 7.x packages
baseurl=https://artifacts.elastic.co/packages/7.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md

and install kibana : sudo yum install kibana You can similarly enable, start/stop systemd services for kibana also.并安装 kibana : sudo yum install kibana您也可以类似地为 kibana 启用、启动/停止 systemd 服务。

I have the elasticsearch and kibana co-located, on same single node set up.我将 elasticsearch 和 kibana 放在同一位置,设置在同一个单节点上。

Now, just use a statsd client, in a flask application for example:现在,只需使用 statsd 客户端,例如在烧瓶应用程序中:

from flask import Flask
from elasticapm.contrib.flask import ElasticAPM
from statsd import StatsClient
from random import randint
from datetime import datetime
import time

statsd = StatsClient(host='0.0.0.0',port=8125,prefix='test')
app = Flask(__name__)
apm = ElasticAPM(app)

@app.route('/')
def hello():
    bfr = time.time()
    time.sleep(3)
    statsd.incr('baz',2)
    statsd.decr('ban')
    statsd.gauge('foo',-3,delta=True)
    statsd.set('users',randint(0,100))
    statsd.timing('req',int((time.time() - bfr)*1000))
    return "Hello World!"

This sets up our statsd client, for statsd server, just go to : http://<es-ip>:5601/app/kibana#/home/tutorial/statsdMetrics and follow up instructions.这将设置我们的 statsd 客户端,对于 statsd 服务器,只需转到: http://<es-ip>:5601/app/kibana#/home/tutorial/statsdMetrics并按照说明进行操作。

Set the metricbeat, enable statsd on the same server as flask application.设置 metricbeat,在与flask 应用程序相同的服务器上启用statsd。 steps are:步骤是:

curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.8.1-x86_64.rpm sudo rpm -vi metricbeat-7.8.1-x86_64.rpm curl -L -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-7.8.1-x86_64.rpm sudo rpm -vi metricbeat-7.8.1-x86_64.rpm

modify output.elasticsearch section in /etc/metricbeat/metricbeat.yml :修改output.elasticsearch在第/etc/metricbeat/metricbeat.yml

sudo metricbeat modules enable statsd

and setup things ie metricbeat / statsd:并设置东西,即 metricbeat / statsd:

sudo metricbeat setup
sudo service metricbeat start

You can do a netstat -tulpn | grep -i 8125你可以做一个netstat -tulpn | grep -i 8125 netstat -tulpn | grep -i 8125 and see a statsd daemon running. netstat -tulpn | grep -i 8125并查看 statsd 守护进程正在运行。

Next, just go to "dev tools" kibana section接下来,只需转到“开发工具”kibana 部分

and fire following query to check the statsd metrics : http://<es-ip>:5601/app/kibana#/dev_tools/console并触发以下查询以检查 statsd 指标: http://<es-ip>:5601/app/kibana#/dev_tools/console

GET /_search
{"query":{"bool":{"filter":{"term":{"event.module":"statsd"}}}},"size":10}

You can now go, create a dashboard, add visualizations with query filters 'event.module' is 'statsd', and even search for terms like .... eg accounts.authentication.login.num_users你现在可以去创建一个仪表板,添加带有查询过滤器“event.module”是“statsd”的可视化,甚至可以搜索诸如……之类的术语,例如accounts.authentication.login.num_users

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM