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