mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-18 13:04:37 +03:00
fix: traffic stats time
This commit is contained in:
@@ -13,6 +13,8 @@ namespace NekoRay::traffic {
|
||||
long long downlink_rate = 0;
|
||||
long long uplink_rate = 0;
|
||||
|
||||
long long last_update;
|
||||
|
||||
explicit TrafficData(std::string tag) {
|
||||
this->tag = std::move(tag);
|
||||
_add(new configItem("dl", &downlink, itemType::integer64));
|
||||
|
||||
@@ -8,11 +8,17 @@
|
||||
namespace NekoRay::traffic {
|
||||
|
||||
TrafficLooper *trafficLooper = new TrafficLooper;
|
||||
QElapsedTimer trafficLooper_timer;
|
||||
|
||||
std::unique_ptr<TrafficData> TrafficLooper::update_stats(TrafficData *item) {
|
||||
#ifndef NKR_NO_GRPC
|
||||
auto interval = dataStore->traffic_loop_interval;
|
||||
if (interval == 0) return nullptr;
|
||||
// last update
|
||||
auto now = trafficLooper_timer.elapsed();
|
||||
auto interval = now - item->last_update;
|
||||
item->last_update = now;
|
||||
if (interval <= 0) return nullptr;
|
||||
|
||||
// query
|
||||
auto uplink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "uplink");
|
||||
auto downlink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "downlink");
|
||||
|
||||
@@ -63,6 +69,7 @@ namespace NekoRay::traffic {
|
||||
}
|
||||
|
||||
void TrafficLooper::loop() {
|
||||
trafficLooper_timer.start();
|
||||
while (true) {
|
||||
auto sleep_ms = dataStore->traffic_loop_interval;
|
||||
auto user_disabled = sleep_ms == 0;
|
||||
|
||||
Reference in New Issue
Block a user