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