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):
"""
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:
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, \
'--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])
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)
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):
};
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)
{
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));
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));