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";
48 if ((rc =
XrdSysThread::Run(&tid, FileSystem::AggregateBootstrap,
static_cast<void *
>(
this), 0,
"FS Stats Compute Thread"))) {
49 m_log.
Emsg(
"FileSystem", rc,
"create stats compute thread");
50 m_failure =
"Failed to create the statistics computing thread.";
61 if (m_ready)
return true;
71 FileSystem::AggregateBootstrap(
void *me) {
74 std::this_thread::sleep_for(std::chrono::seconds(1));
75 myself->AggregateStats();
88 m_log.
Emsg(
"Config", -result,
"parsing config file", configfn);
95 if (!strcmp(val,
"trace")) {
98 m_log.
Emsg(
"Config",
"fsstats.trace requires an argument. Usage: fsstats.trace [all|err|warning|info|debug|none]");
107 else if (!strcmp(val,
"none")) {m_log.
setMsgMask(0);}
108 }
while ((val = statsConf.
GetToken()));
109 }
else if (!strcmp(val,
"slowop")) {
110 if (!(val = statsConf.
GetToken())) {
111 m_log.
Emsg(
"Config",
"fsstats.slowop requires an argument. Usage: fsstats.slowop [duration]");
116 m_log.
Emsg(
"Config",
"fsstats.slowop couldn't parse duration", val, errmsg.c_str());
130 return new Directory(std::move(wrapped), m_log, *
this);
137 return new File(std::move(wrapped), m_log, *
this);
142 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 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 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);
163 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);
168 char *buff,
int &blen)
170 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);
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);
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);
195 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 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 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);
215 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);
219 void FileSystem::AggregateStats()
222 auto len = snprintf(buf, 1500,
224 "\"event\":\"oss_stats\"," \
225 "\"reads\":%" PRIu64
",\"writes\":%" PRIu64
",\"stats\":%" PRIu64
"," \
226 "\"pgreads\":%" PRIu64
",\"pgwrites\":%" PRIu64
",\"readvs\":%" PRIu64
"," \
227 "\"readv_segs\":%" PRIu64
",\"dirlists\":%" PRIu64
",\"dirlist_ents\":%" PRIu64
","
228 "\"truncates\":%" PRIu64
",\"unlinks\":%" PRIu64
",\"chmods\":%" PRIu64
","
229 "\"opens\":%" PRIu64
",\"renames\":%" PRIu64
","
230 "\"slow_reads\":%" PRIu64
",\"slow_writes\":%" PRIu64
",\"slow_stats\":%" PRIu64
","
231 "\"slow_pgreads\":%" PRIu64
",\"slow_pgwrites\":%" PRIu64
",\"slow_readvs\":%" PRIu64
","
232 "\"slow_readv_segs\":%" PRIu64
",\"slow_dirlists\":%" PRIu64
",\"slow_dirlist_ents\":%" PRIu64
","
233 "\"slow_truncates\":%" PRIu64
",\"slow_unlinks\":%" PRIu64
",\"slow_chmods\":%" PRIu64
","
234 "\"slow_opens\":%" PRIu64
",\"slow_renames\":%" PRIu64
","
235 "\"open_t\":%.4f,\"read_t\":%.4f,\"readv_t\":%.4f,"
236 "\"pgread_t\":%.4f,\"write_t\":%.4f,\"pgwrite_t\":%.4f,"
237 "\"dirlist_t\":%.4f,\"stat_t\":%.4f,\"truncate_t\":%.4f,"
238 "\"unlink_t\":%.4f,\"rename_t\":%.4f,\"chmod_t\":%.4f,"
239 "\"slow_open_t\":%.4f,\"slow_read_t\":%.4f,\"slow_readv_t\":%.4f,"
240 "\"slow_pgread_t\":%.4f,\"slow_write_t\":%.4f,\"slow_pgwrite_t\":%.4f,"
241 "\"slow_dirlist_t\":%.4f,\"slow_stat_t\":%.4f,\"slow_truncate_t\":%.4f,"
242 "\"slow_unlink_t\":%.4f,\"slow_rename_t\":%.4f,\"slow_chmod_t\":%.4f"
244 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),
245 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),
246 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),
247 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),
248 static_cast<uint64_t
>(m_ops.m_open_ops),
static_cast<uint64_t
>(m_ops.m_rename_ops),
249 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),
250 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),
251 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),
252 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),
253 static_cast<uint64_t
>(m_slow_ops.m_open_ops),
static_cast<uint64_t
>(m_slow_ops.m_rename_ops),
254 static_cast<float>(m_times.m_open)/1e9,
static_cast<float>(m_times.m_read)/1e9,
static_cast<float>(m_times.m_readv)/1e9,
255 static_cast<float>(m_times.m_pgread)/1e9,
static_cast<float>(m_times.m_write)/1e9,
static_cast<float>(m_times.m_pgwrite)/1e9,
256 static_cast<float>(m_times.m_dirlist)/1e9,
static_cast<float>(m_times.m_stat)/1e9,
static_cast<float>(m_times.m_truncate)/1e9,
257 static_cast<float>(m_times.m_unlink)/1e9,
static_cast<float>(m_times.m_rename)/1e9,
static_cast<float>(m_times.m_chmod)/1e9,
258 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,
259 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,
260 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,
261 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
265 m_log.
Log(
LogMask::Error,
"Aggregate",
"Failed to generate g-stream statistics packet");
269 if (m_gstream && !m_gstream->
Insert(buf, len + 1)) {
270 m_log.
Log(
LogMask::Error,
"Aggregate",
"Failed to send g-stream statistics packet");
276 : m_op_count(op_count),
277 m_slow_op_count(slow_op_count),
279 m_slow_timing(slow_timing),
280 m_start(std::chrono::steady_clock::now()),
281 m_slow_duration(duration)
284 FileSystem::OpTimer::~OpTimer()
286 auto dur = std::chrono::steady_clock::now() - m_start;
288 m_timing += std::chrono::nanoseconds(dur).count();
289 if (dur > m_slow_duration) {
291 m_slow_timing += std::chrono::nanoseconds(dur).count();
int stat(const char *path, struct stat *buf)
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
virtual int StatLS(XrdOucEnv &env, const char *path, char *buff, int &blen)
virtual int StatXA(const char *path, char *buff, int &blen, XrdOucEnv *envP=0)
virtual int StatXP(const char *path, unsigned long long &attr, XrdOucEnv *envP=0)
virtual XrdOssDF * newDir(const char *tident)=0
virtual int Chmod(const char *path, mode_t mode, XrdOucEnv *envP=0)=0
virtual int StatPF(const char *path, struct stat *buff, int opts)
virtual int StatVS(XrdOssVSInfo *vsP, const char *sname=0, int updt=0)
virtual int StatFS(const char *path, char *buff, int &blen, XrdOucEnv *envP=0)
virtual int Rename(const char *oPath, const char *nPath, XrdOucEnv *oEnvP=0, XrdOucEnv *nEnvP=0)=0
virtual XrdOssDF * newFile(const char *tident)=0
virtual int Truncate(const char *path, unsigned long long fsize, XrdOucEnv *envP=0)=0
virtual int Stat(const char *path, struct stat *buff, int opts=0, XrdOucEnv *envP=0)=0
virtual int Unlink(const char *path, int Opts=0, XrdOucEnv *envP=0)=0
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.
int Emsg(const char *esfx, int ecode, const char *text1, const char *text2=0)
void Say(const char *text1, const char *text2=0, const char *txt3=0, const char *text4=0, const char *text5=0, const char *txt6=0)
void setMsgMask(int mask)
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)