Compare commits
No commits in common. "422e86f0a7c87bc670a1f668d948b482057d9593" and "6c67de3bc96de2875ed85cc2b06aa5381905ee64" have entirely different histories.
422e86f0a7
...
6c67de3bc9
|
@ -13,50 +13,32 @@ csr = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
|
||||||
csr.execute(
|
csr.execute(
|
||||||
"""
|
"""
|
||||||
with recursive
|
with recursive t as (
|
||||||
t as (
|
|
||||||
select '2 minutes'::interval as d
|
select '2 minutes'::interval as d
|
||||||
union
|
union
|
||||||
select d * 2 from t where d < '1 year'::interval
|
select d * 2 from t where d < '1 year'::interval
|
||||||
),
|
),
|
||||||
fs as (
|
a as (
|
||||||
select distinct hostname, filesystem
|
select distinct hostname, filesystem, min(ts), max(ts)
|
||||||
from df
|
from df, t
|
||||||
where ts >= now() - '2 minutes'::interval
|
where ts >= now() - t.d
|
||||||
group by hostname, filesystem
|
group by hostname, filesystem, t.d
|
||||||
),
|
),
|
||||||
forecast as (
|
forecast as (
|
||||||
select
|
select
|
||||||
fs.hostname, fs.filesystem,
|
a.hostname, a.filesystem,
|
||||||
new.ts + (new.ts - old.ts) as when,
|
c.ts - b.ts as d,
|
||||||
new.ts + (new.ts - old.ts) - now() as d,
|
c.ts + (c.ts - b.ts) as when,
|
||||||
new.f_used + (new.f_used - old.f_used) as used,
|
c.f_used + (c.f_used - b.f_used) as used,
|
||||||
(new.f_used + (new.f_used - old.f_used)) / old.f_usable * 100 as percent,
|
(c.f_used + (c.f_used - b.f_used)) / b.f_usable * 100 as percent,
|
||||||
(new.f_used + (new.f_used - old.f_used)) > old.f_usable as capacity_exceeded
|
(c.f_used + (c.f_used - b.f_used)) > b.f_usable as capacity_exceeded
|
||||||
from fs, t,
|
from a
|
||||||
lateral (
|
join df b on (a.hostname = b.hostname and a.filesystem = b.filesystem and a.min = b.ts)
|
||||||
select *
|
join df c on (a.hostname = c.hostname and a.filesystem = c.filesystem and a.max = c.ts)
|
||||||
from df
|
|
||||||
where
|
|
||||||
df.hostname = fs.hostname
|
|
||||||
and df.filesystem = fs.filesystem
|
|
||||||
and df.ts >= now() - t.d
|
|
||||||
order by ts
|
|
||||||
limit 1
|
|
||||||
) old,
|
|
||||||
lateral (
|
|
||||||
select *
|
|
||||||
from df
|
|
||||||
where
|
|
||||||
df.hostname = fs.hostname
|
|
||||||
and df.filesystem = fs.filesystem
|
|
||||||
order by ts desc
|
|
||||||
limit 1
|
|
||||||
) new
|
|
||||||
)
|
)
|
||||||
select * from forecast
|
select * from forecast
|
||||||
where capacity_exceeded
|
where capacity_exceeded
|
||||||
order by "when"
|
order by 1, 2, 3
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -13,50 +13,32 @@ csr = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
|
||||||
csr.execute(
|
csr.execute(
|
||||||
"""
|
"""
|
||||||
with recursive
|
with recursive t as (
|
||||||
t as (
|
|
||||||
select '2 minutes'::interval as d
|
select '2 minutes'::interval as d
|
||||||
union
|
union
|
||||||
select d * 2 from t where d < '1 year'::interval
|
select d * 2 from t where d < '1 year'::interval
|
||||||
),
|
),
|
||||||
fs as (
|
a as (
|
||||||
select distinct hostname, filesystem
|
select distinct hostname, filesystem, min(ts), max(ts)
|
||||||
from df
|
from df, t
|
||||||
where ts >= now() - '2 minutes'::interval
|
where ts >= now() - t.d
|
||||||
group by hostname, filesystem
|
group by hostname, filesystem, t.d
|
||||||
),
|
),
|
||||||
forecast as (
|
forecast as (
|
||||||
select
|
select
|
||||||
fs.hostname, fs.filesystem,
|
a.hostname, a.filesystem,
|
||||||
new.ts + (new.ts - old.ts) as when,
|
c.ts - b.ts as d,
|
||||||
new.ts + (new.ts - old.ts) - now() as d,
|
c.ts + (c.ts - b.ts) as when,
|
||||||
new.s_used + (new.s_used - old.s_used) as used,
|
c.s_used + (c.s_used - b.s_used) as used,
|
||||||
(new.s_used + (new.s_used - old.s_used)) / old.s_usable * 100 as percent,
|
(c.s_used + (c.s_used - b.s_used)) / b.s_usable * 100 as percent,
|
||||||
(new.s_used + (new.s_used - old.s_used)) > old.s_usable as capacity_exceeded
|
(c.s_used + (c.s_used - b.s_used)) > b.s_usable as capacity_exceeded
|
||||||
from fs, t,
|
from a
|
||||||
lateral (
|
join df b on (a.hostname = b.hostname and a.filesystem = b.filesystem and a.min = b.ts)
|
||||||
select *
|
join df c on (a.hostname = c.hostname and a.filesystem = c.filesystem and a.max = c.ts)
|
||||||
from df
|
|
||||||
where
|
|
||||||
df.hostname = fs.hostname
|
|
||||||
and df.filesystem = fs.filesystem
|
|
||||||
and df.ts >= now() - t.d
|
|
||||||
order by ts
|
|
||||||
limit 1
|
|
||||||
) old,
|
|
||||||
lateral (
|
|
||||||
select *
|
|
||||||
from df
|
|
||||||
where
|
|
||||||
df.hostname = fs.hostname
|
|
||||||
and df.filesystem = fs.filesystem
|
|
||||||
order by ts desc
|
|
||||||
limit 1
|
|
||||||
) new
|
|
||||||
)
|
)
|
||||||
select * from forecast
|
select * from forecast
|
||||||
where capacity_exceeded
|
where capacity_exceeded
|
||||||
order by "when"
|
order by 1, 2, 3
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
4
df2db
4
df2db
|
@ -12,7 +12,6 @@ csr = db.cursor()
|
||||||
with open("/proc/mounts") as mounts:
|
with open("/proc/mounts") as mounts:
|
||||||
for mount in mounts:
|
for mount in mounts:
|
||||||
(dev, mountpoint, fstype, rest) = mount.split(' ', 3)
|
(dev, mountpoint, fstype, rest) = mount.split(' ', 3)
|
||||||
try:
|
|
||||||
s = os.statvfs(mountpoint)
|
s = os.statvfs(mountpoint)
|
||||||
if s.f_blocks == 0:
|
if s.f_blocks == 0:
|
||||||
continue # not a real file system
|
continue # not a real file system
|
||||||
|
@ -41,9 +40,6 @@ with open("/proc/mounts") as mounts:
|
||||||
(hostname, mountpoint,
|
(hostname, mountpoint,
|
||||||
s_total, s_usable, s_used,
|
s_total, s_usable, s_used,
|
||||||
f_total, f_usable, f_used))
|
f_total, f_usable, f_used))
|
||||||
except PermissionError:
|
|
||||||
# silently ignore some errors
|
|
||||||
pass
|
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue