
Enterprise:创建 meta 引擎来扩展你的 App search 体验

logstash 处理MySQL慢日志后,所有内容都在一个message字段不拆分
input {
file {
type => "mysql-slow"
path => "/tmp/slows.log"
codec => multiline {
pattern => "^# Time:"
negate => true
what => "previous"
}
}
}
filter {
if [ type ] == "mysql-slow" {
grok {
match => { "message" => "SELECT SLEEP" }
add_tag => [ "sleep_drop" ]
}
if "sleep_drop" in [tags] {
drop {}
}
grok {
"message" => "(?m)^#\s+Time\s?.*\s+#\s+User@Host:\s+%{USER:user}\[[^\]]+\]\s+@\s+(?:(?<clienthost>\S*) )?\[(?:%{IPV4:clientip})?\]\s+Id:\s+%{NUMBER:row_id:int}\n#\s+Query_time:\s+%{NUMBER:query_time:float}\s+Lock_time:\s+%{NUMBER:lock_time:float}\s+Rows_sent:\s+%{NUMBER:rows_sent:int}\s+Rows_examined:\s+%{NUMBER:rows_examined:int}\n\s*(?:use %{DATA:database};\s*\n)?SET\s+timestamp=%{NUMBER:timestamp};\n\s*(?<sql>(?<action>\w+)([\w.*\W.*])*;)\s*$"
}
}
}
最后的数据展示出来是这样的,不进行分割字段请问怎么解决
input {
file {
type => "mysql-slow"
path => "/tmp/slows.log"
codec => multiline {
pattern => "^# Time:"
negate => true
what => "previous"
}
}
}
filter {
if [ type ] == "mysql-slow" {
grok {
match => { "message" => "SELECT SLEEP" }
add_tag => [ "sleep_drop" ]
}
if "sleep_drop" in [tags] {
drop {}
}
grok {
"message" => "(?m)^#\s+Time\s?.*\s+#\s+User@Host:\s+%{USER:user}\[[^\]]+\]\s+@\s+(?:(?<clienthost>\S*) )?\[(?:%{IPV4:clientip})?\]\s+Id:\s+%{NUMBER:row_id:int}\n#\s+Query_time:\s+%{NUMBER:query_time:float}\s+Lock_time:\s+%{NUMBER:lock_time:float}\s+Rows_sent:\s+%{NUMBER:rows_sent:int}\s+Rows_examined:\s+%{NUMBER:rows_examined:int}\n\s*(?:use %{DATA:database};\s*\n)?SET\s+timestamp=%{NUMBER:timestamp};\n\s*(?<sql>(?<action>\w+)([\w.*\W.*])*;)\s*$"
}
}
}
最后的数据展示出来是这样的,不进行分割字段请问怎么解决 收起阅读 »

社区日报 第951期 (2020-05-28)
https://t.cn/A62JyQuM
2.倒排序索引与分词Analysis
https://t.cn/A62JyTo7
3.使用 Elasticsearch 优雅搭建自己的搜索系统(附源码)
https://t.cn/A6ADSkg0
编辑:金桥
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
https://t.cn/A62JyQuM
2.倒排序索引与分词Analysis
https://t.cn/A62JyTo7
3.使用 Elasticsearch 优雅搭建自己的搜索系统(附源码)
https://t.cn/A6ADSkg0
编辑:金桥
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第950期 (2020-05-27)
https://t.cn/A62MLdOj
2.在 Kibana 中为不同用户生成不同的 Space
https://t.cn/A62MLkge
3.Elasticsearch 查询过程中的 pre-filter 原理
https://t.cn/A62Myh74
编辑:江水
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
https://t.cn/A62MLdOj
2.在 Kibana 中为不同用户生成不同的 Space
https://t.cn/A62MLkge
3.Elasticsearch 查询过程中的 pre-filter 原理
https://t.cn/A62Myh74
编辑:江水
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
收起阅读 »

社区日报 第949期 (2020-05-26)
http://tinyurl.com/ybmdwwb7
2、Elasticsearch对垒8大竞品技术,孰优孰劣?
https://t.cn/A62V4ijt
3、使用Scroll和Ruby遍历Elasticsearch文档数据。
https://t.cn/A62V4Jxz
编辑:叮咚光军
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://tinyurl.com/ybmdwwb7
2、Elasticsearch对垒8大竞品技术,孰优孰劣?
https://t.cn/A62V4ijt
3、使用Scroll和Ruby遍历Elasticsearch文档数据。
https://t.cn/A62V4Jxz
编辑:叮咚光军
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第947期 (2020-05-24)
http://t.cn/A62qVMNP
2.数据可视化:您需要了解的31种工具。
http://t.cn/A62qfzSz
3.(自备梯子)商业和生活中区块链技术的应用不断增加。
http://t.cn/A62qfleh
编辑:至尊宝
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://t.cn/A62qVMNP
2.数据可视化:您需要了解的31种工具。
http://t.cn/A62qfzSz
3.(自备梯子)商业和生活中区块链技术的应用不断增加。
http://t.cn/A62qfleh
编辑:至尊宝
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第946期 (2020-05-23)

社区日报 第945期 (2020-05-22)
http://t.cn/A62UBZib
2、Elasticsearch结合Laravel(PHP web框架)终极实战指南(梯子)
http://t.cn/A62UBZiq
3、Elasticsearch 分析FTP日志实践(梯子)
http://t.cn/A62UBZi4
编辑:铭毅天下
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://t.cn/A62UBZib
2、Elasticsearch结合Laravel(PHP web框架)终极实战指南(梯子)
http://t.cn/A62UBZiq
3、Elasticsearch 分析FTP日志实践(梯子)
http://t.cn/A62UBZi4
编辑:铭毅天下
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
收起阅读 »

社区日报 第944期 (2020-05-21)
https://t.cn/A62L2ghq
2.elasticsearch支持拼音自动补全
https://t.cn/A6AHyv3k
3.rollup索引管理
https://t.cn/A62L2kf2
编辑:金桥
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
https://t.cn/A62L2ghq
2.elasticsearch支持拼音自动补全
https://t.cn/A6AHyv3k
3.rollup索引管理
https://t.cn/A62L2kf2
编辑:金桥
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第943期 (2020-05-20)
http://t.cn/A62AZWzh
2、请收好 ecs java 日志标准
http://t.cn/A62AZWzZ
3、Grafana 7.0 发布了,快来玩玩吧~
http://t.cn/A62AZWz2
编辑:rockybean
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://t.cn/A62AZWzh
2、请收好 ecs java 日志标准
http://t.cn/A62AZWzZ
3、Grafana 7.0 发布了,快来玩玩吧~
http://t.cn/A62AZWz2
编辑:rockybean
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第942期 (2020-05-19)
https://t.cn/A62z6xMZ
2、在Docker上使用Kibana和Elasticsearch监控nginx日志。
https://t.cn/A62z6Jjw
3、在Spring Data Elasticsearch 4中使用地理距离排序
https://t.cn/A62z66yI
编辑:叮咚光军
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
https://t.cn/A62z6xMZ
2、在Docker上使用Kibana和Elasticsearch监控nginx日志。
https://t.cn/A62z6Jjw
3、在Spring Data Elasticsearch 4中使用地理距离排序
https://t.cn/A62z66yI
编辑:叮咚光军
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

社区日报 第941期 (2020-05-18)
http://t.cn/A62Pc1Ts
2.一份PPT集中了解es发展:Elastic Stack Roadmap(自带梯子)
http://t.cn/A62Pf6DU
使用Elastic Stack和prometheus来实现metric监控
https://www.elastic.co/cn/what ... oring
编辑:cyberdak
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://t.cn/A62Pc1Ts
2.一份PPT集中了解es发展:Elastic Stack Roadmap(自带梯子)
http://t.cn/A62Pf6DU
使用Elastic Stack和prometheus来实现metric监控
https://www.elastic.co/cn/what ... oring
编辑:cyberdak
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »

解决Elasticsearch HTTP方式查询报SocketTimeoutException的问题(待验证)
注意: 此解决方案,短时间内没有复现,还需要长时间验证是否有效。
现象
在使用HTTP方式,Elasticsearch 长时间不查询后,再次查询会出现抛出SocketTimeoutException的问题。
原因
基本逻辑
Elasticsearch 客户端会根据服务器返回的HTTP报文内容,来决定客户端保持HTTP连接Keep-Alive状态的策略。
如果结果如下,那么保持HTTP连接 Keep-Alive状态为120s
Connection: Keep-Alive
Keep-Alive: max=5, timeout = 120
如果不包含上述内容,那么客户端将保持Keep-Alive状态的时间为永久。
事实上,Elasticsearch服务器返回的报文,并没有上述HTTP头内容,所以客户端所有的HTTP连接都为永久保持Keep-Alive。
如果客户端长时间没有发送请求,服务器或者防火墙已经close了HTTP底层的TCP链接,但是此时客户端并不知道,由于Keep Alive是无限期,那么并不会重新建立连接,而是直接发送请求,此时就会得到SocketTimeout异常。
阅读源码
我使用的Elasticsearch的客户端下面的版本
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>5.4.1</version>
</dependency>
其HTTP的发送依赖Maven包httpasyncclient
.
这个包中的接口ConnectionKeepAliveStrategy,抽象了处理 HTTP Keepalive 的策略,其默认实现为:
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultConnectionKeepAliveStrategy implements ConnectionKeepAliveStrategy {
public static final DefaultConnectionKeepAliveStrategy INSTANCE = new DefaultConnectionKeepAliveStrategy();
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
}
-1
代表多长时间,接口说明不是很清楚。
PoolingNHttpClientConnectionManager 类中的代码,实现了上述对待KeepAlive的逻辑,可以看到-1
表示为:无限期
@Override
public void releaseConnection(
final NHttpClientConnection managedConn,
final Object state,
final long keepalive,
final TimeUnit tunit) {
Args.notNull(managedConn, "Managed connection");
synchronized (managedConn) {
final CPoolEntry entry = CPoolProxy.detach(managedConn);
if (entry == null) {
return;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Releasing connection: " + format(entry) + formatStats(entry.getRoute()));
}
final NHttpClientConnection conn = entry.getConnection();
try {
if (conn.isOpen()) {
entry.setState(state);
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
final String s;
// keepalive 就是上面接口 ConnectionKeepAliveStrategy.getKeepAliveDuration()的返回值
if (keepalive > 0) {
s = "for " + (double) keepalive / 1000 + " seconds";
} else {
// 如果小于0 ,那么策略为indefinitely:无限期。
s = "indefinitely";
}
this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
}
}
} finally {
this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
if (this.log.isDebugEnabled()) {
this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
}
}
}
}
解决方式
自定义类实现ConnectionKeepAliveStrategy
接口:
public class CustomConnectionKeepAliveStrategy extends DefaultConnectionKeepAliveStrategy {
public static final CustomConnectionKeepAliveStrategy INSTANCE = new CustomConnectionKeepAliveStrategy();
private CustomConnectionKeepAliveStrategy() {
super();
}
/**
* 最大keep alive的时间(分钟)
* 这里默认为10分钟,可以根据实际情况设置。可以观察客户端机器状态为TIME_WAIT的TCP连接数,如果太多,可以增大此值。
*/
private final long MAX_KEEP_ALIVE_MINUTES = 10;
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
long keepAliveDuration = super.getKeepAliveDuration(response, context);
// <0 为无限期keepalive
// 将无限期替换成一个默认的时间
if(keepAliveDuration < 0){
return TimeUnit.MINUTES.toMillis(MAX_KEEP_ALIVE_MINUTES);
}
return keepAliveDuration;
}
}
在创建Elasticserach Client时,配置
RestClientBuilder builder = RestClient.builder(hosts);
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.setKeepAliveStrategy(CustomConnectionKeepAliveStrategy.INSTANCE);
return httpClientBuilder;
}
});
注意: 此解决方案,短时间内没有复现,还需要长时间验证是否有效。
现象
在使用HTTP方式,Elasticsearch 长时间不查询后,再次查询会出现抛出SocketTimeoutException的问题。
原因
基本逻辑
Elasticsearch 客户端会根据服务器返回的HTTP报文内容,来决定客户端保持HTTP连接Keep-Alive状态的策略。
如果结果如下,那么保持HTTP连接 Keep-Alive状态为120s
Connection: Keep-Alive
Keep-Alive: max=5, timeout = 120
如果不包含上述内容,那么客户端将保持Keep-Alive状态的时间为永久。
事实上,Elasticsearch服务器返回的报文,并没有上述HTTP头内容,所以客户端所有的HTTP连接都为永久保持Keep-Alive。
如果客户端长时间没有发送请求,服务器或者防火墙已经close了HTTP底层的TCP链接,但是此时客户端并不知道,由于Keep Alive是无限期,那么并不会重新建立连接,而是直接发送请求,此时就会得到SocketTimeout异常。
阅读源码
我使用的Elasticsearch的客户端下面的版本
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>rest</artifactId>
<version>5.4.1</version>
</dependency>
其HTTP的发送依赖Maven包httpasyncclient
.
这个包中的接口ConnectionKeepAliveStrategy,抽象了处理 HTTP Keepalive 的策略,其默认实现为:
@Contract(threading = ThreadingBehavior.IMMUTABLE)
public class DefaultConnectionKeepAliveStrategy implements ConnectionKeepAliveStrategy {
public static final DefaultConnectionKeepAliveStrategy INSTANCE = new DefaultConnectionKeepAliveStrategy();
@Override
public long getKeepAliveDuration(final HttpResponse response, final HttpContext context) {
Args.notNull(response, "HTTP response");
final HeaderElementIterator it = new BasicHeaderElementIterator(
response.headerIterator(HTTP.CONN_KEEP_ALIVE));
while (it.hasNext()) {
final HeaderElement he = it.nextElement();
final String param = he.getName();
final String value = he.getValue();
if (value != null && param.equalsIgnoreCase("timeout")) {
try {
return Long.parseLong(value) * 1000;
} catch(final NumberFormatException ignore) {
}
}
}
return -1;
}
}
-1
代表多长时间,接口说明不是很清楚。
PoolingNHttpClientConnectionManager 类中的代码,实现了上述对待KeepAlive的逻辑,可以看到-1
表示为:无限期
@Override
public void releaseConnection(
final NHttpClientConnection managedConn,
final Object state,
final long keepalive,
final TimeUnit tunit) {
Args.notNull(managedConn, "Managed connection");
synchronized (managedConn) {
final CPoolEntry entry = CPoolProxy.detach(managedConn);
if (entry == null) {
return;
}
if (this.log.isDebugEnabled()) {
this.log.debug("Releasing connection: " + format(entry) + formatStats(entry.getRoute()));
}
final NHttpClientConnection conn = entry.getConnection();
try {
if (conn.isOpen()) {
entry.setState(state);
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
final String s;
// keepalive 就是上面接口 ConnectionKeepAliveStrategy.getKeepAliveDuration()的返回值
if (keepalive > 0) {
s = "for " + (double) keepalive / 1000 + " seconds";
} else {
// 如果小于0 ,那么策略为indefinitely:无限期。
s = "indefinitely";
}
this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
}
}
} finally {
this.pool.release(entry, conn.isOpen() && entry.isRouteComplete());
if (this.log.isDebugEnabled()) {
this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
}
}
}
}
解决方式
自定义类实现ConnectionKeepAliveStrategy
接口:
public class CustomConnectionKeepAliveStrategy extends DefaultConnectionKeepAliveStrategy {
public static final CustomConnectionKeepAliveStrategy INSTANCE = new CustomConnectionKeepAliveStrategy();
private CustomConnectionKeepAliveStrategy() {
super();
}
/**
* 最大keep alive的时间(分钟)
* 这里默认为10分钟,可以根据实际情况设置。可以观察客户端机器状态为TIME_WAIT的TCP连接数,如果太多,可以增大此值。
*/
private final long MAX_KEEP_ALIVE_MINUTES = 10;
@Override
public long getKeepAliveDuration(HttpResponse response, HttpContext context) {
long keepAliveDuration = super.getKeepAliveDuration(response, context);
// <0 为无限期keepalive
// 将无限期替换成一个默认的时间
if(keepAliveDuration < 0){
return TimeUnit.MINUTES.toMillis(MAX_KEEP_ALIVE_MINUTES);
}
return keepAliveDuration;
}
}
在创建Elasticserach Client时,配置
RestClientBuilder builder = RestClient.builder(hosts);
builder.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
@Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
httpClientBuilder.setKeepAliveStrategy(CustomConnectionKeepAliveStrategy.INSTANCE);
return httpClientBuilder;
}
});
收起阅读 »

社区日报 第940期 (2020-05-17)
http://t.cn/A6Asz8qN
2.从Quarkus访问Apache Kafka。
http://t.cn/A6AsZZ9G
3.ELK+FileBeat+Kafka搭建日志管理平台。
http://t.cn/A6AsZnzq
编辑:至尊宝
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup
http://t.cn/A6Asz8qN
2.从Quarkus访问Apache Kafka。
http://t.cn/A6AsZZ9G
3.ELK+FileBeat+Kafka搭建日志管理平台。
http://t.cn/A6AsZnzq
编辑:至尊宝
归档:https://ela.st/cn-daily-all
订阅:https://ela.st/cn-daily-sub
沙龙:https://ela.st/cn-meetup 收起阅读 »
