22 m_slow_duration(std::chrono::seconds(1))
24 m_log.Say(
"------ Initializing the storage statistics plugin.");
26 m_failure =
"Failed to configure the storage statistics plugin.";
36 m_log.Say(
"Config",
"Stats monitoring has been configured via xrootd.mongstream directive");
38 m_log.Say(
"Config",
"XrdOssStats plugin is loaded but it requires the oss monitoring g-stream to also be enabled to be useful; try adding `xrootd.mongstream oss ...` to your configuration");
42 m_failure =
"XrdOssStats plugin invoked without a configured environment; likely an internal error";
47 auto runmode = envP->
Get(
"oss.runmode");
48 if (runmode && runmode[0]) {
54 if ((rc =
XrdSysThread::Run(&tid, FileSystem::AggregateBootstrap,
static_cast<void *
>(
this), 0,
"FS Stats Compute Thread"))) {
55 m_log.Emsg(
"FileSystem", rc,
"create stats compute thread");
56 m_failure =
"Failed to create the statistics computing thread.";
67 if (m_ready)
return true;
77FileSystem::AggregateBootstrap(
void *me) {
80 std::this_thread::sleep_for(std::chrono::seconds(1));
81 myself->AggregateStats();
94 m_log.Emsg(
"Config", -result,
"parsing config file", configfn);
101 if (!strcmp(val,
"trace")) {
103 if (!(val = statsConf.
GetToken())) {
104 m_log.Emsg(
"Config",
"fsstats.trace requires an argument. Usage: fsstats.trace [all|err|warning|info|debug|none]");
108 if (!strcmp(val,
"all")) {m_log.setMsgMask(m_log.getMsgMask() |
LogMask::All);}
109 else if (!strcmp(val,
"error")) {m_log.setMsgMask(m_log.getMsgMask() |
LogMask::Error);}
113 else if (!strcmp(val,
"none")) {m_log.setMsgMask(0);}
114 }
while ((val = statsConf.
GetToken()));
115 }
else if (!strcmp(val,
"slowop")) {
116 if (!(val = statsConf.
GetToken())) {
117 m_log.Emsg(
"Config",
"fsstats.slowop requires an argument. Usage: fsstats.slowop [duration]");
122 m_log.Emsg(
"Config",
"fsstats.slowop couldn't parse duration", val, errmsg.c_str());
127 m_log.Emsg(
"Config",
"Logging levels enabled",
LogMaskToString(m_log.getMsgMask()).c_str());
135 std::unique_ptr<XrdOssDF> wrapped(
wrapPI.newDir(user));
136 return new Directory(std::move(wrapped), m_log, *
this);
142 std::unique_ptr<XrdOssDF> wrapped(
wrapPI.newFile(user));
143 return new File(std::move(wrapped), m_log, *
this);
148 OpTimer op(m_ops.m_chmod_ops, m_slow_ops.m_chmod_ops, m_times.m_chmod, m_slow_times.m_chmod, m_slow_duration);
149 return wrapPI.Chmod(path, mode, env);
155 OpTimer op(m_ops.m_rename_ops, m_slow_ops.m_rename_ops, m_times.m_rename, m_slow_times.m_rename, m_slow_duration);
156 return wrapPI.Rename(oPath, nPath, oEnvP, nEnvP);
162 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
169 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
170 return wrapPI.StatFS(path, buff, blen, env);
174 char *buff,
int &blen)
176 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
177 return wrapPI.StatLS(env, path, buff, blen);
182 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
188 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
189 return wrapPI.StatPF(path, buff, 0);
194 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
195 return wrapPI.StatVS(vsP, sname, updt);
201 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
202 return wrapPI.StatXA(path, buff, blen, env);
208 OpTimer op(m_ops.m_stat_ops, m_slow_ops.m_stat_ops, m_times.m_stat, m_slow_times.m_stat, m_slow_duration);
209 return wrapPI.StatXP(path, attr, env);
215 OpTimer op(m_ops.m_truncate_ops, m_slow_ops.m_truncate_ops, m_times.m_truncate, m_slow_times.m_truncate, m_slow_duration);
216 return wrapPI.Truncate(path, fsize, env);
221 OpTimer op(m_ops.m_unlink_ops, m_slow_ops.m_unlink_ops, m_times.m_unlink, m_slow_times.m_unlink, m_slow_duration);
222 return wrapPI.Unlink(path, Opts, env);
225void FileSystem::AggregateStats()
228 auto len = snprintf(buf, 1500,
230 "\"event\":\"oss_stats%s\"," \
231 "\"reads\":%" PRIu64
",\"writes\":%" PRIu64
",\"stats\":%" PRIu64
"," \
232 "\"pgreads\":%" PRIu64
",\"pgwrites\":%" PRIu64
",\"readvs\":%" PRIu64
"," \
233 "\"readv_segs\":%" PRIu64
",\"dirlists\":%" PRIu64
",\"dirlist_ents\":%" PRIu64
","
234 "\"truncates\":%" PRIu64
",\"unlinks\":%" PRIu64
",\"chmods\":%" PRIu64
","
235 "\"opens\":%" PRIu64
",\"renames\":%" PRIu64
","
236 "\"slow_reads\":%" PRIu64
",\"slow_writes\":%" PRIu64
",\"slow_stats\":%" PRIu64
","
237 "\"slow_pgreads\":%" PRIu64
",\"slow_pgwrites\":%" PRIu64
",\"slow_readvs\":%" PRIu64
","
238 "\"slow_readv_segs\":%" PRIu64
",\"slow_dirlists\":%" PRIu64
",\"slow_dirlist_ents\":%" PRIu64
","
239 "\"slow_truncates\":%" PRIu64
",\"slow_unlinks\":%" PRIu64
",\"slow_chmods\":%" PRIu64
","
240 "\"slow_opens\":%" PRIu64
",\"slow_renames\":%" PRIu64
","
241 "\"open_t\":%.4f,\"read_t\":%.4f,\"readv_t\":%.4f,"
242 "\"pgread_t\":%.4f,\"write_t\":%.4f,\"pgwrite_t\":%.4f,"
243 "\"dirlist_t\":%.4f,\"stat_t\":%.4f,\"truncate_t\":%.4f,"
244 "\"unlink_t\":%.4f,\"rename_t\":%.4f,\"chmod_t\":%.4f,"
245 "\"slow_open_t\":%.4f,\"slow_read_t\":%.4f,\"slow_readv_t\":%.4f,"
246 "\"slow_pgread_t\":%.4f,\"slow_write_t\":%.4f,\"slow_pgwrite_t\":%.4f,"
247 "\"slow_dirlist_t\":%.4f,\"slow_stat_t\":%.4f,\"slow_truncate_t\":%.4f,"
248 "\"slow_unlink_t\":%.4f,\"slow_rename_t\":%.4f,\"slow_chmod_t\":%.4f"
250 m_runmode.empty() ?
"" : (
"_" + m_runmode).c_str(),
251 static_cast<uint64_t
>(m_ops.m_read_ops),
static_cast<uint64_t
>(m_ops.m_write_ops),
static_cast<uint64_t
>(m_ops.m_stat_ops),
252 static_cast<uint64_t
>(m_ops.m_pgread_ops),
static_cast<uint64_t
>(m_ops.m_pgwrite_ops),
static_cast<uint64_t
>(m_ops.m_readv_ops),
253 static_cast<uint64_t
>(m_ops.m_readv_segs),
static_cast<uint64_t
>(m_ops.m_dirlist_ops),
static_cast<uint64_t
>(m_ops.m_dirlist_entries),
254 static_cast<uint64_t
>(m_ops.m_truncate_ops),
static_cast<uint64_t
>(m_ops.m_unlink_ops),
static_cast<uint64_t
>(m_ops.m_chmod_ops),
255 static_cast<uint64_t
>(m_ops.m_open_ops),
static_cast<uint64_t
>(m_ops.m_rename_ops),
256 static_cast<uint64_t
>(m_slow_ops.m_read_ops),
static_cast<uint64_t
>(m_slow_ops.m_write_ops),
static_cast<uint64_t
>(m_slow_ops.m_stat_ops),
257 static_cast<uint64_t
>(m_slow_ops.m_pgread_ops),
static_cast<uint64_t
>(m_slow_ops.m_pgwrite_ops),
static_cast<uint64_t
>(m_slow_ops.m_readv_ops),
258 static_cast<uint64_t
>(m_slow_ops.m_readv_segs),
static_cast<uint64_t
>(m_slow_ops.m_dirlist_ops),
static_cast<uint64_t
>(m_slow_ops.m_dirlist_entries),
259 static_cast<uint64_t
>(m_slow_ops.m_truncate_ops),
static_cast<uint64_t
>(m_slow_ops.m_unlink_ops),
static_cast<uint64_t
>(m_slow_ops.m_chmod_ops),
260 static_cast<uint64_t
>(m_slow_ops.m_open_ops),
static_cast<uint64_t
>(m_slow_ops.m_rename_ops),
261 static_cast<float>(m_times.m_open)/1e9,
static_cast<float>(m_times.m_read)/1e9,
static_cast<float>(m_times.m_readv)/1e9,
262 static_cast<float>(m_times.m_pgread)/1e9,
static_cast<float>(m_times.m_write)/1e9,
static_cast<float>(m_times.m_pgwrite)/1e9,
263 static_cast<float>(m_times.m_dirlist)/1e9,
static_cast<float>(m_times.m_stat)/1e9,
static_cast<float>(m_times.m_truncate)/1e9,
264 static_cast<float>(m_times.m_unlink)/1e9,
static_cast<float>(m_times.m_rename)/1e9,
static_cast<float>(m_times.m_chmod)/1e9,
265 static_cast<float>(m_slow_times.m_open)/1e9,
static_cast<float>(m_slow_times.m_read)/1e9,
static_cast<float>(m_slow_times.m_readv)/1e9,
266 static_cast<float>(m_slow_times.m_pgread)/1e9,
static_cast<float>(m_slow_times.m_write)/1e9,
static_cast<float>(m_slow_times.m_pgwrite)/1e9,
267 static_cast<float>(m_slow_times.m_dirlist)/1e9,
static_cast<float>(m_slow_times.m_stat)/1e9,
static_cast<float>(m_slow_times.m_truncate)/1e9,
268 static_cast<float>(m_slow_times.m_unlink)/1e9,
static_cast<float>(m_slow_times.m_rename)/1e9,
static_cast<float>(m_slow_times.m_chmod)/1e9
272 m_log.
Log(
LogMask::Error,
"Aggregate",
"Failed to generate g-stream statistics packet");
276 if (m_gstream && !m_gstream->
Insert(buf, len + 1)) {
277 m_log.
Log(
LogMask::Error,
"Aggregate",
"Failed to send g-stream statistics packet");
283 : m_op_count(op_count),
284 m_slow_op_count(slow_op_count),
286 m_slow_timing(slow_timing),
287 m_start(std::chrono::steady_clock::now()),
288 m_slow_duration(duration)
291FileSystem::OpTimer::~OpTimer()
293 auto dur = std::chrono::steady_clock::now() - m_start;
295 m_timing += std::chrono::nanoseconds(dur).count();
296 if (dur > m_slow_duration) {
298 m_slow_timing += std::chrono::nanoseconds(dur).count();
XrdSys::RAtomic< uint64_t > RAtomic_uint64_t
int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *env=0) override
FileSystem(XrdOss *oss, XrdSysLogger *log, const char *configName, XrdOucEnv *envP)
int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0) override
int StatPF(const char *path, struct stat *buff, int opts) override
int Rename(const char *oPath, const char *nPath, XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0) override
XrdOssDF * newDir(const char *user=0) override
int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
XrdOssDF * newFile(const char *user=0) override
int Chmod(const char *path, mode_t mode, XrdOucEnv *env=0) override
int Unlink(const char *path, int Opts=0, XrdOucEnv *env=0) override
bool InitSuccessful(std::string &errMsg)
int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *env=0) override
int Truncate(const char *path, unsigned long long fsize, XrdOucEnv *env=0) override
bool Config(const char *configfn)
int StatXP(const char *path, unsigned long long &attr, XrdOucEnv *env=0) override
int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen) override
XrdOssWrapper(XrdOss &ossRef)
XrdOss()
Constructor and Destructor.
char * Get(const char *varname)
void * GetPtr(const char *varname)
char * GetToken(char **rest=0, int lowcase=0)
int Gather(const char *cfname, Level lvl, const char *parms=0)
@ trim_lines
Prefix trimmed lines.
void Log(int mask, const char *esfx, const char *text1, const char *text2=0, const char *text3=0)
static int Run(pthread_t *, void *(*proc)(void *), void *arg, int opts=0, const char *desc=0)
bool Insert(const char *data, int dlen)
bool ParseDuration(const std::string &duration, std::chrono::steady_clock::duration &result, std::string &errmsg)
std::string LogMaskToString(int mask)