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 ripple {
16
17static void
19 std::string& text,
21 char const* unitName,
23{
24 auto i = seconds.time_since_epoch() / unitVal;
25
26 if (i == 0)
27 return;
28
29 seconds -= unitVal * i;
30
31 if (!text.empty())
32 text += ", ";
33
34 text += std::to_string(i);
35 text += " ";
36 text += unitName;
37
38 if (i > 1)
39 text += "s";
40}
41
43getCountsJson(Application& app, int minObjectCount)
44{
45 auto objectCounts = CountedObjects::getInstance().getCounts(minObjectCount);
46
48
49 for (auto const& [k, v] : objectCounts)
50 {
51 ret[k] = v;
52 }
53
54 if (app.config().useTxTables())
55 {
56 auto const db =
57 dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
58
59 if (!db)
60 Throw<std::runtime_error>("Failed to get relational database");
61
62 auto dbKB = db->getKBUsedAll();
63
64 if (dbKB > 0)
65 ret[jss::dbKBTotal] = dbKB;
66
67 dbKB = db->getKBUsedLedger();
68
69 if (dbKB > 0)
70 ret[jss::dbKBLedger] = dbKB;
71
72 dbKB = db->getKBUsedTransaction();
73
74 if (dbKB > 0)
75 ret[jss::dbKBTransaction] = dbKB;
76
77 {
79 if (c > 0)
80 ret[jss::local_txs] = static_cast<Json::UInt>(c);
81 }
82 }
83
84 ret[jss::write_load] = app.getNodeStore().getWriteLoad();
85
86 ret[jss::historical_perminute] =
87 static_cast<int>(app.getInboundLedgers().fetchRate());
88 ret[jss::SLE_hit_rate] = app.cachedSLEs().rate();
89 ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate();
90 ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size());
91 ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate();
92
93 ret[jss::fullbelow_size] =
94 static_cast<int>(app.getNodeFamily().getFullBelowCache()->size());
95 ret[jss::treenode_cache_size] =
96 app.getNodeFamily().getTreeNodeCache()->getCacheSize();
97 ret[jss::treenode_track_size] =
98 app.getNodeFamily().getTreeNodeCache()->getTrackSize();
99
100 std::string uptime;
101 auto s = UptimeClock::now();
102 using namespace std::chrono_literals;
103 textTime(uptime, s, "year", 365 * 24h);
104 textTime(uptime, s, "day", 24h);
105 textTime(uptime, s, "hour", 1h);
106 textTime(uptime, s, "minute", 1min);
107 textTime(uptime, s, "second", 1s);
108 ret[jss::uptime] = uptime;
109
110 app.getNodeStore().getCountsJson(ret);
111
112 return ret;
113}
114
115// {
116// min_count: <number> // optional, defaults to 10
117// }
120{
121 int minCount = 10;
122
123 if (context.params.isMember(jss::min_count))
124 minCount = context.params[jss::min_count].asUInt();
125
126 return getCountsJson(context.app, minCount);
127}
128
129} // namespace ripple
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 CachedSLEs & cachedSLEs()=0
virtual Config & config()=0
virtual NodeStore::Database & getNodeStore()=0
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
virtual NetworkOPs & getOPs()=0
virtual InboundLedgers & getInboundLedgers()=0
virtual Family & getNodeFamily()=0
virtual LedgerMaster & getLedgerMaster()=0
virtual RelationalDatabase & getRelationalDatabase()=0
bool useTxTables() const
Definition Config.h:323
static CountedObjects & getInstance() noexcept
List getCounts(int minimumThreshold) const
virtual std::shared_ptr< FullBelowCache > getFullBelowCache()=0
Return a pointer to the Family Full Below Cache.
virtual std::shared_ptr< TreeNodeCache > getTreeNodeCache()=0
Return a pointer to the Family Tree Node 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:248
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
Json::Value doGetCounts(RPC::JsonContext &context)
Json::Value getCountsJson(Application &app, int minObjectCount)
Definition GetCounts.cpp:43
static void textTime(std::string &text, UptimeClock::time_point &seconds, char const *unitName, std::chrono::seconds unitVal)
Definition GetCounts.cpp:18
Application & app
Definition Context.h:22
T time_since_epoch(T... args)
T to_string(T... args)