简体   繁体   中英

How to SELECT (NOW() - LAST PING ) as "seconds from last ping" in SQL

I'm trying to write just a simple sql query on an observability platform like Grafana that will check if a server is up and running - On my database there is a table called ping and what it does is that it usually sends ping request every 15mins to check if the server is up and then stores all the records on the ping table.

SELECT DATE_FORMAT((
    SELECT timeint 
    from mio.nyp_ping 
    ORDER BY timeint DESC 
    LIMIT 1) , '%Y-%M-%D-%H-%') AS Result;

2022-February-3rd-10-02

Use the MAX() function to get the last ping time.

SELECT TIME_TO_SEC(TIMEDIFF(NOW(), MAX(ping_time))) AS "seconds from last ping"
FROM ping

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM