2017-02-21 121 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" 
     } 
}