001/*
002 * Copyright 2008-2018 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright (C) 2015-2018 Ping Identity Corporation
007 *
008 * This program is free software; you can redistribute it and/or modify
009 * it under the terms of the GNU General Public License (GPLv2 only)
010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
011 * as published by the Free Software Foundation.
012 *
013 * This program is distributed in the hope that it will be useful,
014 * but WITHOUT ANY WARRANTY; without even the implied warranty of
015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016 * GNU General Public License for more details.
017 *
018 * You should have received a copy of the GNU General Public License
019 * along with this program; if not, see <http://www.gnu.org/licenses>.
020 */
021package com.unboundid.ldap.sdk.unboundidds.monitors;
022
023
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.Date;
028import java.util.LinkedHashMap;
029import java.util.Map;
030
031import com.unboundid.ldap.sdk.Attribute;
032import com.unboundid.ldap.sdk.Entry;
033import com.unboundid.util.NotMutable;
034import com.unboundid.util.ThreadSafety;
035import com.unboundid.util.ThreadSafetyLevel;
036
037import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*;
038import static com.unboundid.util.StaticUtils.*;
039
040
041
042/**
043 * This class defines a monitor entry that provides basic information about the
044 * Berkeley DB Java Edition environment in use for a backend.
045 * <BR>
046 * <BLOCKQUOTE>
047 *   <B>NOTE:</B>  This class, and other classes within the
048 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
049 *   supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661
050 *   server products.  These classes provide support for proprietary
051 *   functionality or for external specifications that are not considered stable
052 *   or mature enough to be guaranteed to work in an interoperable way with
053 *   other types of LDAP servers.
054 * </BLOCKQUOTE>
055 * <BR>
056 * The information that is provided includes:
057 * <UL>
058 *   <LI>The backend ID for the associated backend.</LI>
059 *   <LI>The version string for the Berkeley DB Java Edition library.</LI>
060 *   <LI>The path to the directory containing the database environment
061 *       files.</LI>
062 *   <LI>The amount of space consumed by the database files.</LI>
063 *   <LI>The amount of memory currently consumed by the database cache.</LI>
064 *   <LI>The maximum amount of memory that may be consumed by the database
065 *       cache.</LI>
066 *   <LI>The percent of the total memory allowed for the database cache that is
067 *       currently in use.</LI>
068 *   <LI>Whether a checkpoint is currently in progress.</LI>
069 *   <LI>The total number of checkpoints that have been completed.</LI>
070 *   <LI>The time that the last completed checkpoint began.</LI>
071 *   <LI>The time that the last completed checkpoint ended.</LI>
072 *   <LI>The total duration of all checkpoints completed.</LI>
073 *   <LI>The average duration of all checkpoints completed.</LI>
074 *   <LI>The duration of the last checkpoint completed.</LI>
075 *   <LI>The length of time since the last checkpoint.</LI>
076 *   <LI>The number of log files that the cleaner needs to examine.</LI>
077 *   <LI>The number of nodes evicted from the database cache.</LI>
078 *   <LI>The number of random-access disk reads performed.</LI>
079 *   <LI>The number of random-access disk writes performed.</LI>
080 *   <LI>The number of sequential disk reads performed.</LI>
081 *   <LI>The number of sequential disk writes performed.</LI>
082 *   <LI>The number of active transactions in the database environment.</LI>
083 *   <LI>The number of read locks held in the database environment.</LI>
084 *   <LI>The number of write locks held in the database environment.</LI>
085 *   <LI>The number of transactions waiting on locks.</LI>
086 *   <LI>A set of generic statistics about the database environment.</LI>
087 *   <LI>A set of generic statistics about the lock subsystem for the database
088 *       environment.</LI>
089 *   <LI>A set of generic statistics about the transaction subsystem for the
090 *       database environment.</LI>
091 * </UL>
092 * The JE environment monitor entries provided by the server can be
093 * retrieved using the {@link MonitorManager#getJEEnvironmentMonitorEntries}
094 * method.  These entries provide specific methods for accessing information
095 * about the JE environment (e.g., the
096 * {@link JEEnvironmentMonitorEntry#getJEVersion} method can be used to retrieve
097 * the Berkeley DB JE version).  Alternately, this information may be accessed
098 * using the generic API.  See the {@link MonitorManager} class documentation
099 * for an example that demonstrates the use of the generic API for accessing
100 * monitor data.
101 */
102@NotMutable()
103@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
104public final class JEEnvironmentMonitorEntry
105       extends MonitorEntry
106{
107  /**
108   * The structural object class used in JE environment monitor entries.
109   */
110  static final String JE_ENVIRONMENT_MONITOR_OC =
111       "ds-je-environment-monitor-entry";
112
113
114
115  /**
116   * The name of the attribute that contains the number of active transactions.
117   */
118  private static final String ATTR_ACTIVE_TXNS = "active-transaction-count";
119
120
121
122  /**
123   * The name of the attribute that contains the average duration of the all
124   * checkpoints in milliseconds.
125   */
126  private static final String ATTR_AVERAGE_CHECKPOINT_DURATION_MILLIS =
127       "average-checkpoint-duration-millis";
128
129
130
131  /**
132   * The name of the attribute that contains the backend ID for the associated
133   * backend.
134   */
135  private static final String ATTR_BACKEND_ID = "backend-id";
136
137
138
139  /**
140   * The name of the attribute that contains the DB cache percent full.
141   */
142  private static final String ATTR_CACHE_PCT_FULL = "db-cache-percent-full";
143
144
145
146  /**
147   * The name of the attribute that indicates whether a checkpoint is currently
148   * in progress.
149   */
150  private static final String ATTR_CHECKPOINT_IN_PROGRESS =
151       "checkpoint-in-progress";
152
153
154
155  /**
156   * The name of the attribute that contains the cleaner backlog.
157   */
158  private static final String ATTR_CLEANER_BACKLOG = "cleaner-backlog";
159
160
161
162  /**
163   * The name of the attribute that contains the current DB cache size.
164   */
165  private static final String ATTR_CURRENT_CACHE_SIZE = "current-db-cache-size";
166
167
168
169  /**
170   * The name of the attribute that contains the path to the DB directory.
171   */
172  private static final String ATTR_DB_DIRECTORY = "db-directory";
173
174
175
176  /**
177   * The name of the attribute that contains the DB on-disk size.
178   */
179  private static final String ATTR_DB_ON_DISK_SIZE = "db-on-disk-size";
180
181
182
183  /**
184   * The name of the attribute that contains the Berkeley DB JE version string.
185   */
186  private static final String ATTR_JE_VERSION = "je-version";
187
188
189
190  /**
191   * The name of the attribute that contains the duration of the last checkpoint
192   * in milliseconds.
193   */
194  private static final String ATTR_LAST_CHECKPOINT_DURATION_MILLIS =
195       "last-checkpoint-duration-millis";
196
197
198
199  /**
200   * The name of the attribute that contains the time the last checkpoint began.
201   */
202  private static final String ATTR_LAST_CHECKPOINT_START_TIME =
203       "last-checkpoint-start-time";
204
205
206
207  /**
208   * The name of the attribute that contains the time the last checkpoint ended.
209   */
210  private static final String ATTR_LAST_CHECKPOINT_STOP_TIME =
211       "last-checkpoint-stop-time";
212
213
214
215  /**
216   * The name of the attribute that contains the time of the last checkpoint.
217   *
218   * @deprecated  Use {@link #ATTR_LAST_CHECKPOINT_STOP_TIME} instead.
219   */
220  @Deprecated()
221  private static final String ATTR_LAST_CHECKPOINT_TIME =
222       "last-checkpoint-time";
223
224
225
226  /**
227   * The name of the attribute that contains the maximum cache size.
228   */
229  private static final String ATTR_MAX_CACHE_SIZE = "max-db-cache-size";
230
231
232
233  /**
234   * The name of the attribute that contains the length of time in milliseconds
235   * since the last checkpoint.
236   */
237  private static final String ATTR_MILLIS_SINCE_LAST_CHECKPOINT =
238       "millis-since-last-checkpoint";
239
240
241
242  /**
243   * The name of the attribute that contains the number of nodes evicted from
244   * the cache.
245   */
246  private static final String ATTR_NODES_EVICTED = "nodes-evicted";
247
248
249
250  /**
251   * The name of the attribute that contains the number of checkpoints
252   * processed.
253   */
254  private static final String ATTR_NUM_CHECKPOINTS = "num-checkpoints";
255
256
257
258  /**
259   * The name of the attribute that contains the number of read locks held.
260   */
261  private static final String ATTR_NUM_READ_LOCKS = "read-locks-held";
262
263
264
265  /**
266   * The name of the attribute that contains the total duration of the all
267   * checkpoints in milliseconds.
268   */
269  private static final String ATTR_TOTAL_CHECKPOINT_DURATION_MILLIS =
270       "total-checkpoint-duration-millis";
271
272
273
274  /**
275   * The name of the attribute that contains the number of transactions waiting
276   * on locks.
277   */
278  private static final String ATTR_NUM_WAITING_TXNS =
279       "transactions-waiting-on-locks";
280
281
282
283  /**
284   * The name of the attribute that contains the number of write locks held.
285   */
286  private static final String ATTR_NUM_WRITE_LOCKS = "write-locks-held";
287
288
289
290  /**
291   * The name of the attribute that contains the number of random reads.
292   */
293  private static final String ATTR_RANDOM_READS = "random-read-count";
294
295
296
297  /**
298   * The name of the attribute that contains the number of random writes.
299   */
300  private static final String ATTR_RANDOM_WRITES = "random-write-count";
301
302
303
304  /**
305   * The name of the attribute that contains the number of sequential reads.
306   */
307  private static final String ATTR_SEQUENTIAL_READS = "sequential-read-count";
308
309
310
311  /**
312   * The name of the attribute that contains the number of sequential writes.
313   */
314  private static final String ATTR_SEQUENTIAL_WRITES = "sequential-write-count";
315
316
317
318  /**
319   * The prefix that will be used for attribute names that contain generic
320   * environment statistics.
321   */
322  private static final String ATTR_PREFIX_ENV_STAT = "je-env-stat-";
323
324
325
326  /**
327   * The prefix that will be used for attribute names that contain generic lock
328   * statistics.
329   */
330  private static final String ATTR_PREFIX_LOCK_STAT = "je-lock-stat-";
331
332
333
334  /**
335   * The prefix that will be used for attribute names that contain generic
336   * transaction statistics.
337   */
338  private static final String ATTR_PREFIX_TXN_STAT = "je-txn-stat-";
339
340
341
342  /**
343   * The name that will be used for the property that contains generic
344   * environment statistics.
345   */
346  private static final String PROPERTY_ENV_STATS = "je-env-stats";
347
348
349
350  /**
351   * The name that will be used for the property that contains generic lock
352   * statistics.
353   */
354  private static final String PROPERTY_LOCK_STATS = "je-lock-stats";
355
356
357
358  /**
359   * The name that will be used for the property that contains generic
360   * transaction statistics.
361   */
362  private static final String PROPERTY_TXN_STATS = "je-txn-stats";
363
364
365
366  /**
367   * The serial version UID for this serializable class.
368   */
369  private static final long serialVersionUID = 2557783119454069632L;
370
371
372
373  // Indicates whether a checkpoint is currently in progress.
374  private final Boolean checkpointInProgress;
375
376  // The time the last checkpoint began.
377  private final Date lastCheckpointStartTime;
378
379  // The time the last checkpoint ended.
380  private final Date lastCheckpointStopTime;
381
382  /**
383   * The time the last checkpoint ended.
384   *
385   * @deprecated  Use lastCheckpointStopTime instead.
386   */
387  @Deprecated
388  private final Date lastCheckpointTime;
389
390  // The number of active transactions.
391  private final Long activeTransactionCount;
392
393  // The average duration for all checkpoints.
394  private final Long averageCheckpointDurationMillis;
395
396  // The current cleaner backlog.
397  private final Long cleanerBacklog;
398
399  // The current DB cache size.
400  private final Long currentDBCacheSize;
401
402  // The current DB cache percent full.
403  private final Long dbCachePercentFull;
404
405  // The current DB on-disk size.
406  private final Long dbOnDiskSize;
407
408  // The duration for the last checkpoint.
409  private final Long lastCheckpointDurationMillis;
410
411  // The maximum allowed DB cache size.
412  private final Long maxDBCacheSize;
413
414  // The length of time since the last checkpoint.
415  private final Long millisSinceLastCheckpoint;
416
417  // The number of nodes evicted from the DB cache.
418  private final Long nodesEvicted;
419
420  // The number of checkpoints completed.
421  private final Long numCheckpoints;
422
423  // The number of random reads performed.
424  private final Long randomReads;
425
426  // The number of random writes performed.
427  private final Long randomWrites;
428
429  // The number of read locks held.
430  private final Long readLocksHeld;
431
432  // The number of sequential reads performed.
433  private final Long sequentialReads;
434
435  // The number of sequential writes performed.
436  private final Long sequentialWrites;
437
438  // The total duration for all checkpoints.
439  private final Long totalCheckpointDurationMillis;
440
441  // The number of transactions waiting on locks.
442  private final Long transactionsWaitingOnLocks;
443
444  // The number of write locks held.
445  private final Long writeLocksHeld;
446
447  // The set of generic environment statistics.
448  private final Map<String,String> envStats;
449
450  // The set of generic lock statistics.
451  private final Map<String,String> lockStats;
452
453  // The set of generic transaction statistics.
454  private final Map<String,String> txnStats;
455
456  // The backend ID for the associated backend.
457  private final String backendID;
458
459  // The path to the directory containing the database files.
460  private final String dbDirectory;
461
462  // The Berkeley DB JE version string.
463  private final String jeVersion;
464
465
466
467  /**
468   * Creates a new JE environment monitor entry from the provided entry.
469   *
470   * @param  entry  The entry to be parsed as a JE environment monitor entry.
471   *                It must not be {@code null}.
472   */
473  @SuppressWarnings("deprecation")
474  public JEEnvironmentMonitorEntry(final Entry entry)
475  {
476    super(entry);
477
478    activeTransactionCount     = getLong(ATTR_ACTIVE_TXNS);
479    cleanerBacklog             = getLong(ATTR_CLEANER_BACKLOG);
480    currentDBCacheSize         = getLong(ATTR_CURRENT_CACHE_SIZE);
481    dbCachePercentFull         = getLong(ATTR_CACHE_PCT_FULL);
482    dbOnDiskSize               = getLong(ATTR_DB_ON_DISK_SIZE);
483    maxDBCacheSize             = getLong(ATTR_MAX_CACHE_SIZE);
484    nodesEvicted               = getLong(ATTR_NODES_EVICTED);
485    randomReads                = getLong(ATTR_RANDOM_READS);
486    randomWrites               = getLong(ATTR_RANDOM_WRITES);
487    readLocksHeld              = getLong(ATTR_NUM_READ_LOCKS);
488    sequentialReads            = getLong(ATTR_SEQUENTIAL_READS);
489    sequentialWrites           = getLong(ATTR_SEQUENTIAL_WRITES);
490    transactionsWaitingOnLocks = getLong(ATTR_NUM_WAITING_TXNS);
491    writeLocksHeld             = getLong(ATTR_NUM_WRITE_LOCKS);
492    backendID                  = getString(ATTR_BACKEND_ID);
493    dbDirectory                = getString(ATTR_DB_DIRECTORY);
494    jeVersion                  = getString(ATTR_JE_VERSION);
495
496    checkpointInProgress = getBoolean(ATTR_CHECKPOINT_IN_PROGRESS);
497    lastCheckpointStartTime = getDate(ATTR_LAST_CHECKPOINT_START_TIME);
498    lastCheckpointStopTime = getDate(ATTR_LAST_CHECKPOINT_STOP_TIME);
499    lastCheckpointTime = getDate(ATTR_LAST_CHECKPOINT_TIME);
500    averageCheckpointDurationMillis  =
501         getLong(ATTR_AVERAGE_CHECKPOINT_DURATION_MILLIS);
502    lastCheckpointDurationMillis =
503         getLong(ATTR_LAST_CHECKPOINT_DURATION_MILLIS);
504    millisSinceLastCheckpoint = getLong(ATTR_MILLIS_SINCE_LAST_CHECKPOINT);
505    numCheckpoints = getLong(ATTR_NUM_CHECKPOINTS);
506    totalCheckpointDurationMillis =
507         getLong(ATTR_TOTAL_CHECKPOINT_DURATION_MILLIS);
508
509    final LinkedHashMap<String,String> tmpEnvStats =
510         new LinkedHashMap<String,String>();
511    final LinkedHashMap<String,String> tmpLockStats =
512         new LinkedHashMap<String,String>();
513    final LinkedHashMap<String,String> tmpTxnStats =
514         new LinkedHashMap<String,String>();
515    for (final Attribute a : entry.getAttributes())
516    {
517      final String name = toLowerCase(a.getName());
518      if (name.startsWith(ATTR_PREFIX_ENV_STAT))
519      {
520        tmpEnvStats.put(
521             toLowerCase(name.substring(ATTR_PREFIX_ENV_STAT.length())),
522             a.getValue());
523      }
524      else if (name.startsWith(ATTR_PREFIX_LOCK_STAT))
525      {
526        tmpLockStats.put(
527             toLowerCase(name.substring(ATTR_PREFIX_LOCK_STAT.length())),
528             a.getValue());
529      }
530      else if (name.startsWith(ATTR_PREFIX_TXN_STAT))
531      {
532        tmpTxnStats.put(
533             toLowerCase(name.substring(ATTR_PREFIX_TXN_STAT.length())),
534             a.getValue());
535      }
536    }
537
538    envStats  = Collections.unmodifiableMap(tmpEnvStats);
539    lockStats = Collections.unmodifiableMap(tmpLockStats);
540    txnStats  = Collections.unmodifiableMap(tmpTxnStats);
541  }
542
543
544
545  /**
546   * Retrieves the backend ID for the backend with which the Berkeley DB JE
547   * database is associated.
548   *
549   * @return  The backend ID for the backend with which the Berkeley DB JE
550   *          database is associated.
551   */
552  public String getBackendID()
553  {
554    return backendID;
555  }
556
557
558
559  /**
560   * Retrieves the Berkeley DB JE version string for the database environment
561   * of the associated backend.
562   *
563   * @return  The Berkeley DB JE version string for the database environment of
564   *          the associated backend, or {@code null} if it was not included in
565   *          the monitor entry.
566   */
567  public String getJEVersion()
568  {
569    return jeVersion;
570  }
571
572
573
574  /**
575   * Retrieves the path to the directory containing the database files.
576   *
577   * @return  The path to the directory containing the database files, or
578   *          {@code null} if it was not included in the monitor entry.
579   */
580  public String getDBDirectory()
581  {
582    return dbDirectory;
583  }
584
585
586
587  /**
588   * Retrieves the amount of disk space in bytes consumed by the database files.
589   *
590   * @return  The amount of disk space in bytes consumed by the database files,
591   *          or {@code null} if it was not included in the monitor entry.
592   */
593  public Long getDBOnDiskSize()
594  {
595    return dbOnDiskSize;
596  }
597
598
599
600  /**
601   * Retrieves the amount of memory in bytes currently consumed by the database
602   * cache.
603   *
604   * @return  The amount of memory in bytes currently consumed by the database
605   *          cache, or {@code null} if it was not included in the monitor
606   *          entry.
607   */
608  public Long getCurrentDBCacheSize()
609  {
610    return currentDBCacheSize;
611  }
612
613
614
615  /**
616   * Retrieves the maximum amount of memory in bytes that may be consumed by the
617   * database cache.
618   *
619   * @return  The maximum of memory in bytes that may be consumed by the
620   *          database cache, or {@code null} if it was not included in the
621   *          monitor entry.
622   */
623  public Long getMaxDBCacheSize()
624  {
625    return maxDBCacheSize;
626  }
627
628
629
630  /**
631   * Retrieves the percentage of the maximum database cache size that is
632   * currently in use.
633   *
634   * @return  The percentage of the maximum database cache size that is
635   *          currently in use, or {@code null} if it was not included in the
636   *          monitor entry.
637   */
638  public Long getDBCachePercentFull()
639  {
640    return dbCachePercentFull;
641  }
642
643
644
645  /**
646   * Indicates whether a checkpoint is currently in progress in the associated
647   * backend.
648   *
649   * @return  A {@code Boolean} value indicating whether a checkpoint is
650   *          currently in progress in the associated backend, or {@code null}
651   *          if it was not included in the monitor entry.
652   */
653  public Boolean checkpointInProgress()
654  {
655    return checkpointInProgress;
656  }
657
658
659
660  /**
661   * Retrieves the number of checkpoints completed in the associated backend.
662   *
663   * @return  The number of checkpoints completed in the associated backend, or
664   *          {@code null} if it was not included in the monitor entry.
665   */
666  public Long getNumCheckpoints()
667  {
668    return numCheckpoints;
669  }
670
671
672
673  /**
674   * Retrieves the total duration in milliseconds of all checkpoints completed
675   * in the associated backend.
676   *
677   * @return  The total duration in milliseconds of all checkpoints completed in
678   *          the associated backend, or {@code null} if it was not included in
679   *          the monitor entry.
680   */
681  public Long getTotalCheckpointDurationMillis()
682  {
683    return totalCheckpointDurationMillis;
684  }
685
686
687
688  /**
689   * Retrieves the average duration in milliseconds of all checkpoints completed
690   * in the associated backend.
691   *
692   * @return  The average duration in milliseconds of all checkpoints completed
693   *          in the associated backend, or {@code null} if it was not included
694   *          in the monitor entry.
695   */
696  public Long getAverageCheckpointDurationMillis()
697  {
698    return averageCheckpointDurationMillis;
699  }
700
701
702
703  /**
704   * Retrieves the duration in milliseconds of the last checkpoint completed in
705   * the associated backend.
706   *
707   * @return  The duration in milliseconds of the last checkpoint completed in
708   *          the associated backend, or {@code null} if it was not included
709   *          in the monitor entry.
710   */
711  public Long getLastCheckpointDurationMillis()
712  {
713    return lastCheckpointDurationMillis;
714  }
715
716
717
718  /**
719   * Retrieves the time that the last completed checkpoint began.
720   *
721   * @return  The time that the last completed checkpoint began, or {@code null}
722   *          if it was not included in the monitor entry.
723   */
724  public Date getLastCheckpointStartTime()
725  {
726    return lastCheckpointStartTime;
727  }
728
729
730
731  /**
732   * Retrieves the time that the last completed checkpoint ended.
733   *
734   * @return  The time that the last completed checkpoint ended, or {@code null}
735   *          if it was not included in the monitor entry.
736   */
737  public Date getLastCheckpointStopTime()
738  {
739    return lastCheckpointStopTime;
740  }
741
742
743
744  /**
745   * Retrieves the time that the last checkpoint occurred.
746   *
747   * @return  The time that the last checkpoint occurred, or {@code null} if it
748   *          was not included in the monitor entry.
749   *
750   * @deprecated  Use {@link #getLastCheckpointStopTime()} instead.
751   */
752  @Deprecated()
753  @SuppressWarnings("deprecation")
754  public Date getLastCheckpointTime()
755  {
756    return lastCheckpointTime;
757  }
758
759
760
761  /**
762   * Retrieves the length of time in milliseconds since the last completed
763   * checkpoint.
764   *
765   * @return  The length of time in milliseconds since the last completed
766   *          checkpoint, or {@code null} if it was not included in the monitor
767   *          entry.
768   */
769  public Long getMillisSinceLastCheckpoint()
770  {
771    return millisSinceLastCheckpoint;
772  }
773
774
775
776  /**
777   * Retrieves the number of log files that the cleaner needs to examine.
778   *
779   * @return  The number of log files that the cleaner needs to examine, or
780   *          {@code null} if it was not included in the monitor entry.
781   */
782  public Long getCleanerBacklog()
783  {
784    return cleanerBacklog;
785  }
786
787
788
789  /**
790   * Retrieves the number of nodes that have been evicted from the database
791   * cache since the backend was started.
792   *
793   * @return  The number of nodes that have been evicted from the database cache
794   *          since the backend was started, or {@code null} if it was not
795   *          included in the monitor entry.
796   */
797  public Long getNodesEvicted()
798  {
799    return nodesEvicted;
800  }
801
802
803
804  /**
805   * Retrieves the number of random-access disk reads performed since the
806   * backend was started.
807   *
808   * @return  The number of random-access disk reads performed since the backend
809   *          was started, or {@code null} if it was not included in the monitor
810   *          entry.
811   */
812  public Long getRandomReads()
813  {
814    return randomReads;
815  }
816
817
818
819  /**
820   * Retrieves the number of random-access disk writes performed since the
821   * backend was started.
822   *
823   * @return  The number of random-access disk writes performed since the
824   *          backend was started, or {@code null} if it was not included in the
825   *          monitor entry.
826   */
827  public Long getRandomWrites()
828  {
829    return randomWrites;
830  }
831
832
833
834  /**
835   * Retrieves the number of sequential disk reads performed since the backend
836   * was started.
837   *
838   * @return  The number of sequential disk reads performed since the backend
839   *          was started, or {@code null} if it was not included in the monitor
840   *          entry.
841   */
842  public Long getSequentialReads()
843  {
844    return sequentialReads;
845  }
846
847
848
849  /**
850   * Retrieves the number of sequential disk writes performed since the backend
851   * was started.
852   *
853   * @return  The number of sequential disk writes performed since the backend
854   *          was started, or {@code null} if it was not included in the monitor
855   *          entry.
856   */
857  public Long getSequentialWrites()
858  {
859    return sequentialWrites;
860  }
861
862
863
864  /**
865   * Retrieves the number of active transactions in the JE database environment.
866   *
867   * @return  The number of active transactions in the JE database environment,
868   *          or {@code null} if it was not included in the monitor entry.
869   */
870  public Long getActiveTransactionCount()
871  {
872    return activeTransactionCount;
873  }
874
875
876
877  /**
878   * Retrieves the number of read locks held in the JE database environment.
879   *
880   * @return  The number of read locks held in the JE database environment, or
881   *          {@code null} if it was not included in the monitor entry.
882   */
883  public Long getReadLocksHeld()
884  {
885    return readLocksHeld;
886  }
887
888
889
890  /**
891   * Retrieves the number of write locks held in the JE database environment.
892   *
893   * @return  The number of write locks held in the JE database environment, or
894   *          {@code null} if it was not included in the monitor entry.
895   */
896  public Long getWriteLocksHeld()
897  {
898    return writeLocksHeld;
899  }
900
901
902
903  /**
904   * Retrieves the number of transactions currently waiting on a lock in the
905   * database environment.
906   *
907   * @return  The number of transactions currently waiting on a lock in the
908   *          database environment, or {@code null} if it was not included in
909   *          the monitor entry.
910   */
911  public Long getTransactionsWaitingOnLocks()
912  {
913    return transactionsWaitingOnLocks;
914  }
915
916
917
918  /**
919   * Retrieves a set of general environment statistics for the database
920   * environment, mapped from the statistic name to the string representation of
921   * its value.  The statistic names will be formatted in all lowercase
922   * characters.
923   *
924   * @return  A set of general environment statistics for the database
925   *          environment, mapped from the statistic name to the string
926   *          representation of its value.
927   */
928  public Map<String,String> getEnvironmentStats()
929  {
930    return envStats;
931  }
932
933
934
935  /**
936   * Retrieves the string representation of the value for a database environment
937   * statistic.
938   *
939   * @param  statName  The name of the statistic to retrieve.  It will be
940   *                   treated in a case-insensitive manner.
941   *
942   * @return  The value of the requested database environment statistic, or
943   *          {@code null} if no such statistic was provided.
944   */
945  public String getEnvironmentStat(final String statName)
946  {
947    return envStats.get(toLowerCase(statName));
948  }
949
950
951
952  /**
953   * Retrieves a set of lock statistics for the database environment, mapped
954   * from the statistic name to the string representation of its value.  The
955   * statistic names will be formatted in all lowercase characters.
956   *
957   * @return  A set of lock statistics for the database environment, mapped from
958   *          the statistic name to the string representation of its value.
959   */
960  public Map<String,String> getLockStats()
961  {
962    return lockStats;
963  }
964
965
966
967  /**
968   * Retrieves the string representation of the value for a database environment
969   * lock statistic.
970   *
971   * @param  statName  The name of the statistic to retrieve.  It will be
972   *                   treated in a case-insensitive manner.
973   *
974   * @return  The value of the requested database environment lock statistic, or
975   *          {@code null} if no such statistic was provided.
976   */
977  public String getLockStat(final String statName)
978  {
979    return lockStats.get(toLowerCase(statName));
980  }
981
982
983
984  /**
985   * Retrieves a set of transaction statistics for the database environment,
986   * mapped from the statistic name to the string representation of its value.
987   * The statistic names will be formatted in all lowercase characters.
988   *
989   * @return  A set of transaction statistics for the database environment,
990   *          mapped from the statistic name to the string representation of its
991   *          value.
992   */
993  public Map<String,String> getTransactionStats()
994  {
995    return txnStats;
996  }
997
998
999
1000  /**
1001   * Retrieves the string representation of the value for a database environment
1002   * transaction statistic.
1003   *
1004   * @param  statName  The name of the statistic to retrieve.  It will be
1005   *                   treated in a case-insensitive manner.
1006   *
1007   * @return  The value of the requested database environment transaction
1008   *          statistic, or {@code null} if no such statistic was provided.
1009   */
1010  public String getTransactionStat(final String statName)
1011  {
1012    return txnStats.get(toLowerCase(statName));
1013  }
1014
1015
1016
1017  /**
1018   * {@inheritDoc}
1019   */
1020  @Override()
1021  public String getMonitorDisplayName()
1022  {
1023    return INFO_JE_ENVIRONMENT_MONITOR_DISPNAME.get();
1024  }
1025
1026
1027
1028  /**
1029   * {@inheritDoc}
1030   */
1031  @Override()
1032  public String getMonitorDescription()
1033  {
1034    return INFO_JE_ENVIRONMENT_MONITOR_DESC.get();
1035  }
1036
1037
1038
1039  /**
1040   * {@inheritDoc}
1041   */
1042  @Override()
1043  public Map<String,MonitorAttribute> getMonitorAttributes()
1044  {
1045    final LinkedHashMap<String,MonitorAttribute> attrs =
1046         new LinkedHashMap<String,MonitorAttribute>();
1047
1048    if (backendID != null)
1049    {
1050      addMonitorAttribute(attrs,
1051           ATTR_BACKEND_ID,
1052           INFO_JE_ENVIRONMENT_DISPNAME_BACKEND_ID.get(),
1053           INFO_JE_ENVIRONMENT_DESC_BACKEND_ID.get(),
1054           backendID);
1055    }
1056
1057    if (jeVersion != null)
1058    {
1059      addMonitorAttribute(attrs,
1060           ATTR_JE_VERSION,
1061           INFO_JE_ENVIRONMENT_DISPNAME_JE_VERSION.get(),
1062           INFO_JE_ENVIRONMENT_DESC_JE_VERSION.get(),
1063           jeVersion);
1064    }
1065
1066    if (dbDirectory != null)
1067    {
1068      addMonitorAttribute(attrs,
1069           ATTR_DB_DIRECTORY,
1070           INFO_JE_ENVIRONMENT_DISPNAME_DB_DIRECTORY.get(),
1071           INFO_JE_ENVIRONMENT_DESC_DB_DIRECTORY.get(),
1072           dbDirectory);
1073    }
1074
1075    if (dbOnDiskSize != null)
1076    {
1077      addMonitorAttribute(attrs,
1078           ATTR_DB_ON_DISK_SIZE,
1079           INFO_JE_ENVIRONMENT_DISPNAME_DB_ON_DISK_SIZE.get(),
1080           INFO_JE_ENVIRONMENT_DESC_DB_ON_DISK_SIZE.get(),
1081           dbOnDiskSize);
1082    }
1083
1084    if (currentDBCacheSize != null)
1085    {
1086      addMonitorAttribute(attrs,
1087           ATTR_CURRENT_CACHE_SIZE,
1088           INFO_JE_ENVIRONMENT_DISPNAME_CURRENT_CACHE_SIZE.get(),
1089           INFO_JE_ENVIRONMENT_DESC_CURRENT_CACHE_SIZE.get(),
1090           currentDBCacheSize);
1091    }
1092
1093    if (maxDBCacheSize != null)
1094    {
1095      addMonitorAttribute(attrs,
1096           ATTR_MAX_CACHE_SIZE,
1097           INFO_JE_ENVIRONMENT_DISPNAME_MAX_CACHE_SIZE.get(),
1098           INFO_JE_ENVIRONMENT_DESC_MAX_CACHE_SIZE.get(),
1099           maxDBCacheSize);
1100    }
1101
1102    if (dbCachePercentFull != null)
1103    {
1104      addMonitorAttribute(attrs,
1105           ATTR_CACHE_PCT_FULL,
1106           INFO_JE_ENVIRONMENT_DISPNAME_CACHE_PCT_FULL.get(),
1107           INFO_JE_ENVIRONMENT_DESC_CACHE_PCT_FULL.get(),
1108           dbCachePercentFull);
1109    }
1110
1111    if (checkpointInProgress != null)
1112    {
1113      addMonitorAttribute(attrs,
1114           ATTR_CHECKPOINT_IN_PROGRESS,
1115           INFO_JE_ENVIRONMENT_DISPNAME_CP_IN_PROGRESS.get(),
1116           INFO_JE_ENVIRONMENT_DESC_CP_IN_PROGRESS.get(),
1117           checkpointInProgress);
1118    }
1119
1120    if (numCheckpoints != null)
1121    {
1122      addMonitorAttribute(attrs,
1123           ATTR_NUM_CHECKPOINTS,
1124           INFO_JE_ENVIRONMENT_DISPNAME_NUM_CP.get(),
1125           INFO_JE_ENVIRONMENT_DESC_NUM_CP.get(),
1126           numCheckpoints);
1127    }
1128
1129    if (totalCheckpointDurationMillis != null)
1130    {
1131      addMonitorAttribute(attrs,
1132           ATTR_TOTAL_CHECKPOINT_DURATION_MILLIS,
1133           INFO_JE_ENVIRONMENT_DISPNAME_TOTAL_CP_DURATION.get(),
1134           INFO_JE_ENVIRONMENT_DESC_TOTAL_CP_DURATION.get(),
1135           totalCheckpointDurationMillis);
1136    }
1137
1138    if (averageCheckpointDurationMillis != null)
1139    {
1140      addMonitorAttribute(attrs,
1141           ATTR_AVERAGE_CHECKPOINT_DURATION_MILLIS,
1142           INFO_JE_ENVIRONMENT_DISPNAME_AVG_CP_DURATION.get(),
1143           INFO_JE_ENVIRONMENT_DESC_AVG_CP_DURATION.get(),
1144           averageCheckpointDurationMillis);
1145    }
1146
1147    if (lastCheckpointDurationMillis != null)
1148    {
1149      addMonitorAttribute(attrs,
1150           ATTR_LAST_CHECKPOINT_DURATION_MILLIS,
1151           INFO_JE_ENVIRONMENT_DISPNAME_LAST_CP_DURATION.get(),
1152           INFO_JE_ENVIRONMENT_DESC_LAST_CP_DURATION.get(),
1153           lastCheckpointDurationMillis);
1154    }
1155
1156    if (lastCheckpointStartTime != null)
1157    {
1158      addMonitorAttribute(attrs,
1159           ATTR_LAST_CHECKPOINT_START_TIME,
1160           INFO_JE_ENVIRONMENT_DISPNAME_LAST_CP_START_TIME.get(),
1161           INFO_JE_ENVIRONMENT_DESC_LAST_CP_START_TIME.get(),
1162           lastCheckpointStartTime);
1163    }
1164
1165    if (lastCheckpointStopTime != null)
1166    {
1167      addMonitorAttribute(attrs,
1168           ATTR_LAST_CHECKPOINT_STOP_TIME,
1169           INFO_JE_ENVIRONMENT_DISPNAME_LAST_CP_STOP_TIME.get(),
1170           INFO_JE_ENVIRONMENT_DESC_LAST_CP_STOP_TIME.get(),
1171           lastCheckpointStopTime);
1172    }
1173
1174    if (millisSinceLastCheckpoint != null)
1175    {
1176      addMonitorAttribute(attrs,
1177           ATTR_MILLIS_SINCE_LAST_CHECKPOINT,
1178           INFO_JE_ENVIRONMENT_DISPNAME_MILLIS_SINCE_CP.get(),
1179           INFO_JE_ENVIRONMENT_DESC_MILLIS_SINCE_CP.get(),
1180           millisSinceLastCheckpoint);
1181    }
1182
1183    if (cleanerBacklog != null)
1184    {
1185      addMonitorAttribute(attrs,
1186           ATTR_CLEANER_BACKLOG,
1187           INFO_JE_ENVIRONMENT_DISPNAME_CLEANER_BACKLOG.get(),
1188           INFO_JE_ENVIRONMENT_DESC_CLEANER_BACKLOG.get(),
1189           cleanerBacklog);
1190    }
1191
1192    if (nodesEvicted != null)
1193    {
1194      addMonitorAttribute(attrs,
1195           ATTR_NODES_EVICTED,
1196           INFO_JE_ENVIRONMENT_DISPNAME_NODES_EVICTED.get(),
1197           INFO_JE_ENVIRONMENT_DESC_NODES_EVICTED.get(),
1198           nodesEvicted);
1199    }
1200
1201    if (randomReads != null)
1202    {
1203      addMonitorAttribute(attrs,
1204           ATTR_RANDOM_READS,
1205           INFO_JE_ENVIRONMENT_DISPNAME_RANDOM_READS.get(),
1206           INFO_JE_ENVIRONMENT_DESC_RANDOM_READS.get(),
1207           randomReads);
1208    }
1209
1210    if (randomWrites != null)
1211    {
1212      addMonitorAttribute(attrs,
1213           ATTR_RANDOM_WRITES,
1214           INFO_JE_ENVIRONMENT_DISPNAME_RANDOM_WRITES.get(),
1215           INFO_JE_ENVIRONMENT_DESC_RANDOM_WRITES.get(),
1216           randomWrites);
1217    }
1218
1219    if (sequentialReads != null)
1220    {
1221      addMonitorAttribute(attrs,
1222           ATTR_SEQUENTIAL_READS,
1223           INFO_JE_ENVIRONMENT_DISPNAME_SEQUENTIAL_READS.get(),
1224           INFO_JE_ENVIRONMENT_DESC_SEQUENTIAL_READS.get(),
1225           sequentialReads);
1226    }
1227
1228    if (sequentialWrites != null)
1229    {
1230      addMonitorAttribute(attrs,
1231           ATTR_SEQUENTIAL_WRITES,
1232           INFO_JE_ENVIRONMENT_DISPNAME_SEQUENTIAL_WRITES.get(),
1233           INFO_JE_ENVIRONMENT_DESC_SEQUENTIAL_WRITES.get(),
1234           sequentialWrites);
1235    }
1236
1237    if (activeTransactionCount != null)
1238    {
1239      addMonitorAttribute(attrs,
1240           ATTR_ACTIVE_TXNS,
1241           INFO_JE_ENVIRONMENT_DISPNAME_ACTIVE_TXNS.get(),
1242           INFO_JE_ENVIRONMENT_DESC_ACTIVE_TXNS.get(),
1243           activeTransactionCount);
1244    }
1245
1246    if (readLocksHeld != null)
1247    {
1248      addMonitorAttribute(attrs,
1249           ATTR_NUM_READ_LOCKS,
1250           INFO_JE_ENVIRONMENT_DISPNAME_READ_LOCKS.get(),
1251           INFO_JE_ENVIRONMENT_DESC_READ_LOCKS.get(),
1252           readLocksHeld);
1253    }
1254
1255    if (writeLocksHeld != null)
1256    {
1257      addMonitorAttribute(attrs,
1258           ATTR_NUM_WRITE_LOCKS,
1259           INFO_JE_ENVIRONMENT_DISPNAME_WRITE_LOCKS.get(),
1260           INFO_JE_ENVIRONMENT_DESC_WRITE_LOCKS.get(),
1261           writeLocksHeld);
1262    }
1263
1264    if (transactionsWaitingOnLocks != null)
1265    {
1266      addMonitorAttribute(attrs,
1267           ATTR_NUM_WAITING_TXNS,
1268           INFO_JE_ENVIRONMENT_DISPNAME_TXNS_WAITING_ON_LOCKS.get(),
1269           INFO_JE_ENVIRONMENT_DESC_TXNS_WAITING_ON_LOCKS.get(),
1270           transactionsWaitingOnLocks);
1271    }
1272
1273    if (! envStats.isEmpty())
1274    {
1275      final ArrayList<String> values = new ArrayList<String>(envStats.size());
1276      for (final Map.Entry<String,String> e : envStats.entrySet())
1277      {
1278        values.add(e.getKey() + '=' + e.getValue());
1279      }
1280
1281      addMonitorAttribute(attrs,
1282           PROPERTY_ENV_STATS,
1283           INFO_JE_ENVIRONMENT_DISPNAME_ENV_STATS.get(),
1284           INFO_JE_ENVIRONMENT_DESC_ENV_STATS.get(),
1285           values);
1286    }
1287
1288    if (! lockStats.isEmpty())
1289    {
1290      final ArrayList<String> values = new ArrayList<String>(lockStats.size());
1291      for (final Map.Entry<String,String> e : lockStats.entrySet())
1292      {
1293        values.add(e.getKey() + '=' + e.getValue());
1294      }
1295
1296      addMonitorAttribute(attrs,
1297           PROPERTY_LOCK_STATS,
1298           INFO_JE_ENVIRONMENT_DISPNAME_LOCK_STATS.get(),
1299           INFO_JE_ENVIRONMENT_DESC_LOCK_STATS.get(),
1300           values);
1301    }
1302
1303    if (! txnStats.isEmpty())
1304    {
1305      final ArrayList<String> values = new ArrayList<String>(txnStats.size());
1306      for (final Map.Entry<String,String> e : txnStats.entrySet())
1307      {
1308        values.add(e.getKey() + '=' + e.getValue());
1309      }
1310
1311      addMonitorAttribute(attrs,
1312           PROPERTY_TXN_STATS,
1313           INFO_JE_ENVIRONMENT_DISPNAME_TXN_STATS.get(),
1314           INFO_JE_ENVIRONMENT_DESC_TXN_STATS.get(),
1315           values);
1316    }
1317
1318    return Collections.unmodifiableMap(attrs);
1319  }
1320}