簡體   English   中英

Grafana 4使用Elasticsearch進行模板化5

[英]Grafana 4 Templating with Elasticsearch 5

編輯:請參閱下面的解決方案

目前在Grafana中存在模板問題 - 試圖從我通過Logstash的Graphite插件向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輸入過濾器 - 基本上是嘗試將石墨樣式度量分割為單獨的字段 -

input {
  graphite {
    type => graphite
    port => 2003
    id => "graphite_input"
  }
}

filter {
        if [type] == "graphite" {
                grok {
                        match => [ "message", "\Aicinga2\.%{MONGO_WORDDASH:host_name:keyword}\.%{WORD:metric_type:keyword}\.%{NOTSPACE:metric_name:keyword}\.value%{SPACE}%{NUMBER:metric_value:float}%{SPACE}%{POSINT:timestamp:date}" ]
                }
        }

}

output { 
        if [type] == "graphite" {
                elasticsearch {
                        index => "graphite-%{+YYYY.MM}"
                        hosts => ["localhost"]
                }
        }

}

我正在索引的示例文檔(取自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
  ]
}

我現在自己解決了這個問題。 字符串字段需要定義為not_analyzed才能顯示在Grafana儀表板中。

這是一個你可以使用的模板示例:注意:你必須手動安裝,似乎logstash不會因為某種原因將它安裝到elasticsearch中(也許是一個bug?)像這樣安裝(假設路徑是/ etc / logstash) /graphite-new.json:

curl -XPUT 'http://localhost:9200/_template/graphite-*' -d@/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"
        }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM