HI,
I am a new user to Grafana. I’ve created my dashboard using Postgres as a Data source.
I’ve followed the API for taking snapshots and have inserted the dashboard json into the api as I’ve seen mentioned in some of the community pages. The only issue I am having is that the time/snapshot is not static.
The now time is static but the start time data is disappears, as if the snapshot reads the data from the DB.
As a note, the data in the DB lasts just over 24 hours. I was creating the APi to take a daily snapshot to preserve previous data. I know I am doing something wrong. Any assistance would be greatly appreciated.
thx
dom
Figured out… found another post indicating that I needed to insert the data into my code.
Found an example of a coded snapshot api with the snapshotdata and modified it with my dashboard and inserted data ( via variables after parsing it in the proper format), with in a bash script and all is working now.
sample code ( needs some additional tuning):
psql -h $PGHOST -U $PGUSER -d $PGDATABASE -w -L PANID2.$$ -p $PGPORT << EOF
SELECT S._qmf_update_time,((S.“msgReceives” - LAG(S.“msgReceives”,1) OVER (order by S._qmf_update_time))/(((DATE_PART(‘day’, S._qmf_update_time::timestamp - LAG(S._qmf_update_time,1) OVER (order by S._qmf_update_time)::timestamp)*24 + DATE_PART(‘hour’, S._qmf_update_time::timestamp - LAG(S._qmf_update_time,1) OVER (order by S._qmf_update_time)::timestamp))*60 + DATE_PART(‘minute’, S._qmf_update_time::timestamp - LAG(S._qmf_update_time,1) OVER (order by S.qmf_update_time)::timestamp))60 + DATE_PART(‘second’, S._qmf_update_time::timestamp - LAG(S._qmf_update_time,1) OVER (order by S._qmf_update_time)::timestamp))) AS MSG_Rate FROM “org.apache.qpid.broker”.“Exchange_samples” as S join “org.apache.qpid.broker”.“Exchange” as E ON S._qmf_object_id = E._qmf_object_id AND E._qmf_agent_id = S._qmf_agent_id WHERE E.“name” = ‘BOB.Ex’ and E._qmf_agent_id LIKE ‘%13000%’;
EOF
cat PANID2.$$ | tr “|” “,” | grep -v "" | grep -v "" | grep -v “+” | grep -v “)” | grep -v “^$” | while read DATA
do
TIMEX=echo $DATA | awk -F"," '{print $1}'
DATAX=echo $DATA | awk -F"," '{print $2}'
if [ -z “$DATAX” ]
then
DATAX=‘0’
fi
NEWTIME=date +%s%3N -d"$TIMEX"
printf “[$DATAX,$NEWTIME],”>> $PANID22
done
PANID2=cat $PANID22 | sed '$s/,$//'
… in the proper panel stanza…
“targets”: [ ],
“snapshotData”: {
“data”: [
{
“target”:“msgReceives”,
“datapoints”:[
‘"$PANID2"’
]
}
]
},