Search code examples
graphite

Understanding the response from Graphite render interface


When getting a JSON response from Graphites /render API it looks as follows.

{
"target": "summarize(sol.count.meter.count, "1day", "sum")",
"datapoints": [
  [
  null,
  1481846400
],,
  [
  null,
  1481932800
],,
  [
  null,
  1482019200
],,
  [
  null,
  1482105600
],,
  [
  null,
  1482192000
],,
  [
  null,
  1482278400
],,
  [
  1006491,
  1482364800
],,
  [
  1577,
  1482451200
],
],
}

My intuition about the expected response is that I would get a list with datapoints, where each day has 0 or 1 measure. However this is not what I get.

What I dont understand is why we need a nested list to represent datapoints? What is the content of the inner list in a Graphite response?


Solution

  • The graphite's json output format can be defined as array of metric series, each metric series is an object with the series' id/name called target and array of datapoints, and finally each datapoint is a array of corresponding value and timestamp.

    [
      {
         "datapoints": [
           [value1, timestamp1],
           [value2, timestamp2],
           // ...
         ],
         "target": "some.metric.count"
      },  {
         "datapoints": [
           [value9, timestamp99],
           [value8, timestamp88],
           // ...
         ],
         "target": "some.metric2.count"
      },
      // ...
    ]
    

    This structure is a result of design concept and its implementation:

    • datapoint must contain value and timestamp (time frames are aligned on render and could it be adjusted) and array is the lightest structure
    • datapoints must be an array to preserve the order, since object is a hash-like structure. Note that each series can have very different timestamps, but have particular order and the same length (nulls if no values found)

    My intuition about the expected response is that I would get a list with datapoints, where each day has 0 or 1 measure. However this is not what I get.

    summarize reduces (using sum/avg/max/min) datapoints per specified time bucket, if all values in buckets are nulls, the final value equals to null. You can use transfomrNulls to replace nulls with desired value.