rippled
Loading...
Searching...
No Matches
GetCounts.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/ledger/AcceptedLedger.h>
21#include <xrpld/app/ledger/InboundLedgers.h>
22#include <xrpld/app/ledger/LedgerMaster.h>
23#include <xrpld/app/main/Application.h>
24#include <xrpld/app/misc/NetworkOPs.h>
25#include <xrpld/app/rdb/backend/SQLiteDatabase.h>
26#include <xrpld/nodestore/Database.h>
27#include <xrpld/rpc/Context.h>
28#include <xrpl/basics/UptimeClock.h>
29#include <xrpl/json/json_value.h>
30#include <xrpl/protocol/ErrorCodes.h>
31#include <xrpl/protocol/jss.h>
32
33namespace ripple {
34
35static void
37 std::string& text,
39 const char* unitName,
41{
42 auto i = seconds.time_since_epoch() / unitVal;
43
44 if (i == 0)
45 return;
46
47 seconds -= unitVal * i;
48
49 if (!text.empty())
50 text += ", ";
51
52 text += std::to_string(i);
53 text += " ";
54 text += unitName;
55
56 if (i > 1)
57 text += "s";
58}
59
61getCountsJson(Application& app, int minObjectCount)
62{
63 auto objectCounts = CountedObjects::getInstance().getCounts(minObjectCount);
64
66
67 for (auto const& [k, v] : objectCounts)
68 {
69 ret[k] = v;
70 }
71
72 if (app.config().useTxTables())
73 {
74 auto const db =
75 dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
76
77 if (!db)
78 Throw<std::runtime_error>("Failed to get relational database");
79
80 auto dbKB = db->getKBUsedAll();
81
82 if (dbKB > 0)
83 ret[jss::dbKBTotal] = dbKB;
84
85 dbKB = db->getKBUsedLedger();
86
87 if (dbKB > 0)
88 ret[jss::dbKBLedger] = dbKB;
89
90 dbKB = db->getKBUsedTransaction();
91
92 if (dbKB > 0)
93 ret[jss::dbKBTransaction] = dbKB;
94
95 {
97 if (c > 0)
98 ret[jss::local_txs] = static_cast<Json::UInt>(c);
99 }
100 }
101
102 ret[jss::write_load] = app.getNodeStore().getWriteLoad();
103
104 ret[jss::historical_perminute] =
105 static_cast<int>(app.getInboundLedgers().fetchRate());
106 ret[jss::SLE_hit_rate] = app.cachedSLEs().rate();
107 ret[jss::ledger_hit_rate] = app.getLedgerMaster().getCacheHitRate();
108 ret[jss::AL_size] = Json::UInt(app.getAcceptedLedgerCache().size());
109 ret[jss::AL_hit_rate] = app.getAcceptedLedgerCache().getHitRate();
110
111 ret[jss::fullbelow_size] =
112 static_cast<int>(app.getNodeFamily().getFullBelowCache()->size());
113 ret[jss::treenode_cache_size] =
114 app.getNodeFamily().getTreeNodeCache()->getCacheSize();
115 ret[jss::treenode_track_size] =
116 app.getNodeFamily().getTreeNodeCache()->getTrackSize();
117
118 std::string uptime;
119 auto s = UptimeClock::now();
120 using namespace std::chrono_literals;
121 textTime(uptime, s, "year", 365 * 24h);
122 textTime(uptime, s, "day", 24h);
123 textTime(uptime, s, "hour", 1h);
124 textTime(uptime, s, "minute", 1min);
125 textTime(uptime, s, "second", 1s);
126 ret[jss::uptime] = uptime;
127
128 app.getNodeStore().getCountsJson(ret);
129
130 return ret;
131}
132
133// {
134// min_count: <number> // optional, defaults to 10
135// }
138{
139 int minCount = 10;
140
141 if (context.params.isMember(jss::min_count))
142 minCount = context.params[jss::min_count].asUInt();
143
144 return getCountsJson(context.app, minCount);
145}
146
147} // namespace ripple
Represents a JSON value.
Definition: json_value.h:148
UInt asUInt() const
Definition: json_value.cpp:551
bool isMember(const char *key) const
Return true if the object has a member named key.
Definition: json_value.cpp:949
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:343
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:267
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
double rate() const
Returns the fraction of cache hits.
Definition: TaggedCache.h:476
static time_point now()
Definition: UptimeClock.cpp:67
T empty(T... args)
@ objectValue
object value (collection of name/value pairs).
Definition: json_value.h:44
unsigned int UInt
Definition: json_forwards.h:27
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
static void textTime(std::string &text, UptimeClock::time_point &seconds, const char *unitName, std::chrono::seconds unitVal)
Definition: GetCounts.cpp:36
Json::Value doGetCounts(RPC::JsonContext &context)
Definition: GetCounts.cpp:137
Json::Value getCountsJson(Application &app, int minObjectCount)
Definition: GetCounts.cpp:61
Application & app
Definition: Context.h:40
Json::Value params
Definition: Context.h:62
T time_since_epoch(T... args)
T to_string(T... args)