Page 1 of 1

[SOLVED] Free disk space per machine

Published: July 8, 2021 - 3:24 PM
by mviale
Good morning,

I am looking to create a query that will quickly extract the free space from each machine in my fleet.

For this, there's the Freespace attribute available, which I'm trying to bring up, but it's not working:
select host_metrics->'local_drives'->>'C'->>>'FreeSpace' as "Free Space", host_metrics->'last_logged_on_user' as User, host_info->'computer_fqdn' as Name from hosts

And here's the error it's showing me
Capture.JPG
Capture.JPG (24.33 KB) Viewed 15579 times
I'm not an SQL expert at all; the last time I did it was in class about 15 years ago! It seems to be a formatting issue, if I understand correctly, but I'm a bit stuck. If anyone has any ideas...

Mathieu

Re: Free disk space per machine

Published: July 8, 2021 - 7:26 PM
by dcardon
Good evening Mathieu,

You weren't far off. But it's true that PostgreSQL's JSON query syntax isn't the most intuitive.

I added a conversion to GB and rounding to two decimal places.
select
round(((host_metrics->'local_drives'->'C'->'FreeSpace')::float / 1073741824)::numeric,2) as free_space_en_go ,
host_metrics->'last_logged_on_user' as User,
os_name,
os_version ,
host_info->'computer_fqdn' as fqdn
from hosts
order by computer_name
Denis

Re: [SOLVED] Free disk space per machine

Published: July 8, 2021 - 8:53 PM
by mviale
Good evening Denis,

thank you very much!

Mathieu

Re: [SOLVED] Free disk space per machine

Published: July 15, 2021 - 9:28 PM
by dcardon
Good evening Mathieu,
Thank you so much to you and the metropolitan area for switching to the Enterprise version. This allows us to properly fund WAPT's development and take WAPT further, and there's still a long way to go :-) !
See you soon,
Denis

Re: [SOLVED] Free disk space per machine

Published: Dec 13, 2021 - 1:25 PM
by Jonalex
Good morning,

I tried this request but I got an error message:
Error on server: ProgrammingErooc("cannot cast type jsonb to double precision
Am I the only one? :)

Thank you in advance

Re: [SOLVED] Free disk space per machine

Published: March 6, 2023 - 4:24 PM
by jtheuxb
Hello,

sorry to revive this thread after so long, but I have the same problem as the person above.
Since I'm not familiar with SQL, I'm a bit stuck. Any help would be appreciated. :)

Re: [SOLVED] Free disk space per machine

Published: March 7, 2023 - 10:54 AM
by dcardon
Hello Jérôme,

please do not revive a topic marked as RESOLVED, as this makes forum moderation a bit complicated.

You can start a new topic and reference the existing one. It might also be helpful to specify the version of Wapt you are using.

Regards,

Denis