From 0f0725c9296228b8d3a6729572ab60c4b1721791 Mon Sep 17 00:00:00 2001 From: Simon Pichugin Date: Mar 13 2018 07:43:59 +0000 Subject: Issue 49593 - NDN cache stats should be under the global stats Bug description: The Normalized DN cache stats are listed under backend stats, but the cache is global across all backends so they should just be listed under the global ldbm monitor. Fix description: Move NDN stats to global ldbm monitor. Change lib389 MonitorLDBM and MonitorBackend objects accordingly. Fix dbmon.sh tool so it shows the stats like this: Wed Mar 7 12:50:14 EST 2018 dbcachefree 52150272 free% 99.812 roevicts 0 hit% 100 pagein 0 pageout 0 dbname count free free% size hit_ratio global:ndn 69 20960096 99.946 165.565 73 userroot:ent 2 201318969 100.0 3811.5 62.0 userroot:dn 2 67108738 100.0 63.0 0.0 https://pagure.io/389-ds-base/issue/49593 Reviewed by: mreynolds, wibrown (Thanks!) --- diff --git a/ldap/admin/src/scripts/dbmon.sh.in b/ldap/admin/src/scripts/dbmon.sh.in index 8dad687..55aaff5 100644 --- a/ldap/admin/src/scripts/dbmon.sh.in +++ b/ldap/admin/src/scripts/dbmon.sh.in @@ -55,6 +55,10 @@ parseldif() { /^dbcachepageout/ { dbcachepageout=$2 } /^nsslapd-db-page-ro-evict-rate/ { dbroevict=$2 } /^nsslapd-db-pages-in-use/ { dbpages=$2 } + /^normalizeddncachehitratio/ { ndnratio=$2 } + /^currentnormalizeddncachesize/ { ndncursize=$2 ; havendnstats=1 } + /^maxnormalizeddncachesize/ { ndnmaxsize=$2 } + /^currentnormalizeddncachecount/ { ndncount=$2 } /^dn: cn=monitor, *cn=[a-zA-Z0-9][a-zA-Z0-9_\.\-]*, *cn=ldbm database, *cn=plugins, *cn=config/ { idxnum=-1 idxname="" @@ -72,10 +76,6 @@ parseldif() { /^maxdncachesize/ { stats[dbname,"dnmax"]=$2 } /^currentdncachecount/ { stats[dbname,"dncnt"]=$2 } /^dncachehitratio/ { stats[dbname,"dnratio"]=$2 } - /^normalizeddncachehitratio/ { stats[dbname,"ndnratio"]=$2 } - /^currentnormalizeddncachesize/ { stats[dbname,"ndncursize"]=$2 ; havendnstats=1 } - /^maxnormalizeddncachesize/ { stats[dbname,"ndnmaxsize"]=$2 } - /^currentnormalizeddncachecount/ { stats[dbname,"ndncount"]=$2 } /^dbfilename-/ { #rhds @@ -142,7 +142,9 @@ parseldif() { maxdbnamelen += 4 # :ent dbentext = ":ent" dbdnext = ":dn " - dbndnext = ":ndn" + if (havendnstats) { + dbndnext = ":ndn" + } } else { dbentext = "" dbdnext = "" @@ -156,6 +158,16 @@ parseldif() { fmtstr = sprintf("%%%d.%ds %%10.10s %%13.13s %%6.6s %%7.7s %%10.9s\n", maxdbnamelen, maxdbnamelen) printf fmtstr, "dbname", "count", "free", "free%", "size", "hit_ratio%" } + + fmtstr = sprintf("%%%d.%ds %%10d %%13d %%6.1f %%7.1f %%10.1f\n", maxdbnamelen, maxdbnamelen) + if (havendnstats) { + # normalized dn cache + ndnfree=ndnmaxsize-ndncursize + ndnfreep=ndnfree/ndnmaxsize*100 + ndnsize=(ndncount == 0) ? 0 : ndncursize/ndncount + printf fmtstr, "global" dbndnext, ndncount, ndnfree, ndnfreep, ndnsize, ndnratio + } + for (dbn in dbnames) { cur=stats[dbn,"entcur"] max=stats[dbn,"entmax"] @@ -164,7 +176,6 @@ parseldif() { free=max-cur freep=free/max*100 size=(cnt == 0) ? 0 : cur/cnt - fmtstr = sprintf("%%%d.%ds %%10d %%13d %%6.1f %%7.1f %%10.1f\n", maxdbnamelen, maxdbnamelen) printf fmtstr, dbnames[dbn] dbentext, cnt, free, freep, size, eratio if (havednstats) { dcur=stats[dbn,"dncur"] @@ -177,18 +188,6 @@ parseldif() { printf fmtstr, dbnames[dbn] dbdnext, dcnt, dfree, dfreep, dsize, dratio } - if (havendnstats) { - # normalized dn cache - nratio=stats[dbn,"ndnratio"] - ncursize=stats[dbn,"ndncursize"] - nmaxsize=stats[dbn,"ndnmaxsize"] - ncount=stats[dbn,"ndncount"] - nfree=nmaxsize-ncursize - nfreep=nfree/nmaxsize*100 - nsize=(ncount == 0) ? 0 : ncursize/ncount - printf fmtstr, dbnames[dbn] dbndnext, ncount, nfree, nfreep, nsize, nratio - } - if (indexlist) { len = idxmaxlen[dbn] fmtstr = sprintf("%%%d.%ds %%%d.%ds pagein %%8d pageout %%8d\n", maxdbnamelen, maxdbnamelen, len, len) diff --git a/ldap/servers/slapd/back-ldbm/monitor.c b/ldap/servers/slapd/back-ldbm/monitor.c index 5f57b9f..f912dca 100644 --- a/ldap/servers/slapd/back-ldbm/monitor.c +++ b/ldap/servers/slapd/back-ldbm/monitor.c @@ -48,11 +48,9 @@ ldbm_back_monitor_instance_search(Slapi_PBlock *pb __attribute__((unused)), struct berval *vals[2]; char buf[BUFSIZ]; PRUint64 hits, tries; - long nentries, maxentries, count; + int64_t nentries; + int64_t maxentries; size_t size, maxsize; - size_t thread_size; - size_t evicts; - size_t slots; /* NPCTE fix for bugid 544365, esc 0. <04-Jul-2001> */ struct stat astat; /* end of NPCTE fix for bugid 544365 */ @@ -101,9 +99,9 @@ ldbm_back_monitor_instance_search(Slapi_PBlock *pb __attribute__((unused)), MSET("currentEntryCacheSize"); sprintf(buf, "%lu", (long unsigned int)maxsize); MSET("maxEntryCacheSize"); - sprintf(buf, "%ld", nentries); + sprintf(buf, "%" PRId64, nentries); MSET("currentEntryCacheCount"); - sprintf(buf, "%ld", maxentries); + sprintf(buf, "%" PRId64, maxentries); MSET("maxEntryCacheCount"); if (entryrdn_get_switch()) { @@ -120,39 +118,11 @@ ldbm_back_monitor_instance_search(Slapi_PBlock *pb __attribute__((unused)), MSET("currentDnCacheSize"); sprintf(buf, "%lu", (long unsigned int)maxsize); MSET("maxDnCacheSize"); - sprintf(buf, "%ld", nentries); + sprintf(buf, "%" PRId64, nentries); MSET("currentDnCacheCount"); - sprintf(buf, "%ld", maxentries); + sprintf(buf, "%" PRId64, maxentries); MSET("maxDnCacheCount"); } - /* normalized dn cache stats */ - if (ndn_cache_started()) { - ndn_cache_get_stats(&hits, &tries, &size, &maxsize, &thread_size, &evicts, &slots, &count); - sprintf(buf, "%" PRIu64, tries); - MSET("normalizedDnCacheTries"); - sprintf(buf, "%" PRIu64, hits); - MSET("normalizedDnCacheHits"); - sprintf(buf, "%" PRIu64, (tries - hits)); - MSET("normalizedDnCacheMisses"); - sprintf(buf, "%lu", (unsigned long)(100.0 * (double)hits / (double)(tries > 0 ? tries : 1))); - MSET("normalizedDnCacheHitRatio"); - sprintf(buf, "%"PRIu64, evicts); - MSET("NormalizedDnCacheEvictions"); - sprintf(buf, "%lu", (long unsigned int)size); - MSET("currentNormalizedDnCacheSize"); - if (maxsize == 0) { - sprintf(buf, "%d", -1); - } else { - sprintf(buf, "%lu", (long unsigned int)maxsize); - } - MSET("maxNormalizedDnCacheSize"); - sprintf(buf, "%"PRIu64, thread_size); - MSET("NormalizedDnCacheThreadSize"); - sprintf(buf, "%"PRIu64, slots); - MSET("NormalizedDnCacheThreadSlots"); - sprintf(buf, "%ld", count); - MSET("currentNormalizedDnCacheCount"); - } #ifdef DEBUG { @@ -235,6 +205,14 @@ ldbm_back_monitor_search(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAft DB_MPOOL_STAT *mpstat = NULL; DB_MPOOL_FSTAT **mpfstat = NULL; uintmax_t cache_tries; + int64_t count; + uint64_t hits; + uint64_t tries; + uint64_t size; + uint64_t maxsize; + uint64_t thread_size; + uint64_t evicts; + uint64_t slots; vals[0] = &val; vals[1] = NULL; @@ -271,6 +249,35 @@ ldbm_back_monitor_search(Slapi_PBlock *pb, Slapi_Entry *e, Slapi_Entry *entryAft sprintf(buf, "%lu", (unsigned long)mpstat->st_rw_evict); MSET("dbCacheRWEvict"); + /* normalized dn cache stats */ + if (ndn_cache_started()) { + ndn_cache_get_stats(&hits, &tries, &size, &maxsize, &thread_size, &evicts, &slots, &count); + sprintf(buf, "%" PRIu64, tries); + MSET("normalizedDnCacheTries"); + sprintf(buf, "%" PRIu64, hits); + MSET("normalizedDnCacheHits"); + sprintf(buf, "%" PRIu64, (tries - hits)); + MSET("normalizedDnCacheMisses"); + sprintf(buf, "%" PRIu64, (uint64_t)(100.0 * (double)hits / (double)(tries > 0 ? tries : 1))); + MSET("normalizedDnCacheHitRatio"); + sprintf(buf, "%" PRIu64, evicts); + MSET("NormalizedDnCacheEvictions"); + sprintf(buf, "%" PRIu64, size); + MSET("currentNormalizedDnCacheSize"); + if (maxsize == 0) { + sprintf(buf, "%d", -1); + } else { + sprintf(buf, "%" PRIu64, maxsize); + } + MSET("maxNormalizedDnCacheSize"); + sprintf(buf, "%" PRIu64, thread_size); + MSET("NormalizedDnCacheThreadSize"); + sprintf(buf, "%" PRIu64, slots); + MSET("NormalizedDnCacheThreadSlots"); + sprintf(buf, "%" PRId64, count); + MSET("currentNormalizedDnCacheCount"); + } + slapi_ch_free((void **)&mpstat); if (mpfstat) diff --git a/src/lib389/lib389/monitor.py b/src/lib389/lib389/monitor.py index e36d911..1cf9b22 100644 --- a/src/lib389/lib389/monitor.py +++ b/src/lib389/lib389/monitor.py @@ -10,6 +10,7 @@ import ldap from ldap import filter as ldap_filter from lib389._constants import * from lib389._mapped_object import DSLdapObjects, DSLdapObject +from lib389.utils import ds_is_older class Monitor(DSLdapObject): """An object that helps reading of cn=monitor for server statistics. @@ -96,6 +97,17 @@ class MonitorLDBM(DSLdapObject): 'dbcacheroevict', 'dbcacherwevict', ] + if not ds_is_older("1.4.0"): + self._backend_keys.extend([ + 'normalizeddncachetries', + 'normalizeddncachehits', + 'normalizeddncachemisses', + 'normalizeddncachehitratio', + 'currentnormalizeddncachesize', + 'maxnormalizeddncachesize', + 'currentnormalizeddncachecount' + ]) + def status(self): return self.get_attrs_vals(self._backend_keys) @@ -122,14 +134,17 @@ class MonitorBackend(DSLdapObject): 'maxdncachesize', 'currentdncachecount', 'maxdncachecount', - 'normalizeddncachetries', - 'normalizeddncachehits', - 'normalizeddncachemisses', - 'normalizeddncachehitratio', - 'currentnormalizeddncachesize', - 'maxnormalizeddncachesize', - 'currentnormalizeddncachecount', ] + if ds_is_older("1.4.0"): + self._backend_keys.extend([ + 'normalizeddncachetries', + 'normalizeddncachehits', + 'normalizeddncachemisses', + 'normalizeddncachehitratio', + 'currentnormalizeddncachesize', + 'maxnormalizeddncachesize', + 'currentnormalizeddncachecount' + ]) def status(self): return self.get_attrs_vals(self._backend_keys)