mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Tidy up LoadMonitor stats API
This commit is contained in:
@@ -278,14 +278,11 @@ public:
|
||||
if (type == jtGENERIC)
|
||||
continue;
|
||||
|
||||
uint64 count;
|
||||
uint64 latencyAvg;
|
||||
uint64 latencyPeak;
|
||||
LoadMonitor::Stats stats;
|
||||
int jobCount;
|
||||
int threadCount;
|
||||
bool isOver;
|
||||
|
||||
m_loads [i].getCountAndLatency (count, latencyAvg, latencyPeak, isOver);
|
||||
m_loads [i].getStats ();
|
||||
|
||||
MapType::const_iterator it = m_jobCounts.find (type);
|
||||
|
||||
@@ -300,11 +297,12 @@ public:
|
||||
threadCount = it->second.running;
|
||||
}
|
||||
|
||||
if ((count != 0) || (jobCount != 0) || (latencyPeak != 0) || (threadCount != 0))
|
||||
if ((stats.count != 0) || (jobCount != 0) ||
|
||||
(stats.latencyPeak != 0) || (threadCount != 0))
|
||||
{
|
||||
Json::Value pri (Json::objectValue);
|
||||
|
||||
if (isOver)
|
||||
if (stats.isOverloaded)
|
||||
pri["over_target"] = true;
|
||||
|
||||
pri["job_type"] = Job::toString (type);
|
||||
@@ -312,14 +310,14 @@ public:
|
||||
if (jobCount != 0)
|
||||
pri["waiting"] = jobCount;
|
||||
|
||||
if (count != 0)
|
||||
pri["per_second"] = static_cast<int> (count);
|
||||
if (stats.count != 0)
|
||||
pri["per_second"] = static_cast<int> (stats.count);
|
||||
|
||||
if (latencyPeak != 0)
|
||||
pri["peak_time"] = static_cast<int> (latencyPeak);
|
||||
if (stats.latencyPeak != 0)
|
||||
pri["peak_time"] = static_cast<int> (stats.latencyPeak);
|
||||
|
||||
if (latencyAvg != 0)
|
||||
pri["avg_time"] = static_cast<int> (latencyAvg);
|
||||
if (stats.latencyAvg != 0)
|
||||
pri["avg_time"] = static_cast<int> (stats.latencyAvg);
|
||||
|
||||
if (threadCount != 0)
|
||||
pri["in_progress"] = threadCount;
|
||||
|
||||
@@ -17,6 +17,26 @@
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
/*
|
||||
|
||||
TODO
|
||||
----
|
||||
|
||||
- Use Journal for logging
|
||||
|
||||
*/
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
LoadMonitor::Stats::Stats()
|
||||
: count (0)
|
||||
, latencyAvg (0)
|
||||
, latencyPeak (0)
|
||||
, isOverloaded (false)
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
SETUP_LOG (LoadMonitor)
|
||||
|
||||
@@ -171,26 +191,28 @@ bool LoadMonitor::isOver ()
|
||||
return isOverTarget (mLatencyMSAvg / (mLatencyEvents * 4), mLatencyMSPeak / (mLatencyEvents * 4));
|
||||
}
|
||||
|
||||
void LoadMonitor::getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver)
|
||||
LoadMonitor::Stats LoadMonitor::getStats ()
|
||||
{
|
||||
Stats stats;
|
||||
|
||||
ScopedLockType sl (mLock, __FILE__, __LINE__);
|
||||
|
||||
update ();
|
||||
|
||||
count = mCounts / 4;
|
||||
stats.count = mCounts / 4;
|
||||
|
||||
if (mLatencyEvents == 0)
|
||||
{
|
||||
latencyAvg = 0;
|
||||
latencyPeak = 0;
|
||||
stats.latencyAvg = 0;
|
||||
stats.latencyPeak = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4);
|
||||
latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4);
|
||||
stats.latencyAvg = mLatencyMSAvg / (mLatencyEvents * 4);
|
||||
stats.latencyPeak = mLatencyMSPeak / (mLatencyEvents * 4);
|
||||
}
|
||||
|
||||
isOver = isOverTarget (latencyAvg, latencyPeak);
|
||||
}
|
||||
stats.isOverloaded = isOverTarget (stats.latencyAvg, stats.latencyPeak);
|
||||
|
||||
// vim:ts=4
|
||||
return stats;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,17 @@ public:
|
||||
bool isOverTarget (uint64 avg, uint64 peak);
|
||||
|
||||
// VFALCO TODO make this return the values in a struct.
|
||||
void getCountAndLatency (uint64& count, uint64& latencyAvg, uint64& latencyPeak, bool& isOver);
|
||||
struct Stats
|
||||
{
|
||||
Stats();
|
||||
|
||||
uint64 count;
|
||||
uint64 latencyAvg;
|
||||
uint64 latencyPeak;
|
||||
bool isOverloaded;
|
||||
};
|
||||
|
||||
Stats getStats ();
|
||||
|
||||
bool isOver ();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user