Skip to content

Instantly share code, notes, and snippets.

@rc9000
Created August 17, 2023 11:37
Show Gist options
  • Save rc9000/2f19b558fdd0973278a9d0f76b221951 to your computer and use it in GitHub Desktop.
Save rc9000/2f19b558fdd0973278a9d0f76b221951 to your computer and use it in GitHub Desktop.
nd_poller_perf.sql
$ cat /data/postgres/bin/nd_poller_perf.sql
with cte as (
select
(select count(*) from device where last_macsuck > (current_timestamp - interval '1 minute')) as macsuck_last1min,
(select count(*) from device where last_arpnip > (current_timestamp - interval '1 minute')) as arpnip_last1min,
(select count(*) from device where last_macsuck > (current_timestamp - interval '5 minutes')) as macsuck_last5min,
(select count(*) from device where last_arpnip > (current_timestamp - interval '5 minutes')) as arpnip_last5min
)
select
c.macsuck_last1min,
c.arpnip_last1min,
case (c.macsuck_last1min + c.arpnip_last1min)
when 0 then -1
else ((select count(*) from device where last_discover > current_timestamp - interval '72 hours' ) / ((c.macsuck_last1min + c.arpnip_last1min) / 2.0))::int
end as estim_cycle_1min,
c.macsuck_last5min,
c.arpnip_last5min,
case (c.macsuck_last5min + c.arpnip_last5min)
when 0 then -1
else ((select count(*) from device where last_discover > current_timestamp - interval '72 hours' ) / ((c.macsuck_last5min + c.arpnip_last5min) / 2.0) * 5)::int
end as estim_cycle_5min
from cte c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment