Skip to contentSkip to conversation

mountstats: Adding 'Day:Hour:Min:Sec' format along with 'age' to "mountstats --nfs" for ease of understanding.

PATCH Superseded Rohan Sable 3 participants 6 messages Jun 4, 2020 2 messages not in the archive

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mountstats: Adding 'Day:Hour:Min:Sec' format along with 'age' to "mountstats --nfs" for ease of understanding.

This patch adds printing of 'Age' in 'Sec' and 'Day:Hours:Min:Sec' like below to --nfs in mountstats :
NFS mount age: 9479; 0 Day(s) 2 Hour(s) 37 Min(s) 59 Sec(s)

---
 tools/mountstats/mountstats.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)
tools/mountstats/mountstats.py +12 -0
index d565385d..c4f4f9e6 100755
@@ -233,6 +233,16 @@ Nfsv4ops = [
     'COPY_NOTIFY'
 ]
 
+# Function to convert sec from age to Day:Hours:Min:Sec.
+def sec_conv(rem):
+    day = int(rem / (24 * 3600))
+    rem %= (24 * 3600)
+    hrs = int(rem / 3600)
+    rem %= 3600
+    min = int(rem / 60)
+    sec = rem % 60
+    print(day, "Day(s)", hrs, "Hour(s)", min, "Min(s)", sec, "Sec(s)")
+
 class DeviceData:
     """DeviceData objects provide methods for parsing and displaying
     data for a single mount grabbed from /proc/self/mountstats
@@ -391,6 +401,8 @@ class DeviceData:
         """Pretty-print the NFS options
         """
         print('  NFS mount options: %s' % ','.join(self.__nfs_data['mountoptions']))
+        print('  NFS mount age: %d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
         print('  NFS server capabilities: %s' % ','.join(self.__nfs_data['servercapabilities']))
         if 'nfsv4flags' in self.__nfs_data:
             print('  NFSv4 capability flags: %s' % ','.join(self.__nfs_data['nfsv4flags']))
Signature · 1 line
2.25.4
#1 lore raw
Quoted 20 lines · Rohan Sable

This patch adds printing of 'Age' in 'Sec' and 'Day:Hours:Min:Sec' like below to --nfs in mountstats :
NFS mount age: 9479; 0 Day(s) 2 Hour(s) 37 Min(s) 59 Sec(s)

---
tools/mountstats/mountstats.py | 12 ++++++++++++

1 file changed, 12 insertions(+)
tools/mountstats/mountstats.py +0 -0
index d565385d..c4f4f9e6 100755
@@ -233,6 +233,16 @@ Nfsv4ops = [
    'COPY_NOTIFY'

]

tools/mountstats/mountstats.py Nfsv4ops = [ · line 245

Quoted 10 lines
tools/mountstats/mountstats.py +10 -0
+# Function to convert sec from age to Day:Hours:Min:Sec.
+def sec_conv(rem):
+    day = int(rem / (24 * 3600))
+    rem %= (24 * 3600)
+    hrs = int(rem / 3600)
+    rem %= 3600
+    min = int(rem / 60)
+    sec = rem % 60
+    print(day, "Day(s)", hrs, "Hour(s)", min, "Min(s)", sec, "Sec(s)")
+

Just wondering if there's a Python module that can do this for us?

Quoted 15 lines

class DeviceData:
"""DeviceData objects provide methods for parsing and displaying data for a single mount grabbed from /proc/self/mountstats

tools/mountstats/mountstats.py +2 -0
@@ -391,6 +401,8 @@ class DeviceData:
        """Pretty-print the NFS options
        """
        print('  NFS mount options: %s' % ','.join(self.__nfs_data['mountoptions']))
+        print('  NFS mount age: %d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
        print('  NFS server capabilities: %s' % ','.join(self.__nfs_data['servercapabilities']))
        if 'nfsv4flags' in self.__nfs_data:
            print('  NFSv4 capability flags: %s' % ','.join(self.__nfs_data['nfsv4flags']))
Signature · 1 line
2.25.4

--
Chuck Lever

#2 lore raw

Using the datetime module?

datetime.timedelta(seconds = n)
Should print in below format
0:11:05

Quoted 56 lines · Chuck Lever
Quoted 21 lines · Rohan Sable

This patch adds printing of 'Age' in 'Sec' and 'Day:Hours:Min:Sec' like below to --nfs in mountstats :
NFS mount age: 9479; 0 Day(s) 2 Hour(s) 37 Min(s) 59 Sec(s)

---
tools/mountstats/mountstats.py | 12 ++++++++++++

1 file changed, 12 insertions(+)
tools/mountstats/mountstats.py +0 -0
index d565385d..c4f4f9e6 100755
@@ -233,6 +233,16 @@ Nfsv4ops = [
    'COPY_NOTIFY'

]

tools/mountstats/mountstats.py Nfsv4ops = [ · line 245

Quoted 10 lines
tools/mountstats/mountstats.py +10 -0
+# Function to convert sec from age to Day:Hours:Min:Sec.
+def sec_conv(rem):
+    day = int(rem / (24 * 3600))
+    rem %= (24 * 3600)
+    hrs = int(rem / 3600)
+    rem %= 3600
+    min = int(rem / 60)
+    sec = rem % 60
+    print(day, "Day(s)", hrs, "Hour(s)", min, "Min(s)", sec, "Sec(s)")
+

Just wondering if there's a Python module that can do this for us?

Quoted 13 lines

class DeviceData:
"""DeviceData objects provide methods for parsing and displaying data for a single mount grabbed from /proc/self/mountstats

tools/mountstats/mountstats.py +2 -1
@@ -391,6 +401,8 @@ class DeviceData:
        """Pretty-print the NFS options
        """
        print('  NFS mount options: %s' % ','.join(self.__nfs_data['mountoptions']))
+        print('  NFS mount age: %d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
        print('  NFS server capabilities: %s' % ','.join(self.__nfs_data['servercapabilities']))
        if 'nfsv4flags' in self.__nfs_data:
            print('  NFSv4 capability flags: %s' % ','.join(self.__nfs_data['nfsv4flags']))
--
Quoted 2 lines

2.25.4

--
Chuck Lever

#3 lore raw

I get the below results using the datetime module.

# mountstats --nfs | grep -w age
  NFS mount age: 688865; 7 days, 23:21:05
Quoted 64 lines · Kenneth Dsouza

Using the datetime module?

datetime.timedelta(seconds = n)
Should print in below format
0:11:05

Quoted 56 lines · Chuck Lever
Quoted 21 lines · Rohan Sable

This patch adds printing of 'Age' in 'Sec' and 'Day:Hours:Min:Sec' like below to --nfs in mountstats :
NFS mount age: 9479; 0 Day(s) 2 Hour(s) 37 Min(s) 59 Sec(s)

---
tools/mountstats/mountstats.py | 12 ++++++++++++

1 file changed, 12 insertions(+)
tools/mountstats/mountstats.py +0 -0
index d565385d..c4f4f9e6 100755
@@ -233,6 +233,16 @@ Nfsv4ops = [
    'COPY_NOTIFY'

]

tools/mountstats/mountstats.py Nfsv4ops = [ · line 245

Quoted 10 lines
tools/mountstats/mountstats.py +10 -0
+# Function to convert sec from age to Day:Hours:Min:Sec.
+def sec_conv(rem):
+    day = int(rem / (24 * 3600))
+    rem %= (24 * 3600)
+    hrs = int(rem / 3600)
+    rem %= 3600
+    min = int(rem / 60)
+    sec = rem % 60
+    print(day, "Day(s)", hrs, "Hour(s)", min, "Min(s)", sec, "Sec(s)")
+

Just wondering if there's a Python module that can do this for us?

Quoted 13 lines

class DeviceData:
"""DeviceData objects provide methods for parsing and displaying data for a single mount grabbed from /proc/self/mountstats

tools/mountstats/mountstats.py +2 -1
@@ -391,6 +401,8 @@ class DeviceData:
        """Pretty-print the NFS options
        """
        print('  NFS mount options: %s' % ','.join(self.__nfs_data['mountoptions']))
+        print('  NFS mount age: %d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
        print('  NFS server capabilities: %s' % ','.join(self.__nfs_data['servercapabilities']))
        if 'nfsv4flags' in self.__nfs_data:
            print('  NFSv4 capability flags: %s' % ','.join(self.__nfs_data['nfsv4flags']))
--
Quoted 2 lines

2.25.4

--
Chuck Lever

#4 lore raw
Quoted 8 lines · Kenneth Dsouza

I get the below results using the datetime module.

# mountstats --nfs | grep -w age
 NFS mount age: 688865; 7 days, 23:21:05

For pretty-printing the mount point's age, you probably don't need to display the raw delta seconds value.

Quoted 57 lines · Kenneth Dsouza
Quoted 56 lines

Using the datetime module?

datetime.timedelta(seconds = n)
Should print in below format
0:11:05

Quoted 48 lines · Chuck Lever
Quoted 21 lines · Rohan Sable

This patch adds printing of 'Age' in 'Sec' and 'Day:Hours:Min:Sec' like below to --nfs in mountstats :
NFS mount age: 9479; 0 Day(s) 2 Hour(s) 37 Min(s) 59 Sec(s)

---
tools/mountstats/mountstats.py | 12 ++++++++++++

1 file changed, 12 insertions(+)
tools/mountstats/mountstats.py +0 -0
index d565385d..c4f4f9e6 100755
@@ -233,6 +233,16 @@ Nfsv4ops = [
   'COPY_NOTIFY'

]

tools/mountstats/mountstats.py Nfsv4ops = [ · line 245

Quoted 10 lines
tools/mountstats/mountstats.py +10 -0
+# Function to convert sec from age to Day:Hours:Min:Sec.
+def sec_conv(rem):
+    day = int(rem / (24 * 3600))
+    rem %= (24 * 3600)
+    hrs = int(rem / 3600)
+    rem %= 3600
+    min = int(rem / 60)
+    sec = rem % 60
+    print(day, "Day(s)", hrs, "Hour(s)", min, "Min(s)", sec, "Sec(s)")
+

Just wondering if there's a Python module that can do this for us?

Quoted 13 lines

class DeviceData:
"""DeviceData objects provide methods for parsing and displaying data for a single mount grabbed from /proc/self/mountstats

tools/mountstats/mountstats.py +2 -1
@@ -391,6 +401,8 @@ class DeviceData:
       """Pretty-print the NFS options
       """
       print('  NFS mount options: %s' % ','.join(self.__nfs_data['mountoptions']))
+        print('  NFS mount age: %d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
       print('  NFS server capabilities: %s' % ','.join(self.__nfs_data['servercapabilities']))
       if 'nfsv4flags' in self.__nfs_data:
           print('  NFSv4 capability flags: %s' % ','.join(self.__nfs_data['nfsv4flags']))
--
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
Quoted 2 lines

2.25.4

--
Chuck Lever

--
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): CAC0K3ih2GF6sxio70WMVxiO24e7xfRjVFfgScFSvYRSyjZ4+XQ@mail.gmail.com

A message that is not in the archive (sent off-list or not yet received): CAC0K3iiJ3vdvAidLugYeCJGU669=tdd2a4Dj_iez2MVrWsdNfA@mail.gmail.com

#7 lore raw
Quoted 7 lines · Rohan Sable
Quoted 3 lines
Quoted 3 lines

For pretty-printing the mount point's age, you probably don't need to display the raw delta seconds value.

Quoted 6 lines

Yes, I can drop that.

Quoted 1 line
Quoted 1 line

Just wondering if there's a Python module that can do this for us?

I was not exactly sure if I could be doing that, since this is kind of the 1st one for me. If that's fine, using the timedate module makes it way smaller and easier.

Importing "datetime" should be fine.

--
Chuck Lever