rippled
Loading...
Searching...
No Matches
GetCounts.cpp
1#include <xrpld/app/ledger/AcceptedLedger.h>
2#include <xrpld/app/ledger/InboundLedgers.h>
3#include <xrpld/app/ledger/LedgerMaster.h>
4#include <xrpld/app/main/Application.h>
5#include <xrpld/app/misc/NetworkOPs.h>
6#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
7#include <xrpld/rpc/Context.h>
8
9#include <xrpl/basics/UptimeClock.h>
10#include <xrpl/json/json_value.h>
11#include <xrpl/nodestore/Database.h>
12#include <xrpl/protocol/ErrorCodes.h>
13#include <xrpl/protocol/jss.h>
14
15namespace xrpl {
16
17static void
18textTime(std::string& text, UptimeClock::time_point& seconds, char const* unitName, std::chrono::seconds unitVal)
19{
20 auto i = seconds.time_since_epoch() / unitVal;
21
22 if (i == 0)
23 return;
24
25 seconds -= unitVal * i;
26
27 if (!text.empty())
28 text += ", ";
29
30 text += std::to_string(i);
31 text += " ";
32 text += unitName;
33
34 if (i > 1)
35 text += "s";
36}
37
39getCountsJson(Application& app, int minObjectCount)
40{
41 auto objectCounts = CountedObjects::getInstance().getCounts(minObjectCount);
42
44
45 for (auto const& [k, v] : objectCounts)
46 {
47 ret[k] = v;
48 }
49
50 if (app.config().useTxTables())
51 {
52 auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
53
54 if (!db)
55 Throw<std::runtime_error>("Failed to get relational database");
56
57 auto dbKB = db->getKBUsedAll();
58
59 if (dbKB > 0)
60 ret[jss::dbKBTotal] = dbKB;
61
62 dbKB = db->getKBUsedLedger();
63
64 if (dbKB > 0)
65 ret[jss::dbKBLedger] = dbKB;
66
67 dbKB = db->getKBUsedTransaction();
68
69 if (dbKB > 0)
70 ret[jss::dbKBTransaction] = dbKB;
71
72 {
74 if (c > 0)
75 ret[jss::local_txs] = static_cast<Json::UInt>(c);
76 }
77 }
78
79 ret[jss::write_load] = app.getNodeStore().getWriteLoad();
80
81 ret[jss::historical_perminute] = static_cast<int>(app.getInboundLedgers().fetchRate());
82 ret[jss::SLE_hit_rate] = app.cachedSLEs().rate();
83 ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate();
84 ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size());
85 ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate();
86
87 ret[jss::fullbelow_size] = static_cast<int>(app.getNodeFamily().getFullBelowCache()->size());
88 ret[jss::treenode_cache_size] = app.getNodeFamily().getTreeNodeCache()->getCacheSize();
89 ret[jss::treenode_track_size] = app.getNodeFamily().getTreeNodeCache()->getTrackSize();
90
91 std::string uptime;
92 auto s = UptimeClock::now();
93 using namespace std::chrono_literals;
94 textTime(uptime, s, "year", 365 * 24h);
95 textTime(uptime, s, "day", 24h);
96 textTime(uptime, s, "hour", 1h);
97 textTime(uptime, s, "minute", 1min);
98 textTime(uptime, s, "second", 1s);
99 ret[jss::uptime] = uptime;
100
101 app.getNodeStore().getCountsJson(ret);
102
103 return ret;
104}
105
106// {
107// min_count: <number> // optional, defaults to 10
108// }
111{
112 int minCount = 10;
113
114 if (context.params.isMember(jss::min_count))
115 minCount = context.params[jss::min_count].asUInt();
116
117 return getCountsJson(context.app, minCount);
118}
119
120} // namespace xrpl
Represents a JSON value.
Definition json_value.h:131
UInt asUInt() const
bool isMember(char const *key) const
Return true if the object has a member named key.
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
virtual Config & config()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual NodeStore::Database & getNodeStore()=0
virtual Family & getNodeFamily()=0
virtual CachedSLEs & cachedSLEs()=0
virtual RelationalDatabase & getRelationalDatabase()=0
virtual NetworkOPs & getOPs()=0
bool useTxTables() const
Definition Config.h:318
List getCounts(int minimumThreshold) const
static CountedObjects & getInstance() noexcept
virtual std::shared_ptr< TreeNodeCache > getTreeNodeCache()=0
Return a pointer to the Family Tree Node Cache.
virtual std::shared_ptr< FullBelowCache > getFullBelowCache()=0
Return a pointer to the Family Full Below Cache.
virtual std::size_t fetchRate()=0
Returns the rate of historical ledger fetches per minute.
virtual std::size_t getLocalTxCount()=0
void getCountsJson(Json::Value &obj)
Definition Database.cpp:225
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
double rate() const
Returns the fraction of cache hits.
static time_point now()
T empty(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition json_value.h:27
unsigned int UInt
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
static void textTime(std::string &text, UptimeClock::time_point &seconds, char const *unitName, std::chrono::seconds unitVal)
Definition GetCounts.cpp:18
Json::Value getCountsJson(Application &app, int minObjectCount)
Definition GetCounts.cpp:39
Json::Value doGetCounts(RPC::JsonContext &context)
Application & app
Definition Context.h:22
Json::Value params
Definition Context.h:44
T time_since_epoch(T... args)
T to_string(T... args)