Kibana 不显示从 Node.js Winston Logger 发送到 Elasticsearch 的日志
Kibana Not Showing Logs Sent to Elasticsearch From Node.js Winston Logger
我使用 winston
和 winston-elasticsearch
包将日志从 Node.js 应用程序直接发送到 Elasticsearch。 Elasticsearch 7.5.1、Logstash 和 Kibana 7.5.1 使用 Docker Compose 部署在远程服务器上。
问题一:在运行发送2条日志消息到Elasticsearch的node.js文件后,程序没有自动退出到return 到终端。在 Mac OS X Mojave 10.14.6.
上使用 Node.js v12.6.0
问题2:将这2条日志消息发送到Elasticsearch后,可以在http://<example.com>:9200/logs-2020.02.01/_search
使用网络浏览器查看。
{"took":5,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"logs-2020.02.01","_type":"_doc","_id":"85GgA3ABiaPPk4as1pEc","_score":1.0,"_source":{"@timestamp":"2020-02-02T02:00:35.789Z","message":"a debug message","severity":"debug","fields":{}}},{"_index":"logs-2020.02.01","_type":"_doc","_id":"9JGgA3ABiaPPk4as1pEc","_score":1.0,"_source":{"@timestamp":"2020-02-02T02:00:35.791Z","message":"an info log","severity":"info","fields":{}}}]}}
但是,这些日志不会显示在 Kibana 上,例如 https://<example.com>/app/infra#/logs/stream?_g=()
的日志部分。
知道如何让日志也显示在 Kibana 上吗?另外,为什么 Node.js 应用程序在发送日志消息后没有退出?
谢谢!
Node.js 应用程序
const winston = require('winston');
const ElasticsearchWinston = require('winston-elasticsearch');
const options = {
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
},
elasticsearch: {
level: 'debug',
clientOpts: {
node: 'http://user:pass@example.com:9200',
log: 'debug',
maxRetries: 2,
requestTimeout: 10000,
sniffOnStart: false,
}
}
}
var logger = winston.createLogger({
exitOnError: false,
transports: [
new winston.transports.Console(options.console),
new ElasticsearchWinston(options.elasticsearch)
]
});
logger.debug('a debug message');
logger.info('an info log');
我不是 node.js 专家,所以我只会关注 kibana 问题。 Logs 应用并不像您的应用那样适合 "custom" logs/indices。
如文档中所述 (https://www.elastic.co/guide/en/kibana/current/xpack-logs.html):
The Logs app in Kibana enables you to explore logs for common servers, containers, and services.
日志应用程序用于监控您的基础架构和 ELK 服务,例如通过某些 Beats 模块(例如 Filebeat 的 Elasticsearch、Kibana 和 Logstash 模块)。
也来自文档 (https://www.elastic.co/guide/en/kibana/current/xpack-logs-configuring.html):
The default source configuration for logs is specified in the Logs app settings in the Kibana configuration file. The default configuration uses the filebeat-* index pattern to query the data.
这解释了为什么您在日志应用程序中看不到任何数据,因为您的索引使用 'logs-*' 索引模式。
长话短说:
要查看 log-* 索引中的文档,您需要打开 Discovery(Kibana 左侧栏中的第一个图标)和 select 您已经设置的索引模式。这是在 Kibana 中搜索应用程序数据的合适方式。
希望能帮到你
我使用 winston
和 winston-elasticsearch
包将日志从 Node.js 应用程序直接发送到 Elasticsearch。 Elasticsearch 7.5.1、Logstash 和 Kibana 7.5.1 使用 Docker Compose 部署在远程服务器上。
问题一:在运行发送2条日志消息到Elasticsearch的node.js文件后,程序没有自动退出到return 到终端。在 Mac OS X Mojave 10.14.6.
上使用 Node.js v12.6.0问题2:将这2条日志消息发送到Elasticsearch后,可以在http://<example.com>:9200/logs-2020.02.01/_search
使用网络浏览器查看。
{"took":5,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":{"value":2,"relation":"eq"},"max_score":1.0,"hits":[{"_index":"logs-2020.02.01","_type":"_doc","_id":"85GgA3ABiaPPk4as1pEc","_score":1.0,"_source":{"@timestamp":"2020-02-02T02:00:35.789Z","message":"a debug message","severity":"debug","fields":{}}},{"_index":"logs-2020.02.01","_type":"_doc","_id":"9JGgA3ABiaPPk4as1pEc","_score":1.0,"_source":{"@timestamp":"2020-02-02T02:00:35.791Z","message":"an info log","severity":"info","fields":{}}}]}}
但是,这些日志不会显示在 Kibana 上,例如 https://<example.com>/app/infra#/logs/stream?_g=()
的日志部分。
知道如何让日志也显示在 Kibana 上吗?另外,为什么 Node.js 应用程序在发送日志消息后没有退出?
谢谢!
Node.js 应用程序
const winston = require('winston');
const ElasticsearchWinston = require('winston-elasticsearch');
const options = {
console: {
level: 'debug',
handleExceptions: true,
json: false,
colorize: true
},
elasticsearch: {
level: 'debug',
clientOpts: {
node: 'http://user:pass@example.com:9200',
log: 'debug',
maxRetries: 2,
requestTimeout: 10000,
sniffOnStart: false,
}
}
}
var logger = winston.createLogger({
exitOnError: false,
transports: [
new winston.transports.Console(options.console),
new ElasticsearchWinston(options.elasticsearch)
]
});
logger.debug('a debug message');
logger.info('an info log');
我不是 node.js 专家,所以我只会关注 kibana 问题。 Logs 应用并不像您的应用那样适合 "custom" logs/indices。
如文档中所述 (https://www.elastic.co/guide/en/kibana/current/xpack-logs.html):
The Logs app in Kibana enables you to explore logs for common servers, containers, and services.
日志应用程序用于监控您的基础架构和 ELK 服务,例如通过某些 Beats 模块(例如 Filebeat 的 Elasticsearch、Kibana 和 Logstash 模块)。
也来自文档 (https://www.elastic.co/guide/en/kibana/current/xpack-logs-configuring.html):
The default source configuration for logs is specified in the Logs app settings in the Kibana configuration file. The default configuration uses the filebeat-* index pattern to query the data.
这解释了为什么您在日志应用程序中看不到任何数据,因为您的索引使用 'logs-*' 索引模式。
长话短说:
要查看 log-* 索引中的文档,您需要打开 Discovery(Kibana 左侧栏中的第一个图标)和 select 您已经设置的索引模式。这是在 Kibana 中搜索应用程序数据的合适方式。
希望能帮到你