Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bareos/bareos.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlaa Eddine Elamri <alaeddine.elamri@bareos.com>2022-10-25 18:24:10 +0300
committerAlaa Eddine Elamri <alaeddine.elamri@bareos.com>2022-11-10 22:13:37 +0300
commit379ebbac25130e49c98b486a60c2d0b6d722b36e (patch)
tree64751334ef8e20bfc183e85fc108a8cf52987112
parente8ea99c5afa74ec2c913dae4454c3a831a2cce74 (diff)
stored: dird: lib: cats: add new stats and checkpoint fields
added: * last checkpoint time * last checkpoint files * last transfer rate * average rate update filename only when attribute was actually updated
-rw-r--r--core/src/cats/sql_update.cc19
-rw-r--r--core/src/dird/catreq.cc15
-rw-r--r--core/src/include/jcr.h3
-rw-r--r--core/src/lib/jcr.cc16
-rw-r--r--core/src/stored/append.cc3
-rw-r--r--core/src/stored/askdir.cc6
-rw-r--r--core/src/stored/status.cc20
7 files changed, 55 insertions, 27 deletions
diff --git a/core/src/cats/sql_update.cc b/core/src/cats/sql_update.cc
index df1826a6c..fbb28479d 100644
--- a/core/src/cats/sql_update.cc
+++ b/core/src/cats/sql_update.cc
@@ -113,9 +113,24 @@ bool BareosDb::UpdateJobStartRecord(JobControlRecord* jcr, JobDbRecord* jr)
bool BareosDb::UpdateRunningJobRecord(JobControlRecord* jcr)
{
+ char timestamp[MAX_TIME_LENGTH];
+
+ auto now
+ = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
+
+ bstrutime(timestamp, sizeof(timestamp), now);
+
+ jcr->UpdateJobStats();
+
DbLocker _{this};
- Mmsg(cmd, "UPDATE Job SET JobBytes=%llu,JobFiles=%lu WHERE JobId=%lu",
- jcr->JobBytes, jcr->JobFiles, jcr->JobId);
+ Mmsg(cmd,
+ "UPDATE Job SET "
+ "JobFiles=%lu,LastCheckpointFiles=%lu,"
+ "JobBytes=%llu,AverageTransferRate=%lu,LastTransferRate=%lu,"
+ "LastCheckpointTime='%s',LastFileProcessed='%s'"
+ " WHERE JobId=%lu",
+ jcr->JobFiles, jcr->LastCheckpointFiles, jcr->JobBytes, jcr->AverageRate,
+ jcr->LastRate, timestamp, jcr->ar ? jcr->ar->fname : "", jcr->JobId);
return UPDATE_DB(jcr, cmd) > 0;
}
diff --git a/core/src/dird/catreq.cc b/core/src/dird/catreq.cc
index b9dc5f533..95caac039 100644
--- a/core/src/dird/catreq.cc
+++ b/core/src/dird/catreq.cc
@@ -69,7 +69,8 @@ static char Create_job_media[]
static char Update_filelist[] = "Catreq Job=%127s UpdateFileList\n";
static char Update_jobrecord[]
- = "Catreq Job=%127s UpdateJobRecord JobFiles=%lu JobBytes=%llu\n";
+ = "Catreq Job=%127s UpdateJobRecord LastCheckpointFiles=%lu JobFiles=%lu "
+ "JobBytes=%llu\n";
// Responses sent to Storage daemon
static char OK_media[]
@@ -131,9 +132,6 @@ void CatalogRequest(JobControlRecord* jcr, BareosSocket* bs)
return;
}
- uint32_t update_jobfiles = 0;
- uint64_t update_jobbytes = 0;
-
// Find next appendable medium for SD
unwanted_volumes.check_size(bs->message_length);
if (sscanf(bs->msg, Find_media, &Job, &index, &pool_name, &mr.MediaType,
@@ -362,14 +360,11 @@ void CatalogRequest(JobControlRecord* jcr, BareosSocket* bs)
_("Batch database connection not found. Cannot update file list\n"));
}
- } else if (sscanf(bs->msg, Update_jobrecord, &Job, &update_jobfiles,
- &update_jobbytes)
- == 3) {
+ } else if (sscanf(bs->msg, Update_jobrecord, &Job, &jcr->LastCheckpointFiles,
+ &jcr->JobFiles, &jcr->JobBytes)
+ == 4) {
Dmsg0(0, "Updating job record\n");
- jcr->JobFiles = update_jobfiles;
- jcr->JobBytes = update_jobbytes;
-
if (!jcr->db->UpdateRunningJobRecord(jcr)) {
Jmsg(jcr, M_FATAL, 0, _("Catalog error updating Job record. %s\n"),
jcr->db->strerror());
diff --git a/core/src/include/jcr.h b/core/src/include/jcr.h
index f140e399f..22a95c8b2 100644
--- a/core/src/include/jcr.h
+++ b/core/src/include/jcr.h
@@ -143,6 +143,7 @@ class JobControlRecord {
void MyThreadSendSignal(int sig); /**< in lib/jcr.c */
void SetKillable(bool killable); /**< in lib/jcr.c */
bool IsKillable() const { return my_thread_killable; }
+ void UpdateJobStats();
dlink<JobControlRecord> link; /**< JobControlRecord chain link */
pthread_t my_thread_id{}; /**< Id of thread controlling jcr */
@@ -162,9 +163,11 @@ class JobControlRecord {
uint32_t VolSessionId{};
uint32_t VolSessionTime{};
uint32_t JobFiles{}; /**< Number of files written, this job */
+ uint32_t LastCheckpointFiles{}; /**< Last checkpoint number of files written*/
uint32_t JobErrors{}; /**< Number of non-fatal errors this job */
uint32_t JobWarnings{}; /**< Number of warning messages */
uint32_t LastRate{}; /**< Last sample bytes/sec */
+ uint32_t AverageRate{}; /**< Last average bytes/sec */
uint64_t JobBytes{}; /**< Number of bytes processed this job */
uint64_t LastJobBytes{}; /**< Last sample number bytes */
uint64_t ReadBytes{}; /**< Bytes read -- before compression */
diff --git a/core/src/lib/jcr.cc b/core/src/lib/jcr.cc
index cd983b894..7dbebf362 100644
--- a/core/src/lib/jcr.cc
+++ b/core/src/lib/jcr.cc
@@ -861,6 +861,22 @@ void JcrWalkEnd(JobControlRecord* jcr)
}
}
+
+void JobControlRecord::UpdateJobStats()
+{
+ time_t now = time(nullptr);
+ int sec;
+
+ if (last_time == 0) { last_time = run_time; }
+ sec = now - last_time;
+ if (sec <= 0) { sec = 1; }
+ LastRate = (JobBytes - LastJobBytes) / sec;
+ if (AverageRate == 0) { AverageRate = LastRate; }
+ AverageRate = (AverageRate + LastRate) / 2;
+ LastJobBytes = JobBytes;
+ last_time = now;
+}
+
// Return number of Jobs
int JobCount()
{
diff --git a/core/src/stored/append.cc b/core/src/stored/append.cc
index 338841a74..12b11c351 100644
--- a/core/src/stored/append.cc
+++ b/core/src/stored/append.cc
@@ -147,6 +147,9 @@ static void SaveFullyProcessedFiles(JobControlRecord* jcr,
for_each(
processed_files.begin(), processed_files.end(),
[&jcr](ProcessedFile& file) { file.SendAttributesToDirector(jcr); });
+
+ jcr->LastCheckpointFiles
+ = processed_files.back().GetFileIndex() - jcr->JobFiles;
jcr->JobFiles = processed_files.back().GetFileIndex();
processed_files.clear();
}
diff --git a/core/src/stored/askdir.cc b/core/src/stored/askdir.cc
index cd2de66cf..35c8d5e6a 100644
--- a/core/src/stored/askdir.cc
+++ b/core/src/stored/askdir.cc
@@ -66,7 +66,8 @@ static char Create_job_media[]
static char Update_filelist[] = "Catreq Job=%s UpdateFileList\n";
static char Update_jobrecord[]
- = "Catreq Job=%s UpdateJobRecord JobFiles=%lu JobBytes=%llu\n";
+ = "Catreq Job=%s UpdateJobRecord LastCheckpointFiles=%lu JobFiles=%lu "
+ "JobBytes=%llu\n";
static char FileAttributes[] = "UpdCat Job=%s FileAttributes ";
@@ -630,7 +631,8 @@ bool StorageDaemonDeviceControlRecord::DirAskToUpdateFileList()
bool StorageDaemonDeviceControlRecord::DirAskToUpdateJobRecord()
{
BareosSocket* dir = jcr->dir_bsock;
- return dir->fsend(Update_jobrecord, jcr->Job, jcr->JobFiles, jcr->JobBytes);
+ return dir->fsend(Update_jobrecord, jcr->Job, jcr->LastCheckpointFiles,
+ jcr->JobFiles, jcr->JobBytes);
}
diff --git a/core/src/stored/status.cc b/core/src/stored/status.cc
index 5432af94e..dd3106d44 100644
--- a/core/src/stored/status.cc
+++ b/core/src/stored/status.cc
@@ -650,9 +650,8 @@ static void ListRunningJobs(StatusPacket* sp)
JobControlRecord* jcr;
DeviceControlRecord *dcr, *rdcr;
bool found = false;
- time_t now = time(NULL);
PoolMem msg(PM_MESSAGE);
- int len, avebps, bps, sec;
+ int len;
char JobName[MAX_NAME_LENGTH];
char b1[50], b2[50], b3[50], b4[50];
@@ -701,22 +700,17 @@ static void ListRunningJobs(StatusPacket* sp)
dcr->spooling, dcr->despooling, dcr->despool_wait);
sp->send(msg, len);
}
- if (jcr->last_time == 0) { jcr->last_time = jcr->run_time; }
- sec = now - jcr->last_time;
- if (sec <= 0) { sec = 1; }
- bps = (jcr->JobBytes - jcr->LastJobBytes) / sec;
- if (jcr->LastRate == 0) { jcr->LastRate = bps; }
- avebps = (jcr->LastRate + bps) / 2;
+
+ jcr->UpdateJobStats();
+
len = Mmsg(msg,
_(" Files=%s Bytes=%s AveBytes/sec=%s LastBytes/sec=%s\n"),
edit_uint64_with_commas(jcr->JobFiles, b1),
edit_uint64_with_commas(jcr->JobBytes, b2),
- edit_uint64_with_commas(avebps, b3),
- edit_uint64_with_commas(bps, b4));
+ edit_uint64_with_commas(jcr->AverageRate, b3),
+ edit_uint64_with_commas(jcr->LastRate, b4));
sp->send(msg, len);
- jcr->LastRate = avebps;
- jcr->LastJobBytes = jcr->JobBytes;
- jcr->last_time = now;
+
found = true;
if (jcr->file_bsock) {
len = Mmsg(msg, _(" FDReadSeqNo=%s in_msg=%u out_msg=%d fd=%d\n"),