Display time difference between 2 timestamps and alert if exceed the limit

Hello,

I’m new to Grafana. I need to create a simple dashboard to display how much time is elapsed from the request to a server and the response from the server.

So, I’ve a table (in Postgres):

id client_id message_id operation_type request_timestamp response_timestamp
5789 99990002 1 P001 2022-04-29 16:32:36.613753+02 2022-04-29 16:32:37.142817+02
5790 99990002 2 P001 2022-04-29 16:32:36.619755+02 2022-04-29 16:32:37.145819+02
5791 99990004 1 P004 2022-04-29 16:32:37.132818+02 2022-04-29 16:32:38.120785+02

I want to display the time difference (response_timestamp - request_timestamp), divided in category (operation_type). I want to see if the time is growing up, and alert if it go over a limit.

I can’t understand how to do the query, and what kind of graph is required, to achieve a real time dashboard.

SOLVED converting the time in milliseconds

SELECT
req_datetime AS “time”,
op_type,
extract (MILLISECONDS FROM (res_datetime - req_datetime)) AS ka_milliseconds
FROM ptsrv_simulationregistry
WHERE
$__timeFilter(req_datetime)
AND op_type = ‘P004’
ORDER BY 1,2,3