1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-07-05 00:28:52 +02:00

Add general-purpose statistics collector.

Currently each module that needs to collect statistics implements custom code to do so. This is cumbersome.

Create a general purpose module for collecting and reporting statistics. Statistics are output in the log at detail level, but there are other uses they could be put to eventually.

No new functionality is added. This is just a drop-in replacement for the current statistics, with the advantage of being more flexible.

The new stats are slower because they involve a list lookup, but performance testing shows stats can be updated at about 40,000/ms which seems fast enough for our purposes.
This commit is contained in:
David Steele
2020-08-20 14:04:26 -04:00
committed by GitHub
parent 53f8e7a9cf
commit 959f77cd6a
26 changed files with 356 additions and 202 deletions

View File

@ -7,12 +7,11 @@ Common Command Routines
#include <string.h>
#include "common/debug.h"
#include "common/io/http/client.h"
#include "common/io/socket/client.h"
#include "common/io/tls/client.h"
#include "common/log.h"
#include "common/memContext.h"
#include "common/stat.h"
#include "common/time.h"
#include "common/type/json.h"
#include "config/config.h"
#include "version.h"
@ -181,23 +180,11 @@ cmdEnd(int code, const String *errorMessage)
{
MEM_CONTEXT_TEMP_BEGIN()
{
// Log socket statistics
String *sckClientStat = sckClientStatStr();
// Output statistics if there are any
const KeyValue *statKv = statToKv();
if (sckClientStat != NULL)
LOG_DETAIL(strZ(sckClientStat));
// Log tls statistics
String *tlsClientStat = tlsClientStatStr();
if (tlsClientStat != NULL)
LOG_DETAIL(strZ(tlsClientStat));
// Log http statistics
String *httpClientStat = httpClientStatStr();
if (httpClientStat != NULL)
LOG_INFO(strZ(httpClientStat));
if (varLstSize(kvKeyList(statKv)) > 0)
LOG_DETAIL_FMT("statistics: %s", strZ(jsonFromKv(statKv)));
// Basic info on command end
String *info = strNewFmt("%s command end: ", strZ(cfgCommandRoleName()));