代码之家  ›  专栏  ›  技术社区  ›  Nyxynyx

Kibana未显示从Node.js Winston Logger发送到Elasticsearch的日志

  •  0
  • Nyxynyx  · 技术社区  · 6 年前

    我正在使用Node.js应用程序将日志直接发送到Elasticsearch winston winston-elasticsearch 包装。Elasticsearch 7.5.1,Logstash&Kibana 7.5.1使用Docker Compose部署在远程服务器上。

    问题1:

    问题2: 将这两条日志消息发送到Elasticsearch后,可以在以下位置使用web浏览器查看它们: 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=() .

    enter image description here

    enter image description here

    enter image description here

    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');
    
    0 回复  |  直到 6 年前
        1
  •  1
  •   apt-get_install_skill    6 年前

    我不是node.js专家,所以我只关注kibana问题。Logs应用程序不适用于像您这样的“自定义”日志/索引。

    如文件中所述( https://www.elastic.co/guide/en/kibana/current/xpack-logs.html ):

    通用服务器、容器和服务。

    也来自文档( https://www.elastic.co/guide/en/kibana/current/xpack-logs-configuring.html ):

    查询数据。

    这解释了为什么你在logs应用程序中看不到任何数据,因为你的索引使用“logs-*”索引模式。

    长话短说:

    我希望我能帮助你。

    推荐文章