Add summary stat's calculation

This commit is contained in:
Andrew Johnson
2025-02-18 14:20:14 -06:00
parent 90f97a7037
commit 72f3e75c8d
4 changed files with 39 additions and 10 deletions

View File

@@ -130,11 +130,23 @@ int dbServerClient(char *pBuf, size_t bufSize)
int dbServerStats(const char *name, unsigned *channels, unsigned *clients)
{
dbServer *psrv = (dbServer *)ellFirst(&serverList);
unsigned tch, tcl;
if (!name || state != running || !psrv)
if (state != running || !psrv)
return -1;
while (psrv) {
for (tch = 0, tcl = 0; psrv;
psrv = (dbServer *)ellNext(&psrv->node)) {
if (!name) {
if (psrv->stats) {
unsigned lch, lcl;
psrv->stats(&lch, &lcl);
tch += lch;
tcl += lcl;
}
continue;
}
if (strcmp(name, psrv->name) == 0) {
if (!psrv->stats)
return -1;
@@ -142,7 +154,11 @@ int dbServerStats(const char *name, unsigned *channels, unsigned *clients)
psrv->stats(channels, clients);
return 0;
}
psrv = (dbServer *)ellNext(&psrv->node);
}
if (!name) {
if (channels) *channels = tch;
if (clients) *clients = tcl;
return 0;
}
return -1;
}

View File

@@ -151,9 +151,11 @@ DBCORE_API int dbServerClient(char *pBuf, size_t bufSize);
*
* This is an API for iocStats and similar to fetch the number of channels
* and clients connected to the named server layer.
* If the name given is NULL the statistics returned are the totals for
* all the registered server layers.
* @param name Server name
* @param channels Where to return the channel count
* @param clients Where to return the client count
* @param channels NULL, or where to return the channel count
* @param clients NULL or where to return the client count
* @returns 0 on success; -1 if IOC isn't running, no such named server,
* or that server doesn't implement the stats method.
*