xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
xrpld
rpc
handlers
admin
status
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
18
namespace
xrpl
{
19
20
static
void
21
textTime
(
22
std::string
& text,
23
UptimeClock::time_point
& seconds,
24
char
const
* unitName,
25
std::chrono::seconds
unitVal)
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
45
json::Value
46
getCountsJson
(
Application
& app,
int
minObjectCount)
47
{
48
auto
objectCounts =
CountedObjects::getInstance
().
getCounts
(minObjectCount);
49
50
json::Value
ret(
json::ValueType::Object
);
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
// }
113
json::Value
114
doGetCounts
(
rpc::JsonContext
& context)
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
std::string
chrono
json::Value
Represents a JSON value.
Definition
json_value.h:117
json::Value::asUInt
UInt asUInt() const
Definition
json_value.cpp:631
json::Value::isMember
bool isMember(char const *key) const
Return true if the object has a member named key.
Definition
json_value.cpp:1049
xrpl::Application
Definition
Application.h:94
xrpl::Application::config
virtual Config & config()=0
xrpl::Config::useTxTables
bool useTxTables() const
Definition
src/xrpld/core/Config.h:366
xrpl::CountedObjects::getCounts
List getCounts(int minimumThreshold) const
Definition
CountedObject.cpp:20
xrpl::CountedObjects::getInstance
static CountedObjects & getInstance() noexcept
Definition
CountedObject.cpp:8
xrpl::Family::getTreeNodeCache
virtual std::shared_ptr< TreeNodeCache > getTreeNodeCache()=0
Return a pointer to the Family Tree Node Cache.
xrpl::LedgerMaster::getCacheHitRate
float getCacheHitRate()
Definition
LedgerMaster.cpp:1825
xrpl::NetworkOPs::getLocalTxCount
virtual std::size_t getLocalTxCount()=0
xrpl::RelationalDatabase::getKBUsedAll
virtual uint32_t getKBUsedAll()=0
getKBUsedAll Returns the amount of space used by all databases.
xrpl::ServiceRegistry::getRelationalDatabase
virtual RelationalDatabase & getRelationalDatabase()=0
xrpl::ServiceRegistry::getOPs
virtual NetworkOPs & getOPs()=0
xrpl::ServiceRegistry::getNodeStore
virtual node_store::Database & getNodeStore()=0
xrpl::ServiceRegistry::getAcceptedLedgerCache
virtual TaggedCache< UInt256, AcceptedLedger > & getAcceptedLedgerCache()=0
xrpl::ServiceRegistry::getInboundLedgers
virtual InboundLedgers & getInboundLedgers()=0
xrpl::ServiceRegistry::getLedgerMaster
virtual LedgerMaster & getLedgerMaster()=0
xrpl::ServiceRegistry::getNodeFamily
virtual Family & getNodeFamily()=0
xrpl::ServiceRegistry::getCachedSLEs
virtual CachedSLEs & getCachedSLEs()=0
xrpl::TaggedCache::rate
double rate() const
Returns the fraction of cache hits.
xrpl::UptimeClock::time_point
std::chrono::time_point< UptimeClock > time_point
Definition
UptimeClock.h:24
xrpl::UptimeClock::now
static time_point now()
Definition
UptimeClock.cpp:49
xrpl::node_store::Database::getWriteLoad
virtual std::int32_t getWriteLoad() const =0
Retrieve the estimated number of pending write operations.
xrpl::node_store::Database::getCountsJson
void getCountsJson(json::Value &obj)
Definition
libxrpl/nodestore/Database.cpp:258
cstddef
std::chrono::seconds
std::string::empty
T empty(T... args)
json::UInt
unsigned int UInt
Definition
json_forwards.h:7
json::ValueType::Object
@ Object
object value (collection of name/value pairs).
Definition
json_value.h:29
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::textTime
static void textTime(std::string &text, UptimeClock::time_point &seconds, char const *unitName, std::chrono::seconds unitVal)
Definition
GetCounts.cpp:21
xrpl::doGetCounts
json::Value doGetCounts(rpc::JsonContext &context)
Definition
GetCounts.cpp:114
xrpl::getCountsJson
json::Value getCountsJson(Application &app, int minObjectCount)
Definition
GetCounts.cpp:46
std::size_t
string
xrpl::rpc::Context::app
Application & app
Definition
Context.h:29
xrpl::rpc::JsonContext
Definition
Context.h:41
xrpl::rpc::JsonContext::params
json::Value params
Definition
Context.h:51
std::chrono::time_point::time_since_epoch
T time_since_epoch(T... args)
std::to_string
T to_string(T... args)
Generated by
1.17.0