No time in JSON response

  • What Grafana version and what operating system are you using?

v10.4.15

  • What are you trying to achieve?

I want to create timeseries of brightadata balance over time.

  • How are you trying to achieve it?

Using Infinity Data Source - By calling Brightdata’s API for total balance, i am getting balance in response JSON.

  • What happened?

There is no timestamp in response json so it could create timeseries (after some time) from it.

  • What did you expect to happen?

To automatically fill up timestamp as system’s time if there is no such timestamp in json response.

  • Can you copy/paste the configuration(s) that you are having problems with?
{
  "annotations": {
    "list": [
      {
        "builtIn": 1,
        "datasource": {
          "type": "grafana",
          "uid": "-- Grafana --"
        },
        "enable": true,
        "hide": true,
        "iconColor": "rgba(0, 211, 255, 1)",
        "name": "Annotations & Alerts",
        "type": "dashboard"
      }
    ]
  },
  "editable": true,
  "fiscalYearStartMonth": 0,
  "graphTooltip": 0,
  "id": 115,
  "links": [],
  "panels": [
    {
      "datasource": {
        "type": "yesoreyeram-infinity-datasource",
        "uid": "aebgij08c3g1sa"
      },
      "fieldConfig": {
        "defaults": {
          "color": {
            "mode": "thresholds"
          },
          "custom": {
            "align": "auto",
            "cellOptions": {
              "type": "auto"
            },
            "inspect": false
          },
          "mappings": [],
          "thresholds": {
            "mode": "absolute",
            "steps": [
              {
                "color": "green",
                "value": null
              },
              {
                "color": "red",
                "value": 80
              }
            ]
          }
        },
        "overrides": []
      },
      "gridPos": {
        "h": 8,
        "w": 12,
        "x": 0,
        "y": 0
      },
      "id": 1,
      "options": {
        "cellHeight": "sm",
        "footer": {
          "countRows": false,
          "fields": "",
          "reducer": [
            "sum"
          ],
          "show": false
        },
        "showHeader": true
      },
      "pluginVersion": "10.4.15",
      "targets": [
        {
          "columns": [],
          "datasource": {
            "type": "yesoreyeram-infinity-datasource",
            "uid": "aebgij08c3g1sa"
          },
          "filters": [],
          "format": "table",
          "global_query_id": "",
          "parser": "backend",
          "refId": "A",
          "root_selector": "",
          "source": "url",
          "type": "json",
          "url": "https://api.brightdata.com/customer/balance",
          "url_options": {
            "data": "",
            "headers": [
              {
                "key": "Authorization",
                "value": "Bearer REDACTED"
              }
            ],
            "method": "GET"
          }
        }
      ],
      "title": "Brightdata total balance",
      "type": "table"
    }
  ],
  "schemaVersion": 39,
  "tags": [],
  "templating": {
    "list": []
  },
  "time": {
    "from": "now-6h",
    "to": "now"
  },
  "timepicker": {},
  "timezone": "browser",
  "title": "Providers balances",
  "uid": "aebyg43jn8hz4c",
  "version": 2,
  "weekStart": ""
}
  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.

Not really. When i turn it into timeseries it shows: Data is missing a time field

  • Did you follow any online instructions? If so, what is the URL?

There is basically no guides or forum posts regarding this topic.

Hi,

We’ll need some more info from you - can you share a sample response from the api? When you say there’s no timestamp, what do you mean - there should be one in the response? Are (Is?) the returned values grouped by something (e.g. month) or is it just a single value. If the second one timeseries would be at least… bugging? Maybe a stat panel would suit you better?

1 Like

Hello. Sure, here is the response json:

{
  "balance": 100,
  "credit": 0,
  "prepayment": 10.04,
  "pending_costs": 4.58
}

You can see there is no timestamp.

I mean, the API is responding with current status of the balance so there is no need to be.

I am not sure what are you asking but i guess it is just a single value for each field.

I would like to see how the balance was fluctuating over time (so the timeseries would be the best fit).

The main issue is Grafana wants to see timestamp in the table for each row. If there isn’t any, it cannot draw the graph.

I would like to see Grafana handle such situations by pasting current time to the table each time the API is called.

E.g: I have set the interval to 10s, which means the API is called every 10 seconds. From the point i would build the query, it would pull current status of balance every 10 seconds and would draw graph from each time points over time. I think the second issue is, i am not understanding grafana the right way. If i understand grafana correctly, it is just showing the data / tables / timeseries saved somewhere else (prometheus?). But there is also something like Infinity Data Source which can make API calls so it would be awesome to create the data and timeseries in Grafana directly.

Is there such way to achieve it without big overhead?

Tl;dr - unless api provides the data in time, there’s no way to create time series in Grafana the way you described.

Grafana is only a visualization tool. So in order to have the time series like you’re describing you’d have to have it somewhere stored (like promtehues). Infinity plugin just takes the api response and can manipulate it to some extent but Grafana (AFAIK) is not able to create series by its own. What you could do would be to either have some application or Alloy instance to “scrape” that endpoint every 10 seconds (or any other interval, cause I think you don’t really need it that often - I might be wrong) and save it to Prometheus instance.

you could use jsonata to add random date but not sure that is what you really want

or

then

1 Like