Jira (FACT-2128) fact mountpoints does not correctly calculates mountpoint capacity

23 views
Skip to first unread message

Valentyna (JIRA)

unread,
Nov 19, 2019, 4:14:03 AM11/19/19
to puppe...@googlegroups.com
Valentyna created an issue
 
Facter / Bug FACT-2128
fact mountpoints does not correctly calculates mountpoint capacity
Issue Type: Bug Bug
Assignee: Unassigned
Created: 2019/11/19 1:13 AM
Priority: Normal Normal
Reporter: Valentyna

I have (root /) mountpoint my df output looks:

root@test:~# df /dev/sdb2
Filesystem  1K-blocks   Used         Available   Use% Mounted on
/dev/sdb2   19555608   15877636 2661556   86%    /

df displays correct data as 86% used on this mountpoint.

Fact mountpoints displays:

root@test:~# facter mountpoints./

{ available => "3.51 GiB", available_bytes => 3766226944, capacity => "81.19%", device => "/dev/sdb2", filesystem => "ext4", options => [ "rw", "relatime", "errors=remount-ro", "stripe=32624", "data=ordered" ], size => "18.65 GiB", size_bytes => 20024942592, used => "15.14 GiB", used_bytes => 16258715648 }

It displays only 81.19% of used space.

I think to solve the problem instead of dividing Used÷1K-blocks 15877632÷19555608×100=81,19%, should divide Available÷1K-blocks ex. 100−2661560÷19555608×100=86,38%.

Add Comment Add Comment
 
This message was sent by Atlassian JIRA (v7.7.1#77002-sha1:e75ca93)
Atlassian logo

Valentyna (JIRA)

unread,
Nov 22, 2019, 2:22:05 AM11/22/19
to puppe...@googlegroups.com
Valentyna updated an issue
Change By: Valentyna
I have (root /) mountpoint my df output looks:

root@test:~# df /dev/sdb2
Filesystem  1K-blocks   Used        
 
Available   Use% Mounted on
/dev/sdb2   19555608  
15877636 2661556 15911760   2627432     86%    /

df displays correct data as {color:#14892c}*86%*{color} used on this mountpoint.


Fact mountpoints displays:

root@test:~# facter mountpoints./

{
available => "3.
51 48 GiB",
available_bytes =>
3766226944 3731296256 ,
capacity => "81.
19 37 %",

device => "/dev/sdb2",
filesystem => "ext4",
options => [
"rw",
"relatime",
"errors=remount-ro",
"stripe=32624",
"data=ordered"
],
size => "18.65 GiB",
size_bytes => 20024942592,
used => "15. 14 17 GiB",
used_bytes =>
16258715648 16293646336
}

It displays only {color:#d04437}*81.
19 37 %*{color} of used space.

I
think `ve read df manpage on [http://manpages.ubuntu.com/manpages/trusty/man1/df.1posix.html] which describes where to solve the problem instead get differrent types of dividing spaces and how to calculate used space. As a result I`ve created cpp file which correctly calculates available, free and used space.

#include<stdio.h>
#include<sys/stat.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/vfs.h>

int main(int argc, char
* argv[]) { color
   struct statfs stats;
   statfs("/", &stats);
   printf("fragment size %lu\n", stats.f_frsize);
   printf("blocks size in f_frsize units %lu\n", stats.f_blocks);
   printf("free blocks %lu\n", stats.f_bfree);
   printf("free blocks for unprivileged users
: #d04437}Used÷1K %lu\n", stats.f_bavail);

   unsigned long *total* = stats.f_blocks * stats.f_frsize / 1024;
   unsigned long *available* = stats.f_bavail * stats.f_frsize / 1024;
   unsigned long *free* = stats.f_bfree * stats.f_frsize / 1024;
   unsigned long *used* = total
- blocks free;
   float uf = used + available;
   float usedpercent = used / uf * 100;
   printf("total %lu\n", total);
   printf("available: %lu\n", available);
   printf("used: %lu\n", used);
   printf("percent: %f\n", usedpercent);

}

{color :#14892c } * 15877632÷19555608×100= {color:# FF0000 59afe1 } *81,19%*  I`ve get output: {color} , should divide
{color :#14892c } *Available÷1K-blocks*

{color :#333333 } ex. 100−2661560÷ fragment size 4096
blocks size in f_frsize units 4888902
free blocks 910962
free blocks for unprivileged users: 656858
total
19555608 ×100=
available: 2627432
used: 15911760
{color:#14892c}* 86,38%* usedpercent: 85 . 827690* {color} {color}

Valentyna (JIRA)

unread,
Nov 22, 2019, 2:23:04 AM11/22/19
to puppe...@googlegroups.com

Valentyna (JIRA)

unread,
Nov 22, 2019, 2:23:04 AM11/22/19
to puppe...@googlegroups.com
Valentyna updated an issue
I have (root /) mountpoint my df output looks:

root@test:~# df /dev/sdb2
Filesystem  1K-blocks   Used          Available   Use% Mounted on
/dev/sdb2   19555608   15911760  2627432   86%    /


df displays correct data as {color:#14892c}*86%*{color} used on this mountpoint.

Fact mountpoints displays:

root@test:~# facter mountpoints./

{

available => "3.48 GiB",
available_bytes => 3731296256,
capacity => "81.37%",
device => "/dev/sdb2",
filesystem => "ext4",
options => [
"rw",
"relatime",
"errors=remount-ro",
"stripe=32624",
"data=ordered"
],
size => "18.65 GiB",
size_bytes => 20024942592,
used => "15.17 GiB",
used_bytes => 16293646336
}

It displays only {color:#d04437}*81.37%*{color} of used space.

I`ve read df manpage on [http://manpages.ubuntu.com/manpages/trusty/man1/df.1posix.html] which describes where to get differrent types of spaces and how to calculate used space. As a result I`ve created cpp file which correctly calculates available, free and used space.


#include<stdio.h>
#include<sys/stat.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/vfs.h>

int main(int argc, char* argv [ ^disk_usage.cpp ] ) {
   struct statfs stats;
 
  statfs("/", &stats);
   printf("fragment size %lu\n", stats.f_frsize);
   printf("blocks size in f_frsize units %lu\n", stats.f_blocks);
   printf("free blocks %lu\n", stats.f_bfree);
   printf("free blocks for unprivileged users: %lu\n", stats.f_bavail);


   unsigned long *total* = stats.f_blocks * stats.f_frsize / 1024;
   unsigned long *available* = stats.f_bavail * stats.f_frsize / 1024;
   unsigned long *free* = stats.f_bfree * stats.f_frsize / 1024;
   unsigned long *used* = total - free;

   float uf = used + available;
   float usedpercent = used / uf * 100;
   printf("total %lu\n", total);
   printf("available: %lu\n", available);
   printf("used: %lu\n", used);
   printf("percent: %f\n", usedpercent);

}

{color:#14892c} {color:#59afe1}  I`ve get output:{color}
{color}

{color:#333333}
fragment size 4096

blocks size in f_frsize units 4888902
free blocks 910962
free blocks for unprivileged users: 656858
total 19555608
available: 2627432
used: 15911760
{color:#14892c} *usedpercent: 85.827690* {color}{color}

Valentyna (JIRA)

unread,
Nov 22, 2019, 2:24:04 AM11/22/19
to puppe...@googlegroups.com
Valentyna updated an issue
I have (root /) mountpoint my df output looks:

root@test:~# df /dev/sdb2
Filesystem  1K-blocks   Used          Available   Use% Mounted on
/dev/sdb2   19555608   15911760  2627432   86%    /

df displays correct data as {color:#14892c}*86%*{color} used on this mountpoint.

Fact mountpoints displays:

root@test:~# facter mountpoints./

{ available => "3.48 GiB", available_bytes => 3731296256, capacity => "81.37%", device => "/dev/sdb2", filesystem => "ext4", options => [ "rw", "relatime", "errors=remount-ro", "stripe=32624", "data=ordered" ], size => "18.65 GiB", size_bytes => 20024942592, used => "15.17 GiB", used_bytes => 16293646336 }

It displays only {color:#d04437}*81.37%*{color} of used space.

I`ve read df manpage on [http://manpages.ubuntu.com/manpages/trusty/man1/df.1posix.html] which describes where to get differrent types of spaces and how to calculate used space. As a result I`ve created cpp file which correctly calculates available, free and used space. [^disk_usage.cpp]

 

{color:#14892c} I `ve get output:{color}

fragment size 4096
blocks size in f_frsize units 4888902
free blocks 910962
free blocks for unprivileged users: 656858
total 19555608
available: 2627432
used: 15911760
*usedpercent: 85.827690*

Valentyna (JIRA)

unread,
Nov 22, 2019, 5:53:04 AM11/22/19
to puppe...@googlegroups.com
Valentyna updated an issue
I have (root /) mountpoint my df output looks:

root@test:~# df /dev/sdb2
Filesystem  1K-blocks   Used          Available   Use% Mounted on
/dev/sdb2   19555608   15911760  2627432   86%    /

df displays correct data as {color:#14892c}*86%*{color} used on this mountpoint.

Fact mountpoints displays:

root@test:~# facter mountpoints./

{ available => "3.48 GiB", available_bytes => 3731296256, capacity => "81.37%", device => "/dev/sdb2", filesystem => "ext4", options => [ "rw", "relatime", "errors=remount-ro", "stripe=32624", "data=ordered" ], size => "18.65 GiB", size_bytes => 20024942592, used => "15.17 GiB", used_bytes => 16293646336 }

It displays only {color:#d04437}*81.37%*{color} of used space.

I`ve read df manpage on [http://manpages.ubuntu.com/manpages/trusty/man1/df.1posix.html] which describes where to get differrent types of spaces and how to calculate used space. As a result I`ve created cpp file which correctly calculates available, free and used space. [^disk_usage.cpp]

{color:#14892c} I get output:{color}

fragment size 4096
blocks size in f_frsize units 4888902
free blocks 910962
free blocks for unprivileged users: 656858
total 19555608
available: 2627432
used: 15911760
*usedpercent: 85.827690*


 

I`ve already created *pull request* on git to solve this problem https://github.com/puppetlabs/facter/pull/1846

Gheorghe Popescu (JIRA)

unread,
Nov 27, 2019, 3:02:05 AM11/27/19
to puppe...@googlegroups.com

Gheorghe Popescu (JIRA)

unread,
Nov 27, 2019, 3:02:05 AM11/27/19
to puppe...@googlegroups.com

Gheorghe Popescu (JIRA)

unread,
Nov 27, 2019, 4:56:03 AM11/27/19
to puppe...@googlegroups.com

Gheorghe Popescu (JIRA)

unread,
Nov 27, 2019, 4:56:03 AM11/27/19
to puppe...@googlegroups.com

Gheorghe Popescu (JIRA)

unread,
Jan 15, 2020, 5:44:05 AM1/15/20
to puppe...@googlegroups.com

Jean Bond (JIRA)

unread,
Jan 15, 2020, 2:00:04 PM1/15/20
to puppe...@googlegroups.com
Jean Bond updated an issue
Change By: Jean Bond
Labels: resolved-issue-added
Reply all
Reply to author
Forward
0 new messages