2017-02-21 120 views
1

编辑:请参阅以下解决方案Grafana 4模板与Elasticsearch 5

目前其在Grafana模板的问题 - 试图从一些数据,我喂在通过Logstash的石墨Elasticsearch主机名的下拉列表插件,所以我可以在Grafana中构建一个动态模板。

版本 Grafana 4.1.2 + Elasticsearch/Logstash 5.2.1

在Grafana条款查询我试图用的是按照文档grafana网站上进行如下 - http://docs.grafana.org/features/datasources/elasticsearch/

{"find": "terms", "field": "host_name"} 

这工作得很好,如果该字段是一个数字类型的字段 - 例如,我得到的metric_value模板的结果,但这似乎不适用于文本/字符串字段。我想知道这是否可能是由于我构建或摄取字段的方式 - 您可以在下面看到我如何尝试实现这一点 - 请注意,我已经尝试了“关键字”和“文本”类型领域,既不似乎工作

这是我使用的Logstash输入滤波器 - 基本上是试图分裂石墨风格量度输入到单独的领域 -

​​

和实例文档,我的索引(取自kibana)

{ 
    "_index": "graphite-2017.02", 
    "_type": "graphite", 
    "_id": "XYZdflksdf", 
    "_score": null, 
    "_source": { 
    "@timestamp": "2017-02-21T00:17:16.000Z", 
    "metric_name": "interface-eth0.snmp-interface.perfdata.eth0_in_discard", 
    "port": 37694, 
    "icinga2.XXXYYY.services.interface-eth0.snmp-interface.perfdata.eth0_in_discard.value": 357237, 
    "@version": "1", 
    "host": "192.168.1.1", 
    "metric_type": "services", 
    "metric_value": 357237, 
    "message": "icinga2.XXXYYY.services.interface-eth0.snmp-interface.perfdata.eth0_in_discard.value 357237 1487636236", 
    "type": "graphite", 
    "host_name": "XXXYYY", 
    "timestamp": "1487636236" 
    }, 
    "fields": { 
    "@timestamp": [ 
     1487636236000 
    ] 
    }, 
    "sort": [ 
    1487636236000 
    ] 
} 
+0

https://github.com/grafana/grafana/issues/7335 – trogs

+0

http://www.pipebug.com/elasticsearch-logstash-kibana-4-mapping-4.html – trogs

+0

https:// www。 elastic.co/guide/en/beats/filebeat/1.2/filebeat-template.html – trogs

回答

0

我现在已经自己解决了这个问题。需要将字符串字段定义为not_analyzed才能显示在Grafana仪表板中。

这里有一个例子模板,你可以使用: 注:(?也许一个bug),你必须手动安装此,好像logstash不会将它安装到elasticsearch出于某种原因 安装像这样(假设路径是/etc/logstash/graphite-new.json:

curl -XPUT 'http://localhost:9200/_template/graphite-*' [email protected]/etc/logstash/graphite-new.json 

模板:

{ 
    "template" : "graphite-*", 
    "settings" : { "index.refresh_interval" : "60s" }, 
    "mappings" : { 
     "_default_" : { 
      "_all" : { "enabled" : false }, 
      "dynamic_templates" : [{ 
       "message_field" : { 
       "match" : "message", 
       "match_mapping_type" : "string", 
       "mapping" : { "type" : "string", "index" : "not_analyzed" } 
       } 
      }, { 
       "string_fields" : { 
       "match" : "*", 
       "match_mapping_type" : "string", 
       "mapping" : { "type" : "string", "index" : "not_analyzed" } 
       } 
      }], 
      "properties" : { 
       "@timestamp" : { "type" : "date", "format" : "dateOptionalTime" }, 
       "@version" : { "type" : "integer", "index" : "not_analyzed" }, 
       "metric_name" : { "type" : "string", "index" : "not_analyzed" }, 
       "host" : { "type" : "string", "index" : "not_analyzed" }, 
       "host_name" : { "type" : "string", "index" : "not_analyzed" }, 
       "metric_type" : { "type" : "string", "index" : "not_analyzed" } 
      } 
     } 
    } 
} 

我还有在logstash过滤器这个定义,以及:

if [type] == "graphite" { 
     elasticsearch { 
       index => "graphite-%{+YYYY.MM}" 
       hosts => ["localhost"] 
       template => "/etc/logstash/graphite-new.json" 
     } 
}