2013-12-17 22 views
1

我們如何獲得石墨中的一系列常數值。我已經檢查了功能constantLine(x),但是它在「圖形」上繪製了一條常量線。不過,我需要json格式的值。以json格式返回石墨中的恆定值

函數Identity(t),返回x(t) = t;我們需要的是y(t) = constant

目前,我認爲我們需要在石墨DB中注入數據點。沒有它,我們可以做到嗎?

[graphite web uri]/render?target=FUNC(x)&format=json. 

*編輯: 我曾嘗試constantLine(x)函數 我得到: 回溯(最近通話最後一個): *

File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 111, in get_response 
    response = callback(request, *callback_args, **callback_kwargs) 
    File "/opt/graphite/webapp/graphite/render/views.py", line 104, in renderView 
    seriesList = evaluateTarget(requestContext, target) 
    File "/opt/graphite/webapp/graphite/render/evaluator.py", line 10, in evaluateTarget 
    result = evaluateTokens(requestContext, tokens) 
    File "/opt/graphite/webapp/graphite/render/evaluator.py", line 21, in evaluateTokens 
    return evaluateTokens(requestContext, tokens.expression) 
    File "/opt/graphite/webapp/graphite/render/evaluator.py", line 27, in evaluateTokens 
    func = SeriesFunctions[tokens.call.func] 
KeyError: u'contantLine' 

*

回答

0

graphite.com/render/?target=constantLine(123.456)&format=json

返回

[{"target": "123.456", "datapoints": [[123.456, 1381399794]]}]

這不是你想要的?如果您希望石墨返回純粹的123.456,您將不得不編輯代碼並重寫結果的顯示方式。

  1. 添加新功能customConstantLine(requestContext, value)functions.py
  2. 覆蓋渲染類,以打印純123.456,當返回函數是customConstantLine()

單挑:您的編輯還必須考慮多個目標返回的情況。

編輯:

修補functions.py!如果你不想升級你的Graphite add-

def constantLine(requestContext, value): 
    start = timestamp(requestContext['startTime']) 
    end = timestamp(requestContext['endTime']) 
    step = (end - start)/1.0 
    series = TimeSeries(str(value), start, end, step, [value, value]) 
    return [series] 
+0

嘿我有一個錯誤,當我使用相同的,你使用的石墨版本? –

+0

0.9.10。我編輯了答案,包括解決方法。 – erbdex

+0

嗨,有一個函數閾值(20.1,「你好」,顏色),這解決了這個問題,可悲的是,這再次與&format = json不起作用;檢查functions.py,其相同.. –