8000 Add: completion and downloaded volumes statistics by dnzbk · Pull Request #544 · nzbgetcom/nzbget · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add: completion and downloaded volumes statistics #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions daemon/nntp/ArticleDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
* Copyright (C) 2024-2025 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -153,13 +153,21 @@ void ArticleDownloader::Run()

if (status == adFinished || status == adFailed || status == adNotFound || status == adCrcError)
{
m_serverStats.StatOp(newsServer->GetId(), status == adFinished ? 1 : 0, status == adFinished ? 0 : 1, ServerStatList::soSet);
int serverId = newsServer->GetId();
int success = status == adFinished ? 1 : 0;
int failed = status == adFinished ? 0 : 1;
m_serverStats.StatOp(serverId, success, failed, ServerStatList::soSet);
ServerVolume::Stats stats;
stats.bytes = 0;
stats.articles.failed = failed;
stats.articles.success = success;
g_StatMeter->AddServerStats(stats, serverId);
}
}

if (m_connection)
{
AddServerData();
AddServerStats();
}

if (!connected && m_connection)
Expand Down Expand Up @@ -378,7 +386,7 @@ ArticleDownloader::EStatus ArticleDownloader::Download()
SetLastUpdateTimeNow();
if (oldTime != m_lastUpdateTime)
{
AddServerData();
AddServerStats();
}

// decode article data
Expand Down Expand Up @@ -583,15 +591,20 @@ void ArticleDownloader::FreeConnection(bool keepConnected)
{
m_connection->Disconnect();
}
AddServerData();
AddServerStats();
g_ServerPool->FreeConnection(m_connection, true);
m_connection = nullptr;
}
}

void ArticleDownloader::AddServerData()
void ArticleDownloader::AddServerStats()
{
int serverId = m_connection->GetNewsServer()->GetId();
int bytesRead = m_connection->FetchTotalBytesRead();
g_StatMeter->AddServerData(bytesRead, m_connection->GetNewsServer()->GetId());
ServerVolume::Stats stats;
stats.bytes = Util::SafeIntCast<int, uint32>(bytesRead);
stats.articles.failed = 0;
stats.articles.success = 0;
g_StatMeter->AddServerStats(stats, serverId);
m_downloadedSize += bytesRead;
}
4 changes: 2 additions & 2 deletions daemon/nntp/ArticleDownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Copyright (C) 2004 Sven Henkel <sidddy@users.sourceforge.net>
* Copyright (C) 2007-2017 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
* Copyright (C) 2024-2025 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -105,7 +105,7 @@ class ArticleDownloader : public Thread, public Subject
EStatus CheckResponse(const char* response, const char* comment);
void SetStatus(EStatus status) { m_status = status; }
bool Write(char* buffer, int len);
void AddServerData();
void AddServerStats();
};

#endif
71 changes: 57 additions & 14 deletions daemon/nntp/StatMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2014-2019 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
* Copyright (C) 2024-2025 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -45,9 +45,16 @@ void ServerVolume::CalcSlots(time_t locCurTime)
m_firstDay = curDay;
}
m_daySlot = curDay - m_firstDay;
if (m_daySlot + 1 > (int)m_bytesPerDays.size())

size_t daySlot = Util::SafeIntCast<int, size_t>(m_daySlot + 1);
if (daySlot > m_bytesPerDays.size())
{
m_bytesPerDays.resize(daySlot);
}

if (daySlot > m_articlesPerDays.size())
{
m_bytesPerDays.resize(m_daySlot + 1);
m_articlesPerDays.resize(daySlot);
}
}
else
Expand All @@ -56,7 +63,7 @@ void ServerVolume::CalcSlots(time_t locCurTime)
}
}

void ServerVolume::AddData(int bytes)
void ServerVolume::AddStats(Stats stats)
{
time_t curTime = Util::CurrentTime();
time_t locCurTime = curTime + g_WorkState->GetLocalTimeOffset();
Expand Down Expand Up @@ -113,25 +120,62 @@ void ServerVolume::AddData(int bytes)
}

// add bytes to every slot
int64 bytes = static_cast<int64>(stats.bytes);
m_bytesPerSeconds[m_secSlot] += bytes;
m_bytesPerMinutes[m_minSlot] += bytes;
m_bytesPerHours[m_hourSlot] += bytes;
if (m_daySlot >= 0)
{
m_bytesPerDays[m_daySlot] += bytes;
size_t daySlot = static_cast<size_t>(m_daySlot);
m_bytesPerDays[daySlot] += bytes;
m_articlesPerDays[daySlot].failed += stats.articles.failed;
m_articlesPerDays[daySlot].success += stats.articles.success;
}
m_totalBytes += bytes;
m_customBytes += bytes;

m_dataTime = curTime;
}

void ServerVolume::Reset()
{
m_totalBytes = 0;
m_dataTime = 0;
m_firstDay = 0;
m_countersResetTime = Util::CurrentTime();

ResetVolume(m_bytesPerSeconds);
ResetVolume(m_bytesPerMinutes);
ResetVolume(m_bytesPerHours);
ResetVolume(m_bytesPerDays);

ResetArticles();
ResetCustom();
}

void ServerVolume::ResetCustom()
{
m_customBytes = 0;
m_customTime = Util::CurrentTime();
}

void ServerVolume::ResetVolume(VolumeArray& volume)
{
for (int64& size : volume)
{
size = 0;
}
}

void ServerVolume::ResetArticles()
{
for (Articles& articles : m_articlesPerDays)
{
articles.failed = 0;
articles.success = 0;
}
}

void ServerVolume::LogDebugInfo()
{
info(" ---------- ServerVolume");
Expand Down Expand Up @@ -402,16 +446,11 @@ void StatMeter::LogDebugInfo()
}
}

void StatMeter::AddServerData(int bytes, int serverId)
void StatMeter::AddServerStats(ServerVolume::Stats stats, int serverId)
{
if (bytes == 0)
{
return;
}

Guard guard(m_volumeMutex);
m_serverVolumes[0].AddData(bytes);
m_serverVolumes[serverId].AddData(bytes);
m_serverVolumes[0].AddStats(stats);
m_serverVolumes[serverId].AddStats(stats);
m_statChanged = true;
}

Expand All @@ -422,7 +461,11 @@ GuardedServerVolumes StatMeter::GuardServerVolumes()
// update slots
for (ServerVolume& serverVolume : m_serverVolumes)
{
serverVolume.AddData(0);
ServerVolume::Stats stats;
stats.bytes = 0;
stats.articles.failed = 0;
stats.articles.success = 0;
serverVolume.AddStats(stats);
}

return serverVolumes;
Expand Down
43 changes: 37 additions & 6 deletions daemon/nntp/StatMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is part of nzbget. See <https://nzbget.com>.
*
* Copyright (C) 2014-2016 Andrey Prygunkov <hugbug@users.sourceforge.net>
* Copyright (C) 2024 Denis <denis@nzbget.com>
* Copyright (C) 2024-2025 Denis <denis@nzbget.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -31,12 +31,27 @@
class ServerVolume
{
public:
typedef std::vector<int64> VolumeArray;
struct Articles
{
uint32 failed;
uint32 success;
};
struct Stats
{
uint32 bytes;
Articles articles;
};

using VolumeArray = std::vector<int64>;
using ArticlesArray = std::vector<Articles>;

VolumeArray* BytesPerSeconds() { return &m_bytesPerSeconds; }
VolumeArray* BytesPerMinutes() { return &m_bytesPerMinutes; }
VolumeArray* BytesPerHours() { return &m_bytesPerHours; }
VolumeArray* BytesPerDays() { return &m_bytesPerDays; }

const ArticlesArray& GetArticlesPerDays() const { return m_articlesPerDays; }
void SetArticlesPerDays(ArticlesArray articles) { m_articlesPerDays = std::move(articles); }
void SetFirstDay(int firstDay) { m_firstDay = firstDay; }
int GetFirstDay() { return m_firstDay; }
void SetTotalBytes(int64 totalBytes) { m_totalBytes = totalBytes; }
Expand All @@ -51,30 +66,46 @@ class ServerVolume
void SetDataTime(time_t dataTime) { m_dataTime = dataTime; }
time_t GetCustomTime() { return m_customTime; }
void SetCustomTime(time_t customTime) { m_customTime = customTime; }
time_t GetCountersResetTime() { return m_countersResetTime; }
void SetCountersResetTime(time_t time) { m_countersResetTime = time; }

void AddData(int bytes);
void AddStats(Stats stats);
void CalcSlots(time_t locCurTime);
void Reset();
void ResetCustom();
void LogDebugInfo();

private:
void ResetVolume(VolumeArray& volume);
void ResetArticles();

VolumeArray m_bytesPerSeconds = VolumeArray(60);
VolumeArray m_bytesPerMinutes = VolumeArray(60);
VolumeArray m_bytesPerHours = VolumeArray(24);
VolumeArray m_bytesPerDays;
ArticlesArray m_articlesPerDays;

int m_firstDay = 0;
int64 m_totalBytes = 0;
int64 m_customBytes = 0;

/** Date/time when the data was last updated (time is in C/Unix format) */
time_t m_dataTime = 0;

/** Date/time of the last reset of custom counter (time is in C/Unix format) */
time_t m_customTime = Util::CurrentTime();

/** Date/time of the last reset of all counters (time is in C/Unix format) */
time_t m_countersResetTime = Util::CurrentTime();

int m_secSlot = 0;
int m_minSlot = 0;
int m_hourSlot = 0;
int m_daySlot = 0;
};

typedef std::vector<ServerVolume> ServerVolumes;
typedef GuardedPtr<ServerVolumes> GuardedServerVolumes;
using ServerVolumes = std::vector<ServerVolume>;
using GuardedServerVolumes = GuardedPtr<ServerVolumes>;

class StatMeter : public Debuggable
{
Expand All @@ -84,7 +115,7 @@ class StatMeter : public Debuggable
int64 CalcCurrentDownloadSpeed();
int64 CalcMomentaryDownloadSpeed();
void AddSpeedReading(int bytes);
void AddServerData(int bytes, int serverId);
void AddServerStats(ServerVolume::Stats stats, int serverId);
void CalcTotalStat(int* upTimeSec, int* dnTimeSec, int64* allBytes, bool* standBy);
void CalcQuotaUsage(int64& monthBytes, int64& dayBytes);
void IntervalCheck();
Expand Down
Loading
0