2017-03-02 64 views

回答

1

好吧,我發現了它是如何工作的,但我必須說,這是奇怪的,它不記錄任何地方,它涉及稍加修改的源代碼...

背景下第一

的一點點我有一個名爲「Nagios的」一個influxdb數據庫。在這個數據庫裏面,我有幾個系列。在influxdb秀系列展示了數據的串行CPU使用以下

> show series 
key 
--- 
nagios.CPULoad,hostname=cbba.storage,state=OK 
nagios.CPULoad,hostname=ussd1,state=OK 
nagios.CPULoad,hostname=ussd2,state=OK 
nagios.CPULoad,hostname=ussd3,state=OK 
nagios.CPULoad,hostname=ussd4,state=OK 

的結構是這樣的

> select * from "nagios.CPULoad" limit 1 
name: nagios.CPULoad 
time    hostname  load1 load15 load5 state 
----    --------  ----- ------ ----- ----- 
1487867813000000000 cbba.storage 0  0  0  OK 

我的URL來scripted.js如下:

http://10.72.6.220:3000/dashboard/script/scripted.js?name=CPULoad&field=load1&hostname=ussd3 
name indicates the series in influxDB I want to graph 
field indicates which field to use 
hostname indicates the host to choose 

我想要grafana scripted.js構建的SQL如下

SELECT mean("load1") FROM "nagios.CPULoad" WHERE "hostname" = 'ussd3' AND $timeFilter GROUP BY time($interval) fill(null) 

的代碼來構建內部scripted.js涉及到修改「目標」參數dashboard.rows結構,它原來是這樣的(我發現了這一點通過代碼去之後)

targets: [ 
     { 
     "measurement": "nagios." + ARGS.name, 
     "metric": ARGS.name, 
     "tags": { 
      "hostname": { 
        operator: "=" , 
        value: ARGS.hostname 
       } 
     }, 
     "select": [[{ 
        type: "field", 
        params: [ARGS.field] 
       }, { 
        type: "mean", 
        params: [] 
       }]], 
     }, 
    ], 

現在,我不知道爲什麼,但我必須修改代碼才能考慮密鑰「主機名」。在功能renderTagCondition我複製到這裏爲了方便

a.prototype.renderTagCondition = function(a, b, c) { 
    var d = "" 
     , e = a.operator 
     , f = a.value; 
    return b > 0 && (d = (a.condition || "AND") + " "), 
    e || (e = /^\/.*\/$/.test(f) ? "=~" : "="), 
    "=~" !== e && "!~" !== e ? (c && (f = this.templateSrv.replace(f, this.scopedVars)), 
    ">" !== e && "<" !== e && (f = "'" + f.replace(/\\/g, "\\\\") + "'")) : c && (f = this.templateSrv.replace(f, this.scopedVars, "regex")), 
    d + '"' + a.key + '" ' + e + " " + f 
} 

返回值

d + '"' + a.key + '" ' + e + " " + f 

似乎是錯誤的...它應該是

d + '"' + b + '" ' + e + " " + f 

由於B進行 「主機名」

畢竟,調用我在開始時提到的URL,所有的工作都非常好l