001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2009 Sun Microsystems, Inc.
015 * Portions Copyright 2014-2015 ForgeRock AS.
016 */
017package org.opends.guitools.controlpanel.datamodel;
018
019import static org.opends.messages.AdminToolMessages.*;
020
021import org.forgerock.i18n.LocalizableMessage;
022import org.opends.server.monitors.TraditionalWorkQueueMonitor;
023import org.opends.server.util.ServerConstants;
024
025/**
026 * The enumeration containing the different monitoring attributes that can be
027 * displayed in the monitoring panels.
028 */
029public enum BasicMonitoringAttributes implements MonitoringAttributes
030{
031  /**
032   * Start Date.
033   */
034  START_DATE(LocalizableMessage.EMPTY, ServerConstants.ATTR_START_TIME),
035  /**
036   * Current Date.
037   */
038  CURRENT_DATE(LocalizableMessage.EMPTY, ServerConstants.ATTR_CURRENT_TIME),
039  /**
040   * Current Connections.
041   */
042  CURRENT_CONNECTIONS(LocalizableMessage.EMPTY, ServerConstants.ATTR_CURRENT_CONNS),
043  /**
044   * Maximum Connections.
045   */
046  MAX_CONNECTIONS(LocalizableMessage.EMPTY, ServerConstants.ATTR_MAX_CONNS),
047  /**
048   * Total Connections.
049   */
050  TOTAL_CONNECTIONS(LocalizableMessage.EMPTY, ServerConstants.ATTR_TOTAL_CONNS),
051  /**
052   * Average Request Backlog.
053   */
054  AVERAGE_REQUEST_BACKLOG(INFO_CTRL_PANEL_AVERAGE_REQUEST_BACKLOG.get(),
055  TraditionalWorkQueueMonitor.ATTR_AVERAGE_BACKLOG),
056  /**
057   * Max Request Backlog.
058   */
059  MAX_REQUEST_BACKLOG(INFO_CTRL_PANEL_MAX_REQUEST_BACKLOG.get(),
060  TraditionalWorkQueueMonitor.ATTR_MAX_BACKLOG),
061  /**
062   * Current Request Backlog.
063   */
064  CURRENT_REQUEST_BACKLOG(INFO_CTRL_PANEL_CURRENT_REQUEST_BACKLOG.get(),
065  TraditionalWorkQueueMonitor.ATTR_CURRENT_BACKLOG),
066  /**
067   * Requests submitted.
068   */
069  REQUESTS_SUBMITTED(INFO_CTRL_PANEL_REQUESTS_SUBMITTED.get(),
070  TraditionalWorkQueueMonitor.ATTR_OPS_SUBMITTED),
071  /**
072   * Requests rejected.
073   */
074  REQUESTS_REJECTED(INFO_CTRL_PANEL_REQUESTS_REJECTED.get(),
075  TraditionalWorkQueueMonitor.ATTR_OPS_REJECTED_QUEUE_FULL),
076  /**
077   * Entry cache Hits.
078   */
079  ENTRY_CACHE_HITS(INFO_CTRL_PANEL_ENTRY_CACHE_HITS.get(),
080  "entryCacheHits"),
081  /**
082   * Current entry cache count.
083   */
084  CURRENT_ENTRY_CACHE_COUNT(INFO_CTRL_PANEL_CURRENT_ENTRY_CACHE_COUNT.get(),
085  "currentEntryCacheCount"),
086  /**
087   * Entry cache tries.
088   */
089  ENTRY_CACHE_TRIES(INFO_CTRL_PANEL_ENTRY_CACHE_TRIES.get(),
090  "entryCacheTries"),
091  /**
092   * Entry cache hit ratio.
093   */
094  ENTRY_CACHE_HIT_RATIO(INFO_CTRL_PANEL_ENTRY_CACHE_HIT_RATIO.get(),
095  "entryCacheHitRatio"),
096  /**
097   * Entry cache current size.
098   */
099  CURRENT_ENTRY_CACHE_SIZE(INFO_CTRL_PANEL_CURRENT_ENTRY_CACHE_SIZE.get(),
100  "currentEntryCacheSize"),
101  /**
102   * Entry cache max size.
103   */
104  MAX_ENTRY_CACHE_SIZE(INFO_CTRL_PANEL_MAX_ENTRY_CACHE_SIZE.get(),
105  "maxEntryCacheSize"),
106  /**
107   * Entry cache max count.
108   */
109  MAX_ENTRY_CACHE_COUNT(INFO_CTRL_PANEL_MAX_ENTRY_CACHE_COUNT.get(),
110  "maxEntryCacheCount"),
111  /**
112   * Available CPUs.
113   */
114  AVAILABLE_CPUS(INFO_CTRL_PANEL_AVAILABLE_CPUS.get(),
115  "availableCPUs"),
116  /**
117   * System Name.
118   */
119  SYSTEM_NAME(INFO_CTRL_PANEL_SYSTEM_NAME.get(),
120  "systemName"),
121  /**
122   * Operating System.
123   */
124  OPERATING_SYSTEM(INFO_CTRL_PANEL_OPERATING_SYSTEM.get(),
125  "operatingSystem"),
126  /**
127   * Free used memory.
128   */
129  FREE_USED_MEMORY(INFO_CTRL_PANEL_FREE_USED_MEMORY.get(),
130  "freeUsedMemory"),
131  /**
132   * Max memory.
133   */
134  MAX_MEMORY(INFO_CTRL_PANEL_MAX_MEMORY.get(),
135  "maxMemory"),
136  /**
137   * Used memory.
138   */
139  USED_MEMORY(INFO_CTRL_PANEL_USED_MEMORY.get(),
140  "usedMemory"),
141  /**
142   * Class path.
143   */
144  CLASS_PATH(INFO_CTRL_PANEL_CLASS_PATH.get(),
145  "classPath"),
146  /**
147   * Java Vendor.
148   */
149  JAVA_VENDOR(INFO_CTRL_PANEL_JAVA_VENDOR.get(),
150  "javaVendor"),
151  /**
152   * JVM Vendor.
153   */
154  JVM_VENDOR(INFO_CTRL_PANEL_JVM_VENDOR.get(),
155  "javaVendor"),
156  /**
157   * Java Version.
158   */
159  JAVA_VERSION(INFO_CTRL_PANEL_JAVA_VERSION.get(),
160  "javaVersion"),
161  /**
162   * JVM Version.
163   */
164  JVM_VERSION(INFO_CTRL_PANEL_JVM_VERSION.get(),
165  "jvmVersion"),
166  /**
167   * JVM Architecture.
168   */
169  JVM_ARCHITECTURE(INFO_CTRL_PANEL_JVM_ARCHITECTURE.get(),
170  "jvmArchitecture"),
171  /**
172   * JVM Arguments.
173   */
174  JVM_ARGUMENTS(INFO_CTRL_PANEL_JVM_ARGUMENTS.get(),
175  "jvmArguments"),
176  /**
177   * Add Request.
178   */
179  ADD_REQUESTS(INFO_CTRL_PANEL_ADD_REQUESTS_LABEL.get(),
180  "addRequests"),
181  /**
182   * Add Responses.
183   */
184  ADD_RESPONSES(INFO_CTRL_PANEL_ADD_RESPONSES_LABEL.get(),
185  "addResponses"),
186  /**
187   * Bind Request.
188   */
189  BIND_REQUESTS(INFO_CTRL_PANEL_BIND_REQUESTS_LABEL.get(),
190  "bindRequests"),
191  /**
192   * Bind Responses.
193   */
194  BIND_RESPONSES(INFO_CTRL_PANEL_BIND_RESPONSES_LABEL.get(),
195  "bindResponses"),
196  /**
197   * Compare Requests.
198   */
199  COMPARE_REQUESTS(INFO_CTRL_PANEL_COMPARE_REQUESTS_LABEL.get(),
200  "compareRequests"),
201  /**
202   * Compare Responses.
203   */
204  COMPARE_RESPONSES(INFO_CTRL_PANEL_COMPARE_RESPONSES_LABEL.get(),
205  "compareResponses"),
206  /**
207   * Delete Request.
208   */
209  DELETE_REQUESTS(INFO_CTRL_PANEL_DELETE_REQUESTS_LABEL.get(),
210  "deleteRequests"),
211  /**
212   * Delete Responses.
213   */
214  DELETE_RESPONSES(INFO_CTRL_PANEL_DELETE_RESPONSES_LABEL.get(),
215  "deleteResponses"),
216  /**
217   * Extended Request.
218   */
219  EXTENDED_REQUESTS(INFO_CTRL_PANEL_EXTENDED_REQUESTS_LABEL.get(),
220  "extendedRequests"),
221  /**
222   * Extended Responses.
223   */
224  EXTENDED_RESPONSES(INFO_CTRL_PANEL_EXTENDED_RESPONSES_LABEL.get(),
225  "extendedResponses"),
226  /**
227   * Modify DN Request.
228   */
229  MOD_DN_REQUESTS(INFO_CTRL_PANEL_MOD_DN_REQUESTS_LABEL.get(),
230  "modifyDNRequests"),
231  /**
232   * Modify DN Responses.
233   */
234  MOD_DN_RESPONSES(INFO_CTRL_PANEL_MOD_DN_RESPONSES_LABEL.get(),
235  "modifyDNResponses"),
236  /**
237   * Modify Request.
238   */
239  MOD_REQUESTS(INFO_CTRL_PANEL_MOD_REQUESTS_LABEL.get(),
240  "modifyRequests"),
241  /**
242   * Modify Responses.
243   */
244  MOD_RESPONSES(INFO_CTRL_PANEL_MOD_RESPONSES_LABEL.get(),
245  "modifyResponses"),
246  /**
247   * Search Request.
248   */
249  SEARCH_REQUESTS(INFO_CTRL_PANEL_SEARCH_REQUESTS_LABEL.get(),
250  "searchRequests"),
251  /**
252   * Searches Done.
253   */
254  SEARCH_DONE(INFO_CTRL_PANEL_SEARCH_DONE_LABEL.get(),
255  "searchResultsDone"),
256  /**
257   * Unbind Request.
258   */
259  UNBIND_REQUESTS(INFO_CTRL_PANEL_UNBIND_REQUESTS_LABEL.get(),
260  "unbindRequests"),;
261
262  static
263  {
264    // Do this here, since static references do not work if this is done
265    // in the constructor.
266    for (BasicMonitoringAttributes attr : BasicMonitoringAttributes.values())
267    {
268      attr.calculateProperties();
269    }
270  }
271
272  private LocalizableMessage msg;
273  private String attributeName;
274  private boolean isAborted;
275  private boolean isNumeric;
276  private boolean isGMTDate;
277  private boolean isValueInBytes;
278  private boolean canHaveAverage;
279  private boolean isTime;
280
281  private BasicMonitoringAttributes(LocalizableMessage msg, String attributeName)
282  {
283    this.msg = msg;
284    this.attributeName = attributeName;
285  }
286
287  /** {@inheritDoc} */
288  public LocalizableMessage getMessage()
289  {
290    return msg;
291  }
292
293  /** {@inheritDoc} */
294  public String getAttributeName()
295  {
296    return attributeName;
297  }
298
299  /** {@inheritDoc} */
300  public boolean isAborted()
301  {
302    return isAborted;
303  }
304
305  /** {@inheritDoc} */
306  public boolean isNumeric()
307  {
308    return isNumeric;
309  }
310
311  /** {@inheritDoc} */
312  public boolean isTime()
313  {
314    return isTime;
315  }
316
317  /** {@inheritDoc} */
318  public boolean isGMTDate()
319  {
320    return isGMTDate;
321  }
322
323  /** {@inheritDoc} */
324  public boolean isValueInBytes()
325  {
326    return isValueInBytes;
327  }
328
329  /** {@inheritDoc} */
330  public boolean canHaveAverage()
331  {
332    return canHaveAverage;
333  }
334
335  /** {@inheritDoc} */
336  public boolean isNumericDate()
337  {
338    return false;
339  }
340
341  private void calculateProperties()
342  {
343    isAborted = attributeName.indexOf("ds-mon-aborted-") == 0;
344
345    canHaveAverage = attributeName.endsWith("total-count") ||
346    attributeName.endsWith("Requests") ||
347    attributeName.endsWith("Responses") ||
348    this == SEARCH_DONE;
349
350    isGMTDate = this == START_DATE ||
351    this == CURRENT_DATE;
352
353    isValueInBytes = this == FREE_USED_MEMORY ||
354    this == MAX_MEMORY ||
355    this == USED_MEMORY;
356
357    isTime = attributeName.contains("time");
358
359    isNumeric =
360    !isGMTDate() &&
361    this != SYSTEM_NAME &&
362    this != OPERATING_SYSTEM &&
363    this != CLASS_PATH &&
364    this != JAVA_VENDOR &&
365    this != JVM_VENDOR &&
366    this != JAVA_VERSION &&
367    this != JVM_VERSION &&
368    this != JVM_ARCHITECTURE &&
369    this != JVM_ARGUMENTS;
370  }
371}