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