001 /* 002 * Copyright 2014-2015 UnboundID Corp. 003 * All Rights Reserved. 004 */ 005 /* 006 * Copyright (C) 2015 UnboundID Corp. 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 */ 021 package com.unboundid.ldap.sdk.unboundidds.monitors; 022 023 024 025 import java.util.Collections; 026 import java.util.Date; 027 import java.util.LinkedHashMap; 028 import java.util.Map; 029 030 import com.unboundid.ldap.sdk.Entry; 031 import com.unboundid.util.NotMutable; 032 import com.unboundid.util.ThreadSafety; 033 import com.unboundid.util.ThreadSafetyLevel; 034 035 import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 036 037 038 039 /** 040 * <BLOCKQUOTE> 041 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID 042 * LDAP SDK for Java. It is not available for use in applications that 043 * include only the Standard Edition of the LDAP SDK, and is not supported for 044 * use in conjunction with non-UnboundID products. 045 * </BLOCKQUOTE> 046 * This class defines a monitor entry that provides information about the recent 047 * CPU and memory utilization of the underlying system. 048 */ 049 @NotMutable() 050 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 051 public final class HostSystemRecentCPUAndMemoryMonitorEntry 052 extends MonitorEntry 053 { 054 /** 055 * The structural object class used in host system recent CPU and memory 056 * monitor entries. 057 */ 058 static final String HOST_SYSTEM_RECENT_CPU_AND_MEMORY_MONITOR_OC = 059 "ds-host-system-cpu-memory-monitor-entry"; 060 061 062 063 /** 064 * The name of the attribute that contains the recent CPU idle percentage. 065 */ 066 private static final String ATTR_RECENT_CPU_IDLE = "recent-cpu-idle"; 067 068 069 070 /** 071 * The name of the attribute that contains the recent CPU I/O wait percentage. 072 */ 073 private static final String ATTR_RECENT_CPU_IOWAIT = "recent-cpu-iowait"; 074 075 076 077 /** 078 * The name of the attribute that contains the recent CPU system percentage. 079 */ 080 private static final String ATTR_RECENT_CPU_SYSTEM = "recent-cpu-system"; 081 082 083 084 /** 085 * The name of the attribute that contains the recent CPU total busy 086 * percentage. 087 */ 088 private static final String ATTR_RECENT_TOTAL_CPU_BUSY = "recent-cpu-used"; 089 090 091 092 /** 093 * The name of the attribute that contains the recent CPU user percentage. 094 */ 095 private static final String ATTR_RECENT_CPU_USER = "recent-cpu-user"; 096 097 098 099 /** 100 * The name of the attribute that contains the recent amount of free system 101 * memory, in gigabytes. 102 */ 103 private static final String ATTR_RECENT_MEMORY_FREE_GB = 104 "recent-memory-free-gb"; 105 106 107 108 /** 109 * The name of the attribute that contains the recent percent of system memory 110 * that is currently free. 111 */ 112 private static final String ATTR_RECENT_MEMORY_FREE_PCT = 113 "recent-memory-pct-free"; 114 115 116 117 /** 118 * The name of the attribute that contains the time the information was 119 * last updated. 120 */ 121 private static final String ATTR_TIMESTAMP = "timestamp"; 122 123 124 125 /** 126 * The name of the attribute that contains the total amount of system memory, 127 * in gigabytes. 128 */ 129 private static final String ATTR_TOTAL_MEMORY_GB = "total-memory-gb"; 130 131 132 133 /** 134 * The serial version UID for this serializable class. 135 */ 136 private static final long serialVersionUID = -4408434740529394905L; 137 138 139 140 // The time the CPU and memory usage information was last updated. 141 private final Date timestamp; 142 143 // The recent CPU idle percent. 144 private final Double recentCPUIdle; 145 146 // The recent CPU I/O wait percent. 147 private final Double recentCPUIOWait; 148 149 // The recent CPU system percent. 150 private final Double recentCPUSystem; 151 152 // The recent CPU total percent busy. 153 private final Double recentCPUTotalBusy; 154 155 // The recent CPU user percent. 156 private final Double recentCPUUser; 157 158 // The recent free memory, in gigabytes. 159 private final Double recentMemoryFreeGB; 160 161 // The recent free memory percent.. 162 private final Double recentMemoryPercentFree; 163 164 // The total amount of system memory, in gigabytes. 165 private final Double totalMemoryGB; 166 167 168 169 /** 170 * Creates a new host system recent CPU and memory monitor entry from the 171 * provided entry. 172 * 173 * @param entry The entry to be parsed as a host system recent CPU and 174 * memory monitor entry. It must not be {@code null}. 175 */ 176 public HostSystemRecentCPUAndMemoryMonitorEntry(final Entry entry) 177 { 178 super(entry); 179 180 timestamp = getDate(ATTR_TIMESTAMP); 181 recentCPUIdle = getDouble(ATTR_RECENT_CPU_IDLE); 182 recentCPUIOWait = getDouble(ATTR_RECENT_CPU_IOWAIT); 183 recentCPUSystem = getDouble(ATTR_RECENT_CPU_SYSTEM); 184 recentCPUUser = getDouble(ATTR_RECENT_CPU_USER); 185 recentCPUTotalBusy = getDouble(ATTR_RECENT_TOTAL_CPU_BUSY); 186 recentMemoryFreeGB = getDouble(ATTR_RECENT_MEMORY_FREE_GB); 187 recentMemoryPercentFree = getDouble(ATTR_RECENT_MEMORY_FREE_PCT); 188 totalMemoryGB = getDouble(ATTR_TOTAL_MEMORY_GB); 189 } 190 191 192 193 /** 194 * Retrieves the time that the CPU and memory utilization data was last 195 * updated, if available. 196 * 197 * @return The time that the CPU and system memory utilization data was 198 * last updated, or {@code null} if it was not included in the 199 * monitor entry. 200 */ 201 public Date getUpdateTime() 202 { 203 return timestamp; 204 } 205 206 207 208 /** 209 * Retrieves the total percentage of recent CPU time spent in user, system, or 210 * I/O wait states, if available. 211 * 212 * @return The total percentage of recent CPU time spent in user, system, or 213 * I/O wait states, or {@code null} if it was not included in the 214 * monitor entry. 215 */ 216 public Double getRecentCPUTotalBusyPercent() 217 { 218 return recentCPUTotalBusy; 219 } 220 221 222 223 /** 224 * Retrieves the percentage of recent CPU time spent in the user state, if 225 * available. 226 * 227 * @return The percentage of recent CPU time spent in the user state, or 228 * {@code null} if it was not included in the monitor entry. 229 */ 230 public Double getRecentCPUUserPercent() 231 { 232 return recentCPUUser; 233 } 234 235 236 237 /** 238 * Retrieves the percentage of recent CPU time spent in the system state, if 239 * available. 240 * 241 * @return The percentage of recent CPU time spent in the system state, or 242 * {@code null} if it was not included in the monitor entry. 243 */ 244 public Double getRecentCPUSystemPercent() 245 { 246 return recentCPUSystem; 247 } 248 249 250 251 /** 252 * Retrieves the percentage of recent CPU time spent in the I/O wait state, if 253 * available. 254 * 255 * @return The percentage of recent CPU time spent in the I/O wait state, or 256 * {@code null} if it was not included in the monitor entry. 257 */ 258 public Double getRecentCPUIOWaitPercent() 259 { 260 return recentCPUIOWait; 261 } 262 263 264 265 /** 266 * Retrieves the percentage of recent CPU idle time, if available. 267 * 268 * @return The percentage of recent CPU idle time, or {@code null} if it was 269 * not included in the monitor entry. 270 */ 271 public Double getRecentCPUIdlePercent() 272 { 273 return recentCPUIdle; 274 } 275 276 277 278 /** 279 * Retrieves the total amount of system memory in gigabytes, if available. 280 * 281 * @return The total amount of system memory in gigabytes, or {@code null} if 282 * it was not included in the monitor entry. 283 */ 284 public Double getTotalSystemMemoryGB() 285 { 286 return totalMemoryGB; 287 } 288 289 290 291 /** 292 * Retrieves the recent amount of free system memory in gigabytes, if 293 * available. 294 * 295 * @return The recent amount of free system memory in gigabytes, or 296 * {@code null} if it was not included in the monitor entry. 297 */ 298 public Double getRecentSystemMemoryFreeGB() 299 { 300 return recentMemoryFreeGB; 301 } 302 303 304 305 /** 306 * Retrieves the recent percentage of free system memory, if available. 307 * 308 * @return The recent percentage of free system memory, or {@code null} if it 309 * was not included in the monitor entry. 310 */ 311 public Double getRecentSystemMemoryPercentFree() 312 { 313 return recentMemoryPercentFree; 314 } 315 316 317 318 /** 319 * {@inheritDoc} 320 */ 321 @Override() 322 public String getMonitorDisplayName() 323 { 324 return INFO_CPU_MEM_MONITOR_DISPNAME.get(); 325 } 326 327 328 329 /** 330 * {@inheritDoc} 331 */ 332 @Override() 333 public String getMonitorDescription() 334 { 335 return INFO_CPU_MEM_MONITOR_DESC.get(); 336 } 337 338 339 340 /** 341 * {@inheritDoc} 342 */ 343 @Override() 344 public Map<String,MonitorAttribute> getMonitorAttributes() 345 { 346 final LinkedHashMap<String,MonitorAttribute> attrs = 347 new LinkedHashMap<String,MonitorAttribute>(9); 348 349 if (timestamp != null) 350 { 351 addMonitorAttribute(attrs, 352 ATTR_TIMESTAMP, 353 INFO_CPU_MEM_DISPNAME_TIMESTAMP.get(), 354 INFO_CPU_MEM_DESC_TIMESTAMP.get(), 355 timestamp); 356 } 357 358 if (recentCPUTotalBusy != null) 359 { 360 addMonitorAttribute(attrs, 361 ATTR_RECENT_TOTAL_CPU_BUSY, 362 INFO_CPU_MEM_DISPNAME_RECENT_CPU_TOTAL_BUSY.get(), 363 INFO_CPU_MEM_DESC_RECENT_CPU_TOTAL_BUSY.get(), 364 recentCPUTotalBusy); 365 } 366 367 if (recentCPUUser != null) 368 { 369 addMonitorAttribute(attrs, 370 ATTR_RECENT_CPU_USER, 371 INFO_CPU_MEM_DISPNAME_RECENT_CPU_USER.get(), 372 INFO_CPU_MEM_DESC_RECENT_CPU_USER.get(), 373 recentCPUUser); 374 } 375 376 if (recentCPUSystem != null) 377 { 378 addMonitorAttribute(attrs, 379 ATTR_RECENT_CPU_SYSTEM, 380 INFO_CPU_MEM_DISPNAME_RECENT_CPU_SYSTEM.get(), 381 INFO_CPU_MEM_DESC_RECENT_CPU_SYSTEM.get(), 382 recentCPUSystem); 383 } 384 385 if (recentCPUIOWait != null) 386 { 387 addMonitorAttribute(attrs, 388 ATTR_RECENT_CPU_IOWAIT, 389 INFO_CPU_MEM_DISPNAME_RECENT_CPU_IOWAIT.get(), 390 INFO_CPU_MEM_DESC_RECENT_CPU_IOWAIT.get(), 391 recentCPUIOWait); 392 } 393 394 if (recentCPUIdle != null) 395 { 396 addMonitorAttribute(attrs, 397 ATTR_RECENT_CPU_IDLE, 398 INFO_CPU_MEM_DISPNAME_RECENT_CPU_IDLE.get(), 399 INFO_CPU_MEM_DESC_RECENT_CPU_IDLE.get(), 400 recentCPUIdle); 401 } 402 403 if (totalMemoryGB != null) 404 { 405 addMonitorAttribute(attrs, 406 ATTR_TOTAL_MEMORY_GB, 407 INFO_CPU_MEM_DISPNAME_TOTAL_MEM.get(), 408 INFO_CPU_MEM_DESC_TOTAL_MEM.get(), 409 totalMemoryGB); 410 } 411 412 if (recentMemoryFreeGB != null) 413 { 414 addMonitorAttribute(attrs, 415 ATTR_RECENT_MEMORY_FREE_GB, 416 INFO_CPU_MEM_DISPNAME_FREE_MEM_GB.get(), 417 INFO_CPU_MEM_DESC_FREE_MEM_GB.get(), 418 recentMemoryFreeGB); 419 } 420 421 if (recentMemoryPercentFree != null) 422 { 423 addMonitorAttribute(attrs, 424 ATTR_RECENT_MEMORY_FREE_PCT, 425 INFO_CPU_MEM_DISPNAME_FREE_MEM_PCT.get(), 426 INFO_CPU_MEM_DESC_FREE_MEM_PCT.get(), 427 recentMemoryPercentFree); 428 } 429 430 return Collections.unmodifiableMap(attrs); 431 } 432 }