I have a postgresql datasource in my grafana docker container.
This database has a table called posts, where 1 column is of type Time, and another of type Float.
I’m trying to create, using the http api, a dashboard with a graph with this data being updated every 5s.
Every other detail could be the default value.
So, far the only docs related to this was this. HOwever, it’s too simple, and the information seems to be incomplete for my objective…
I’ve tried sending the json below as the payload, but I get a 400 error, i.e. the body isn’t being processed, because I’m doing some mistake in it.
This is a json I saved from a different datasource, but of similar type…
{
"datasource": {
"type": "postgres",
"uid": "aff899bb-691e-4a19-aad8-7c17fc47e845"
},
"fieldConfig": {
"defaults": {
"custom": {
"drawStyle": "line",
"lineInterpolation": "linear",
"barAlignment": 0,
"lineWidth": 1,
"fillOpacity": 0,
"gradientMode": "none",
"spanNulls": false,
"showPoints": "auto",
"pointSize": 5,
"stacking": {
"mode": "none",
"group": "A"
},
"axisPlacement": "auto",
"axisLabel": "",
"axisColorMode": "text",
"scaleDistribution": {
"type": "linear"
},
"axisCenteredZero": false,
"hideFrom": {
"tooltip": false,
"viz": false,
"legend": false
},
"thresholdsStyle": {
"mode": "off"
}
},
"color": {
"mode": "palette-classic"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 0
},
"id": 2,
"options": {
"tooltip": {
"mode": "single",
"sort": "none"
},
"legend": {
"showLegend": true,
"displayMode": "list",
"placement": "bottom",
"calcs": []
}
},
"targets": [
{
"datasource": {
"type": "postgres",
"uid": "aff899bb-691e-4a19-aad8-7c17fc47e845"
},
"editorMode": "code",
"format": "table",
"key": "Q-935d0f25-aa95-4f80-b230-cd4e675787a5-0",
"rawQuery": true,
"rawSql": "SELECT created_at, rating FROM posts ",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [
{
"name": "created_at",
"type": "functionParameter"
}
],
"type": "function"
},
{
"parameters": [
{
"name": "rating",
"type": "functionParameter"
}
],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
]
},
"table": "posts"
}
],
"title": "Ratings",
"type": "timeseries"
}