Skip to contentSkip to conversation

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

PATCH Superseded Rohan Sable 2 participants 2 messages Jun 2, 2020 – Jun 3, 2020

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

The output will look something like this :

From :
age: 2215

To :
age: 2267; 0 Day(s) 0 Hour(s) 37 Min(s) 47 Sec(s)

---
 tools/mountstats/mountstats.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +11 -1
index 6ac83ccb..d9b5af1b 100755
@@ -228,6 +228,15 @@ Nfsv4ops = [
     'CLONE'
 ]
 
+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
@@ -349,7 +358,8 @@ class DeviceData:
             (self.__nfs_data['export'], self.__nfs_data['mountpoint'], \
             self.__nfs_data['fstype'], self.__nfs_data['statvers']))
         print('\topts:\t%s' % ','.join(self.__nfs_data['mountoptions']))
-        print('\tage:\t%d' % self.__nfs_data['age'])
+        print('\tage:\t%d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])
         print('\tcaps:\t%s' % ','.join(self.__nfs_data['servercapabilities']))
         print('\tsec:\tflavor=%d,pseudoflavor=%d' % (self.__nfs_data['flavor'], \
             self.__nfs_data['pseudoflavor']))
Signature · 1 line
2.25.4
#1 lore raw

Hi Rohan,

Quoted 34 lines · Rohan Sable

The output will look something like this :

From :
age: 2215

To :
age: 2267; 0 Day(s) 0 Hour(s) 37 Min(s) 47 Sec(s)

---
 tools/mountstats/mountstats.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
tools/mountstats/mountstats.py +9 -0
index 6ac83ccb..d9b5af1b 100755
@@ -228,6 +228,15 @@ Nfsv4ops = [
     'CLONE'
 ]
 
+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

tools/mountstats/mountstats.py class DeviceData: · line 362

Quoted 6 lines
tools/mountstats/mountstats.py +2 -1
@@ -349,7 +358,8 @@ class DeviceData:
             (self.__nfs_data['export'], self.__nfs_data['mountpoint'], \
             self.__nfs_data['fstype'], self.__nfs_data['statvers']))
         print('\topts:\t%s' % ','.join(self.__nfs_data['mountoptions']))
-        print('\tage:\t%d' % self.__nfs_data['age'])
+        print('\tage:\t%d' % self.__nfs_data['age'], end="; ")
+        sec_conv(self.__nfs_data['age'])

If you write this raw output to a file, you can no longer use the resulting file with 'mountstats --file' or 'mountstats --since':

[smayhew@aion nfs-utils]$ tools/mountstats/mountstats.py --file b1 --since a1 Traceback (most recent call last):
File "tools/mountstats/mountstats.py", line 1130, in <module>
res = main()
File "tools/mountstats/mountstats.py", line 1119, in main
return args.func(args)
File "tools/mountstats/mountstats.py", line 846, in mountstats_command
stats.parse_stats(descr)
File "tools/mountstats/mountstats.py", line 333, in parse_stats
self.__parse_nfs_line(words)
File "tools/mountstats/mountstats.py", line 263, in __parse_nfs_line

    self.__nfs_data['age'] = int(words[1])

ValueError: invalid literal for int() with base 10: '366;'

That was the original intended purpose for the raw option.

I think it would be better leave display_raw_stats() alone and either add the age (including the call to sec_conv()) to display_stats_header() (in which case it would always appear except for when the --raw option is used), or add it to display_nfs_options() (in which case it would only be shown when mountstats is invoked with no options or with the --nfs option).

-Scott

Quoted 6 lines
tools/mountstats/mountstats.py +0 -0
         print('\tcaps:\t%s' % ','.join(self.__nfs_data['servercapabilities']))
         print('\tsec:\tflavor=%d,pseudoflavor=%d' % (self.__nfs_data['flavor'], \
             self.__nfs_data['pseudoflavor']))
Signature · 1 line
2.25.4