mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 18:45:55 +00:00
improved stats
This commit is contained in:
@@ -33,7 +33,7 @@ constexpr uint32_t WARNING_AMENDMENT_WARNED = 1 << 2;
|
|||||||
constexpr uint32_t WARNING_NOT_SYNCED = 1 << 3;
|
constexpr uint32_t WARNING_NOT_SYNCED = 1 << 3;
|
||||||
|
|
||||||
// Time window statistics for rates
|
// Time window statistics for rates
|
||||||
struct RateStats
|
struct MetricRates
|
||||||
{
|
{
|
||||||
double rate_1m; // Average rate over last minute
|
double rate_1m; // Average rate over last minute
|
||||||
double rate_5m; // Average rate over last 5 minutes
|
double rate_5m; // Average rate over last 5 minutes
|
||||||
@@ -41,6 +41,14 @@ struct RateStats
|
|||||||
double rate_24h; // Average rate over last 24 hours
|
double rate_24h; // Average rate over last 24 hours
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AllRates
|
||||||
|
{
|
||||||
|
MetricRates network_in;
|
||||||
|
MetricRates network_out;
|
||||||
|
MetricRates disk_read;
|
||||||
|
MetricRates disk_write;
|
||||||
|
};
|
||||||
|
|
||||||
// Structure to represent a ledger sequence range
|
// Structure to represent a ledger sequence range
|
||||||
struct LgrRange
|
struct LgrRange
|
||||||
{
|
{
|
||||||
@@ -92,10 +100,10 @@ struct ServerInfoHeader {
|
|||||||
|
|
||||||
// Network and disk rates
|
// Network and disk rates
|
||||||
struct {
|
struct {
|
||||||
RateStats network_in;
|
MetricRates network_in;
|
||||||
RateStats network_out;
|
MetricRates network_out;
|
||||||
RateStats disk_read;
|
MetricRates disk_read;
|
||||||
RateStats disk_write;
|
MetricRates disk_write;
|
||||||
} rates;
|
} rates;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -124,40 +132,45 @@ private:
|
|||||||
|
|
||||||
size_t index_1m{0}, index_5m{0}, index_1h{0}, index_24h{0};
|
size_t index_1m{0}, index_5m{0}, index_1h{0}, index_24h{0};
|
||||||
std::chrono::system_clock::time_point last_24h_sample{};
|
std::chrono::system_clock::time_point last_24h_sample{};
|
||||||
RateStats
|
|
||||||
calculateRates(
|
double
|
||||||
|
calculateRate(
|
||||||
const SystemMetrics& current,
|
const SystemMetrics& current,
|
||||||
const std::vector<SystemMetrics>& samples,
|
const std::vector<SystemMetrics>& samples,
|
||||||
size_t window_size,
|
size_t window_size,
|
||||||
double time_period_seconds)
|
double time_period_seconds,
|
||||||
|
std::function<uint64_t(const SystemMetrics&)> metric_getter)
|
||||||
{
|
{
|
||||||
RateStats stats{0.0, 0.0, 0.0, 0.0};
|
|
||||||
if (window_size == 0)
|
if (window_size == 0)
|
||||||
return stats;
|
return 0.0;
|
||||||
|
|
||||||
auto oldest = samples[window_size - 1];
|
auto oldest = samples[window_size - 1];
|
||||||
double elapsed = (current.timestamp - oldest.timestamp) /
|
double elapsed = (current.timestamp - oldest.timestamp) / 1000000.0; // Convert microseconds to seconds
|
||||||
1000000.0; // Convert microseconds to seconds
|
|
||||||
if (elapsed <= 0)
|
if (elapsed <= 0)
|
||||||
return stats;
|
return 0.0;
|
||||||
|
|
||||||
uint64_t net_in_diff =
|
uint64_t current_value = metric_getter(current);
|
||||||
current.network_bytes_in - oldest.network_bytes_in;
|
uint64_t oldest_value = metric_getter(oldest);
|
||||||
uint64_t net_out_diff =
|
uint64_t diff = current_value - oldest_value;
|
||||||
current.network_bytes_out - oldest.network_bytes_out;
|
|
||||||
uint64_t disk_read_diff =
|
|
||||||
current.disk_bytes_read - oldest.disk_bytes_read;
|
|
||||||
uint64_t disk_write_diff =
|
|
||||||
current.disk_bytes_written - oldest.disk_bytes_written;
|
|
||||||
|
|
||||||
return {
|
return static_cast<double>(diff) / elapsed;
|
||||||
static_cast<double>(net_in_diff) / elapsed,
|
}
|
||||||
static_cast<double>(net_out_diff) / elapsed,
|
|
||||||
static_cast<double>(disk_read_diff) / elapsed,
|
MetricRates
|
||||||
static_cast<double>(disk_write_diff) / elapsed};
|
calculateMetricRates(
|
||||||
|
const SystemMetrics& current,
|
||||||
|
std::function<uint64_t(const SystemMetrics&)> metric_getter)
|
||||||
|
{
|
||||||
|
MetricRates rates;
|
||||||
|
rates.rate_1m = calculateRate(current, samples_1m, std::min(index_1m, SAMPLES_1M), 60, metric_getter);
|
||||||
|
rates.rate_5m = calculateRate(current, samples_5m, std::min(index_5m, SAMPLES_5M), 300, metric_getter);
|
||||||
|
rates.rate_1h = calculateRate(current, samples_1h, std::min(index_1h, SAMPLES_1H), 3600, metric_getter);
|
||||||
|
rates.rate_24h = calculateRate(current, samples_24h, std::min(index_24h, SAMPLES_24H), 86400, metric_getter);
|
||||||
|
return rates;
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void
|
void
|
||||||
addSample(const SystemMetrics& metrics)
|
addSample(const SystemMetrics& metrics)
|
||||||
{
|
{
|
||||||
@@ -180,18 +193,19 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<RateStats, RateStats, RateStats, RateStats>
|
AllRates
|
||||||
getRates(const SystemMetrics& current)
|
getRates(const SystemMetrics& current)
|
||||||
{
|
{
|
||||||
return {
|
AllRates rates;
|
||||||
calculateRates(
|
rates.network_in = calculateMetricRates(current,
|
||||||
current, samples_1m, std::min(index_1m, SAMPLES_1M), 60),
|
[](const SystemMetrics& m) { return m.network_bytes_in; });
|
||||||
calculateRates(
|
rates.network_out = calculateMetricRates(current,
|
||||||
current, samples_5m, std::min(index_5m, SAMPLES_5M), 300),
|
[](const SystemMetrics& m) { return m.network_bytes_out; });
|
||||||
calculateRates(
|
rates.disk_read = calculateMetricRates(current,
|
||||||
current, samples_1h, std::min(index_1h, SAMPLES_1H), 3600),
|
[](const SystemMetrics& m) { return m.disk_bytes_read; });
|
||||||
calculateRates(
|
rates.disk_write = calculateMetricRates(current,
|
||||||
current, samples_24h, std::min(index_24h, SAMPLES_24H), 86400)};
|
[](const SystemMetrics& m) { return m.disk_bytes_written; });
|
||||||
|
return rates;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -475,12 +489,11 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get rate statistics
|
// Get rate statistics
|
||||||
auto [rates_1m, rates_5m, rates_1h, rates_24h] =
|
auto rates = metrics_tracker_.getRates(currentMetrics);
|
||||||
metrics_tracker_.getRates(currentMetrics);
|
header->rates.network_in = rates.network_in;
|
||||||
header->rates.network_in = rates_1m;
|
header->rates.network_out = rates.network_out;
|
||||||
header->rates.network_out = rates_5m;
|
header->rates.disk_read = rates.disk_read;
|
||||||
header->rates.disk_read = rates_1h;
|
header->rates.disk_write = rates.disk_write;
|
||||||
header->rates.disk_write = rates_24h;
|
|
||||||
|
|
||||||
// Pack ledger info and ranges
|
// Pack ledger info and ranges
|
||||||
auto lpClosed = ledgerMaster.getValidatedLedger();
|
auto lpClosed = ledgerMaster.getValidatedLedger();
|
||||||
|
|||||||
Reference in New Issue
Block a user