This file is indexed.

/usr/sbin/dbmon.sh is in 389-ds-base 1.3.7.10-1ubuntu1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/sh
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2014 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details. 
# END COPYRIGHT BLOCK
#

. /usr/share/dirsrv/data/DSSharedLib

DURATION=${DURATION:-0}
INCR=${INCR:-1}
SERVID=${SERVID}
BINDDN=${BINDDN:-"cn=directory manager"}
BINDPW=${BINDPW:-"secret"}
DBLIST=${DBLIST:-all}
ldbmdn="cn=ldbm database,cn=plugins,cn=config"
VERBOSE=${VERBOSE:-0}

parseldif() {
    awk -v dblist="$DBLIST" -v verbose=$VERBOSE -v indexlist="$INDEXLIST" -F '[:,= ]+' '
        function printary(ary) {
            for (ii in ary) { print ii, "=", ary[ii] }
        }
        BEGIN {
            pagesize=8192 ; CONVFMT="%.3f" ; OFMT=CONVFMT ; SUBSEP=","
            alldb=0
            if (dblist == "all") {
                alldb=1
            } else {
                split(dblist, dbnames)
                for (key in dbnames) { val=dbnames[key] ; dbnames[tolower(val)]=val; delete dbnames[key] }
            }
            allindex=0
            if (indexlist == "all") {
                allindex=1
            } else {
                split(indexlist, idxnames)
                for (key in idxnames) { val=idxnames[key] ; idxnames[tolower(val)]=val; delete idxnames[key] }
            }
            fn="entcur entmax entcnt dncur dnmax dncnt"
            split(fn, fields)
            havednstats=0
            havendnstats=0
            maxdbnamelen=0
        }
        /^[^ ]|^$/ {origline = $0; $0 = unwrapline; unwrapline = origline}
        /^ / {sub(/^ /, ""); unwrapline = unwrapline $0; next}
        /^nsslapd-db-cache-size-bytes/ { dbcachesize=$2 }
        /^nsslapd-db-page-size/ { pagesize=$2 }
        /^dbcachehitratio/ { dbhitratio=$2 }
        /^dbcachepagein/ { dbcachepagein=$2 }
        /^dbcachepageout/ { dbcachepageout=$2 }
        /^nsslapd-db-page-ro-evict-rate/ { dbroevict=$2 }
        /^nsslapd-db-pages-in-use/ { dbpages=$2 }
        /^dn: cn=monitor, *cn=[a-zA-Z0-9][a-zA-Z0-9_\.\-]*, *cn=ldbm database, *cn=plugins, *cn=config/ {
            idxnum=-1
            idxname=""
            dbname=tolower($5)
            if ((dbname in dbnames) || alldb) {
                len=length(dbname) ; if (len > maxdbnamelen) { maxdbnamelen=len }
                if (!(dbname in dbnames)) { dbnames[dbname] = dbname }
            }
        }
        /^currententrycachesize/ { stats[dbname,"entcur"]=$2 }
        /^maxentrycachesize/ { stats[dbname,"entmax"]=$2 }
        /^currententrycachecount/ { stats[dbname,"entcnt"]=$2 }
        /^entrycachehitratio/ { stats[dbname,"entratio"]=$2 }
        /^currentdncachesize/ { stats[dbname,"dncur"]=$2 ; havednstats=1 }
        /^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
            #dbfilename-3: userRoot/id2entry.db4
            #sunds
            #dbfilename-id2entry: /full/path/to/db/dbname/dbname_id2entry.dbX
            if (dbname in dbnames) {
                split($0, idxline, /[ :/.-]+/)
                idxname=tolower(idxline[4])
                dbn=tolower(idxline[3])
                ilen=length(idxline)
                sundbn=tolower(idxline[ilen-2])
                sunidxname=tolower(idxline[2]) 
                if ((dbn == dbname) && (allindex || (idxname in idxnames))) {
                    idxnum=idxline[2]
                    if (!(idxname in idxnames)) { idxnames[idxname] = idxname }
                    len = length(idxname)
                    if (len > idxmaxlen[dbn]) { idxmaxlen[dbn] = len }
                } else if ((sundbn == dbname) && (allindex || (sunidxname in idxnames))) {
                    idxname=sunidxname
                    idxnum=1 # no index number just index name
                    if (!(idxname in idxnames)) { idxnames[idxname] = idxname }
                    len = length(idxname)
                    if (len > idxmaxlen[sundbn]) { idxmaxlen[sundbn] = len }
                } else {
                    # print "index", idxline[4], "not in idxnames"
                }
            } else {
                # print "dbname", dbname, "not in dbnames"
            }
        }
        /^dbfilepagein-/ { if (idxnum >= 0) { idxstats[dbname,idxname,"pagein"] = $2 } }
        /^dbfilepageout-/ { if (idxnum >= 0) { idxstats[dbname,idxname,"pageout"] = $2 } }
        END {
            free=(dbcachesize-(pagesize*dbpages))
            freeratio=free/dbcachesize
            if (verbose > 1) {
                print "# dbcachefree - free bytes in dbcache"
                print "# free% - percent free in dbcache"
                print "# roevicts - number of read-only pages dropped from cache to make room for other pages"
                print "#            if this is non-zero, it means the dbcache is maxed out and there is page churn"
                print "# hit% - percent of requests that are served by cache"
                print "# pagein - number of pages read into the cache"
                print "# pageout - number of pages dropped from the cache"
            }
            print "dbcachefree", free, "free%", (freeratio*100), "roevicts", dbroevict, "hit%", dbhitratio, "pagein", dbcachepagein, "pageout", dbcachepageout
            if (verbose > 1) {
                print "# dbname - name of database instance - the row shows the entry cache stats"
                print "# count - number of entries in cache"
                print "# free - number of free bytes in cache"
                print "# free% - percent free in cache"
                print "# size - average size of date in cache in bytes (current size/count)"
                if (havednstats) {
                    print "# DNcache - the line below the entry cache stats are the DN cache stats"
                    print "# count - number of dns in dn cache"
                    print "# free - number of free bytes in dn cache"
                    print "# free% - percent free in dn cache"
                    print "# size - average size of dn in dn cache in bytes (currentdncachesize/currentdncachecount)"
                    print "# hit_ratio - cache hit ratio"
                    print "# under each db are the list of selected indexes specified with INDEXLIST"
                }
            }
            if (havednstats || havendnstats) { # make sure there is enough room for dbname:ent and dbname:dn
                maxdbnamelen += 4 # :ent
                dbentext = ":ent"
                dbdnext = ":dn "
                dbndnext = ":ndn"
            } else {
                dbentext = ""
                dbdnext = ""
            }

            if (maxdbnamelen < 6) { # len of "dbname"
                maxdbnamelen = 6
            }

            if (verbose > 0) {
                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%"
            }
            for (dbn in dbnames) {
                cur=stats[dbn,"entcur"]
                max=stats[dbn,"entmax"]
                cnt=stats[dbn,"entcnt"]
                eratio=stats[dbname,"entratio"]
                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"]
                    dmax=stats[dbn,"dnmax"]
                    dcnt=stats[dbn,"dncnt"]
                    dratio=stats[dbn,"dnratio"]
                    dfree=dmax-dcur
                    dfreep=dfree/dmax*100
                    dsize=(dcnt == 0) ? 0 : dcur/dcnt
                    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)
                    for (idx in idxnames) {
                        ipi = idxstats[dbn,idx,"pagein"]
                        ipo = idxstats[dbn,idx,"pageout"]
                        # not every db will have every index
                        if (ipi != "" && ipo != "") {
                            printf fmtstr, "+", idxnames[idx], ipi, ipo
                        }
                    }
                }
            }
        }
        '
}

dodbmon() {
    initfile=$(get_init_file "/etc/default" $SERVID)
    if [ $? -eq 1 ]
    then
        echo "You must supply a valid server instance identifier (via SERVID)."
        echo "Available instances: $initfile"
        exit 1
    fi

    . $initfile

    process_dse $CONFIG_DIR $$
    file="/tmp/DSSharedLib.$$"
    port=$(grep -i 'nsslapd-port' $file | awk '{print $2}' )
    host=$(grep -i 'nsslapd-localhost' $file | awk '{print $2}' )
    security=$(grep -i 'nsslapd-security' $file | awk '{print $2}' )
    certdir=$(grep -i 'nsslapd-certdir' $file | awk '{print $2}' )
    rm $file

    if [ -n "$ldapiURL" ]
    then
        ldapiURL=`echo "$ldapiURL" | sed -e 's/\//%2f/g'`
        ldapiURL="ldapi://"$ldapiURL
    fi

    client_type=`ldapsearch -V 2>&1`;
    echo "$client_type" | grep -q "OpenLDAP"
    if  [ $? -eq 0 ]
    then
        openldap="yes"
        export LDAPTLS_CACERTDIR=$certdir
    fi

    if [ -z $security ]; then
        security="off"
    fi

    while [ 1 ] ; do
        date
        if [ "$security" = "on" ]; then
            # STARTTLS
	    if [ "$openldap" = "yes" ]; then
	        ldapsearch -x -LLL -ZZ -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
                | parseldif
	    else
	        ldapsearch -ZZZ -P $certdir  -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
                | parseldif
	    fi
        else
            # LDAP
            if [ "$openldap" = "yes" ]; then
	        ldapsearch -x -LLL -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
                | parseldif
            else
	        ldapsearch -h $host -p $port -D "$BINDDN" -w "$BINDPW" -b "$ldbmdn" '(|(cn=config)(cn=database)(cn=monitor))' \
                | parseldif
            fi
        fi
        echo ""
        sleep $INCR
    done
}

dodbmon