diff options
| author | Dan Engelbrecht <[email protected]> | 2023-04-21 09:22:03 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-04-21 09:22:03 +0200 |
| commit | cda7cb764af09d90c5a1e5fd2a4e55f43e59581a (patch) | |
| tree | 44b29ffd2d15f340d711eadacdc594e1af60492a /zen/cmds/cache.cpp | |
| parent | Merge branch 'main' of https://github.com/EpicGames/zen (diff) | |
| download | archived-zen-cda7cb764af09d90c5a1e5fd2a4e55f43e59581a.tar.xz archived-zen-cda7cb764af09d90c5a1e5fd2a4e55f43e59581a.zip | |
oplog and cache stats (#244)
* basic oplog stats
* add GetValueStats to cache store
* RwLock::ExclusiveLockScope -> RwLock::SharedLockScope
* add rawhash and attachment count to CacheValueStats
* added cache-stats and project-stats commands
* add cast to make Mac overload detection happy
* fix accept type in cache-stats command
* Add options to project-stats command
* use resource paths for stats in project store
* use resource paths for stats in cache
* fix cache-info and project-info url discriminator
* more control over details$ output
* cleanup
* changelog
Diffstat (limited to 'zen/cmds/cache.cpp')
| -rw-r--r-- | zen/cmds/cache.cpp | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/zen/cmds/cache.cpp b/zen/cmds/cache.cpp index b9e10cbf8..495662d2f 100644 --- a/zen/cmds/cache.cpp +++ b/zen/cmds/cache.cpp @@ -131,3 +131,145 @@ CacheInfoCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) return 1; } + +CacheStatsCommand::CacheStatsCommand() +{ + m_Options.add_options()("h,help", "Print help"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value("http://localhost:1337"), "<hosturl>"); +} + +CacheStatsCommand::~CacheStatsCommand() = default; + +int +CacheStatsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions); + + if (!ParseOptions(argc, argv)) + { + return 0; + } + + cpr::Session Session; + Session.SetUrl({fmt::format("{}/stats/z$", m_HostName)}); + Session.SetHeader(cpr::Header{{"Accept", "application/json"}}); + + cpr::Response Result = Session.Get(); + + if (zen::IsHttpSuccessCode(Result.status_code)) + { + ZEN_CONSOLE("{}", Result.text); + + return 0; + } + + if (Result.status_code) + { + ZEN_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text); + } + else + { + ZEN_ERROR("Info failed: {}", Result.error.message); + } + + return 1; +} + +CacheDetailsCommand::CacheDetailsCommand() +{ + m_Options.add_options()("h,help", "Print help"); + m_Options.add_option("", "u", "hosturl", "Host URL", cxxopts::value(m_HostName)->default_value("http://localhost:1337"), "<hosturl>"); + m_Options.add_option("", "c", "csv", "Info on csv format", cxxopts::value(m_CSV), "<csv>"); + m_Options.add_option("", "d", "details", "Get detailed information about records", cxxopts::value(m_Details), "<details>"); + m_Options.add_option("", + "a", + "attachmentdetails", + "Get detailed information about attachments", + cxxopts::value(m_AttachmentDetails), + "<attachmentdetails>"); + m_Options.add_option("", "n", "namespace", "Namespace name to get info for", cxxopts::value(m_Namespace), "<namespace>"); + m_Options.add_option("", "b", "bucket", "Filter on bucket name", cxxopts::value(m_Bucket), "<bucket>"); + m_Options.add_option("", "v", "valuekey", "Filter on value key hash string", cxxopts::value(m_ValueKey), "<valuekey>"); +} + +CacheDetailsCommand::~CacheDetailsCommand() = default; + +int +CacheDetailsCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) +{ + ZEN_UNUSED(GlobalOptions); + + if (!ParseOptions(argc, argv)) + { + return 0; + } + + cpr::Session Session; + cpr::Parameters Parameters; + if (m_Details) + { + Parameters.Add({"details", "true"}); + } + if (m_AttachmentDetails) + { + Parameters.Add({"attachmentdetails", "true"}); + } + if (m_CSV) + { + Parameters.Add({"csv", "true"}); + } + else + { + Session.SetHeader(cpr::Header{{"Accept", "application/json"}}); + } + + if (!m_ValueKey.empty()) + { + if (m_Namespace.empty() || m_Bucket.empty()) + { + ZEN_ERROR("Provide namespace and bucket name"); + ZEN_CONSOLE("{}", m_Options.help({""}).c_str()); + return 1; + } + Session.SetUrl({fmt::format("{}/z$/details$/{}/{}/{}", m_HostName, m_Namespace, m_Bucket, m_ValueKey)}); + } + else if (!m_Bucket.empty()) + { + if (m_Namespace.empty()) + { + ZEN_ERROR("Provide namespace name"); + ZEN_CONSOLE("{}", m_Options.help({""}).c_str()); + return 1; + } + Session.SetUrl({fmt::format("{}/z$/details$/{}/{}", m_HostName, m_Namespace, m_Bucket)}); + } + else if (!m_Namespace.empty()) + { + Session.SetUrl({fmt::format("{}/z$/details$/{}", m_HostName, m_Namespace)}); + } + else + { + Session.SetUrl({fmt::format("{}/z$/details$", m_HostName)}); + } + Session.SetParameters(Parameters); + + cpr::Response Result = Session.Get(); + + if (zen::IsHttpSuccessCode(Result.status_code)) + { + ZEN_CONSOLE("{}", Result.text); + + return 0; + } + + if (Result.status_code) + { + ZEN_ERROR("Info failed: {}: {} ({})", Result.status_code, Result.reason, Result.text); + } + else + { + ZEN_ERROR("Info failed: {}", Result.error.message); + } + + return 1; +} |