Whamcloud - gitweb
EX-3541 lipe: aggregate LPCC information in lpcc status command
authorLei Feng <flei@whamcloud.com>
Wed, 18 Aug 2021 01:47:54 +0000 (09:47 +0800)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 14 Sep 2021 21:01:36 +0000 (21:01 +0000)
Aggregate LPCC backend information in lpcc status command. Including
the configuration of LPCC, lpcc_purge and stats of lpcc_purge.

Change-Id: I6fd394038b0b9b6279a592bd324b76f90585808e
Signed-off-by: Lei Feng <flei@whamcloud.com>
Test-Parameters: trivial
Reviewed-on: https://review.whamcloud.com/44696
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
lipe/lpcc
lipe/src/lpcc_purge.c

index 5c8bc71..765da83 100755 (executable)
--- a/lipe/lpcc
+++ b/lipe/lpcc
@@ -60,7 +60,7 @@ class LpccService:
             self.lpcc_purge_low_usage = lpcc_purge_obj.get('low_usage', 75)
             self.lpcc_purge_interval = lpcc_purge_obj.get('interval', 30)
             self.lpcc_purge_scan_threads = lpcc_purge_obj.get('scan_threads', 1)
-            self.lpcc_purge_log_level = lpcc_purge_obj.get('log_level');
+            self.lpcc_purge_log_level = lpcc_purge_obj.get('log_level')
 
     @staticmethod
     def _check_process_by_pidfile(procname, pidfile):
@@ -81,7 +81,7 @@ class LpccService:
         """
         Wait for at most secs seconds for the existence of pid in pidfile
         """
-        for i in range(secs):
+        for _ in range(secs):
             if LpccService._check_process_by_pidfile(procname, pidfile):
                 return True
             else:
@@ -120,6 +120,7 @@ class LpccService:
         eprint("Starting lpcc_purge...")
 
         pidfile = '/var/run/lpcc_purge-%d.pid' % self.lpcc_roid
+        statsfile = '/var/run/lpcc_purge-%d.stats' % self.lpcc_roid
         cmdline = [self.lpcc_purge_prog, \
                    '--mount', self.lpcc_mount, \
                    '--cache', self.lpcc_cache, \
@@ -128,7 +129,8 @@ class LpccService:
                    '--low-usage', str(self.lpcc_purge_low_usage), \
                    '--interval', str(self.lpcc_purge_interval), \
                    '--scan-threads', str(self.lpcc_purge_scan_threads), \
-                   '--pidfile', pidfile]
+                   '--pidfile', pidfile, \
+                   '--dump', statsfile]
         if self.lpcc_purge_log_level is not None:
             cmdline.extend(['--log-level', self.lpcc_purge_log_level])
 
@@ -147,6 +149,21 @@ class LpccService:
         pidfile = '/var/run/lpcc_purge-%d.pid' % self.lpcc_roid
         self._kill_process_by_pidfile(self.lpcc_purge_prog, pidfile)
 
+    def _stats_lpcc_purge(self):
+        pidfile = '/var/run/lpcc_purge-%d.pid' % self.lpcc_roid
+        cmdline = ['pkill', '--signal', 'USR1', '--pidfile', pidfile, '--', 'lpcc_purge']
+        subprocess.run(cmdline, check=True)
+
+        statsfile = '/var/run/lpcc_purge-%d.stats' % self.lpcc_roid
+        stats_obj = None
+        try:
+            with open(statsfile) as file_handler:
+                stats_obj = json.load(file_handler)
+        except Exception as err:
+            eprint(err)
+
+        return stats_obj
+
     def _dump_config(self):
         eprint("========== Config ==========")
         yaml.safe_dump(self.lpcc_config, sys.stdout, default_flow_style=False)
@@ -224,6 +241,10 @@ class LpccService:
             result['purge'] = "stopped"
             result['error_msg'] = "lpcc_purge is not running!"
 
+        # if lpcc_purge is running, get its stats
+        if result['purge'] == "running":
+            result['purge_stats'] = self._stats_lpcc_purge()
+
         return result
 
     def is_running(self):
index f8dde31..28f1122 100644 (file)
@@ -111,6 +111,8 @@ struct lpcc_purge_candidate_set {
 };
 static struct lpcc_purge_candidate_set candidate_set;
 
+static double lpcc_purge_get_fs_usage(const char *fs);
+
 struct lpcc_purge_candidate *lpcc_purge_candidate_new(
        uint64_t atime_ms, struct lu_fid fid, const char *path)
 {
@@ -238,11 +240,13 @@ static void lpcc_purge_dump_config_stats(FILE *f)
        int rc;
        char buff[64];
        time_t curr;
+       double usage;
 
        json_object *j_all = json_object_new_object();
 
        curr = time(NULL);
        ctime_r(&curr, buff);
+       buff[strlen(buff) - 1] = '\0';
        json_object *j_curr_time = json_object_new_string(buff);
        json_object_object_add(j_all, "curr_time", j_curr_time);
        rc = llapi_get_fsname(opt.o_mount, buff, sizeof(buff));
@@ -251,6 +255,8 @@ static void lpcc_purge_dump_config_stats(FILE *f)
                exit(1);
        }
        json_object_object_add(j_all, "fsname", json_object_new_string(buff));
+       usage = lpcc_purge_get_fs_usage(opt.o_cache);
+       json_object_object_add(j_all, "cache_usage", json_object_new_double(usage));
 
        json_object *j_config = json_object_new_object();
        json_object_object_add(j_config, "mount", json_object_new_string(opt.o_mount));