Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor SQL query result #2342

Open
1 task done
thedatabaseme opened this issue Nov 23, 2022 · 10 comments · May be fixed by #5429 or #3919
Open
1 task done

Monitor SQL query result #2342

thedatabaseme opened this issue Nov 23, 2022 · 10 comments · May be fixed by #5429 or #3919
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added

Comments

@thedatabaseme
Copy link

⚠️ Please verify that this feature request has NOT been suggested before.

  • I checked and didn't find similar feature request

🏷️ Feature Request Type

New Monitor

🔖 Feature description

Hello,

I would love to see the possibility within Uptime-Kuma, to specify an expected result within a SQL query monitor type (e.g. Postgres).
So a SQL monitor would not only check if it can connect to a database and can execute a query.
Another wish from my side would be, to store the query result in the heartbeat data. You could cut the result to save space, but at least one would have some idea on how the result looked like.

Kind regards
Philip

✔️ Solution

I want to check for the replication status of a Postgres cluster and if a specific cluster member is in recovery or not. So a query like select * from pg_is_in_recovery(); would return either t (true) or f (false). I would like to have the possibility to monitor for the expected result.

❓ Alternatives

If you don't consider to implement this request, at least the result should be exported as a metric so that I can filter on it later. Implementing both options, would be the best solution.

📝 Additional Context

No response

@thedatabaseme thedatabaseme added the feature-request Request for new features to be added label Nov 23, 2022
@blackandred
Copy link

Alternatively you can try to use Infracheck with a custom script, expose the endpoint and just ping it using a regular HTTP check in Uptime Kuma.

https://infracheck.docs.riotkit.org/en/latest/

@cfoellmann
Copy link

I am with @thedatabaseme
I would like to set my SQL statement and define a return value for up (and down).
Or just "0 = down" and "1 = up". Forming the return in your query is easy enough, right?

In my case I would count the rows of a table and return "DOWN" if the count is 0.

@evolucja
Copy link

evolucja commented Apr 11, 2023

Totally for it. Doesn't seem to be very complicated to implement.

@rogerioadris
Copy link

Is there any condition of the query to return down? or is the query just executed without monitoring the return?

@thedatabaseme
Copy link
Author

Is there any condition of the query to return down? or is the query just executed without monitoring the return?

My understanding of the current implementation is, that there is no actual check for the result of the SQL query. When the query finishes without error, the monitor is up. Else it's down.

@rogerioadris
Copy link

Thanks for the answer.
I solved my problem as follows

IF NOT EXISTS(.........) BEGIN
    THROW 51000, 'ERROR XXXXX.', 1;  
END

@wvolkov
Copy link

wvolkov commented Mar 20, 2024

Thx to @rogerioadris idea, I could use it at PostgresSQL as well:

do
$$
declare
	total_errors int2;
	err_text text;
begin

select
		count(*) as total_errors,
		string_agg(p.query || ':\n' || p.context , '\n\n') as x 
into
		total_errors,
		err_text
from
		pglog p
where
		error_severity != 'LOG'
		and application_name = 'pg_cron'
		and log_time > now() - interval '1 day';
	
IF total_errors > 0 THEN
    raise 'Failed Queries\n ```%s```', err_text;  
end if;
	
end
$$

@YuriyGavrilov

This comment was marked as resolved.

@YuriyGavrilov

This comment was marked as resolved.

@CommanderStorm

This comment was marked as resolved.

@kwrx kwrx linked a pull request Dec 10, 2024 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:monitor Everything related to monitors feature-request Request for new features to be added
Projects
None yet
8 participants