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/rdb/backend/SQLiteDatabase.h>
6#include <xrpld/rpc/Context.h>
7
8#include <xrpl/basics/UptimeClock.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/nodestore/Database.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/jss.h>
13#include <xrpl/server/NetworkOPs.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& db = app.getRelationalDatabase();
53
54 auto dbKB = db.getKBUsedAll();
55
56 if (dbKB > 0)
57 ret[jss::dbKBTotal] = dbKB;
58
59 dbKB = db.getKBUsedLedger();
60
61 if (dbKB > 0)
62 ret[jss::dbKBLedger] = dbKB;
63
64 dbKB = db.getKBUsedTransaction();
65
66 if (dbKB > 0)
67 ret[jss::dbKBTransaction] = dbKB;
68
69 {
71 if (c > 0)
72 ret[jss::local_txs] = static_cast<Json::UInt>(c);
73 }
74 }
75
76 ret[jss::write_load] = app.getNodeStore().getWriteLoad();
77
78 ret[jss::historical_perminute] = static_cast<int>(app.getInboundLedgers().fetchRate());
79 ret[jss::SLE_hit_rate] = app.cachedSLEs().rate();
80 ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate();
81 ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size());
82 ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate();
83
84 ret[jss::fullbelow_size] = static_cast<int>(app.getNodeFamily().getFullBelowCache()->size());
85 ret[jss::treenode_cache_size] = app.getNodeFamily().getTreeNodeCache()->getCacheSize();
86 ret[jss::treenode_track_size] = app.getNodeFamily().getTreeNodeCache()->getTrackSize();
87
88 std::string uptime;
89 auto s = UptimeClock::now();
90 using namespace std::chrono_literals;
91 textTime(uptime, s, "year", 365 * 24h);
92 textTime(uptime, s, "day", 24h);
93 textTime(uptime, s, "hour", 1h);
94 textTime(uptime, s, "minute", 1min);
95 textTime(uptime, s, "second", 1s);
96 ret[jss::uptime] = uptime;
97
98 app.getNodeStore().getCountsJson(ret);
99
100 return ret;
101}
102
103// {
104// min_count: <number> // optional, defaults to 10
105// }
108{
109 int minCount = 10;
110
111 if (context.params.isMember(jss::min_count))
112 minCount = context.params[jss::min_count].asUInt();
113
114 return getCountsJson(context.app, minCount);
115}
116
117} // 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: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.
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 CachedSLEs & cachedSLEs()=0
virtual TaggedCache< uint256, AcceptedLedger > & getAcceptedLedgerCache()=0
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:26
unsigned int UInt
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:18
Json::Value getCountsJson(Application &app, int minObjectCount)
Definition GetCounts.cpp:39
Json::Value doGetCounts(RPC::JsonContext &context)
Application & app
Definition Context.h:21
Json::Value params
Definition Context.h:43
T time_since_epoch(T... args)
T to_string(T... args)