001/* 002 * Copyright 2014-2019 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2019 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.LinkedHashMap; 028import java.util.List; 029import java.util.Map; 030import java.util.StringTokenizer; 031 032import com.unboundid.ldap.sdk.Entry; 033import com.unboundid.util.Debug; 034import com.unboundid.util.NotMutable; 035import com.unboundid.util.StaticUtils; 036import com.unboundid.util.ThreadSafety; 037import com.unboundid.util.ThreadSafetyLevel; 038 039import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 040 041 042 043/** 044 * This class defines a numeric gauge monitor entry, which obtains its 045 * information from a numeric value in a monitor entry. 046 * <BR> 047 * <BLOCKQUOTE> 048 * <B>NOTE:</B> This class, and other classes within the 049 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 050 * supported for use against Ping Identity, UnboundID, and 051 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 052 * for proprietary functionality or for external specifications that are not 053 * considered stable or mature enough to be guaranteed to work in an 054 * interoperable way with other types of LDAP servers. 055 * </BLOCKQUOTE> 056 */ 057@NotMutable() 058@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 059public final class NumericGaugeMonitorEntry 060 extends GaugeMonitorEntry 061{ 062 /** 063 * The structural object class used in gauge monitor entries. 064 */ 065 static final String NUMERIC_GAUGE_MONITOR_OC = 066 "ds-numeric-gauge-monitor-entry"; 067 068 069 070 /** 071 * The serial version UID for this serializable class. 072 */ 073 private static final long serialVersionUID = 2049893927290436280L; 074 075 076 077 // The current value for the gauge. 078 private final Double currentValue; 079 080 // The maximum value observed for the gauge. 081 private final Double maximumValue; 082 083 // The minimum value observed for the gauge. 084 private final Double minimumValue; 085 086 // The current value for the gauge. 087 private final Double previousValue; 088 089 // The set of observed values for the gauge. 090 private final List<Double> observedValues; 091 092 093 094 /** 095 * Creates a new numeric gauge monitor entry from the provided entry. 096 * 097 * @param entry The entry to be parsed as a numeric gauge monitor entry. It 098 * must not be {@code null}. 099 */ 100 public NumericGaugeMonitorEntry(final Entry entry) 101 { 102 super(entry); 103 104 currentValue = getDouble("value"); 105 previousValue = getDouble("previous-value"); 106 minimumValue = getDouble("value-minimum"); 107 maximumValue = getDouble("value-maximum"); 108 109 final String observedStr = getString("observed-values"); 110 if ((observedStr == null) || observedStr.isEmpty()) 111 { 112 observedValues = Collections.emptyList(); 113 } 114 else 115 { 116 final ArrayList<Double> values = new ArrayList<>(10); 117 try 118 { 119 final StringTokenizer tokenizer = new StringTokenizer(observedStr, ","); 120 while (tokenizer.hasMoreTokens()) 121 { 122 values.add(Double.parseDouble(tokenizer.nextToken())); 123 } 124 } 125 catch (final Exception e) 126 { 127 Debug.debugException(e); 128 values.clear(); 129 } 130 131 observedValues = Collections.unmodifiableList(values); 132 } 133 } 134 135 136 137 /** 138 * Retrieves the current value for the gauge, if available. 139 * 140 * @return The current value for the gauge, or {@code null} if it was not 141 * included in the monitor entry. 142 */ 143 public Double getCurrentValue() 144 { 145 return currentValue; 146 } 147 148 149 150 /** 151 * Retrieves the previous value for the gauge, if available. 152 * 153 * @return The previous value for the gauge, or {@code null} if it was not 154 * included in the monitor entry. 155 */ 156 public Double getPreviousValue() 157 { 158 return previousValue; 159 } 160 161 162 163 /** 164 * Retrieves the minimum value observed for the gauge, if available. 165 * 166 * @return The minimum value observed for the gauge, or {@code null} if it 167 * was not included in the monitor entry. 168 */ 169 public Double getMinimumValue() 170 { 171 return minimumValue; 172 } 173 174 175 176 /** 177 * Retrieves the maximum value observed for the gauge, if available. 178 * 179 * @return The maximum value observed for the gauge, or {@code null} if it 180 * was not included in the monitor entry. 181 */ 182 public Double getMaximumValue() 183 { 184 return maximumValue; 185 } 186 187 188 189 /** 190 * Retrieves the set of observed values for the gauge, if available. 191 * 192 * @return The set of observed values for the gauge, or {@code null} if it 193 * was not included in the monitor entry. 194 */ 195 public List<Double> getObservedValues() 196 { 197 return observedValues; 198 } 199 200 201 202 /** 203 * {@inheritDoc} 204 */ 205 @Override() 206 public String getMonitorDisplayName() 207 { 208 return INFO_NUMERIC_GAUGE_MONITOR_DISPNAME.get(); 209 } 210 211 212 213 /** 214 * {@inheritDoc} 215 */ 216 @Override() 217 public String getMonitorDescription() 218 { 219 return INFO_NUMERIC_GAUGE_MONITOR_DESC.get(); 220 } 221 222 223 224 /** 225 * {@inheritDoc} 226 */ 227 @Override() 228 public Map<String,MonitorAttribute> getMonitorAttributes() 229 { 230 final Map<String,MonitorAttribute> superAttributes = 231 super.getMonitorAttributes(); 232 233 final LinkedHashMap<String,MonitorAttribute> attrs = new LinkedHashMap<>( 234 StaticUtils.computeMapCapacity(superAttributes.size() + 5)); 235 attrs.putAll(superAttributes); 236 237 if (currentValue != null) 238 { 239 addMonitorAttribute(attrs, 240 "value", 241 INFO_NUMERIC_GAUGE_DISPNAME_CURRENT_VALUE.get(), 242 INFO_NUMERIC_GAUGE_DESC_CURRENT_VALUE.get(), 243 currentValue); 244 } 245 246 if (previousValue != null) 247 { 248 addMonitorAttribute(attrs, 249 "previous-value", 250 INFO_NUMERIC_GAUGE_DISPNAME_PREVIOUS_VALUE.get(), 251 INFO_NUMERIC_GAUGE_DESC_PREVIOUS_VALUE.get(), 252 previousValue); 253 } 254 255 if (minimumValue != null) 256 { 257 addMonitorAttribute(attrs, 258 "value-minimum", 259 INFO_NUMERIC_GAUGE_DISPNAME_MINIMUM_VALUE.get(), 260 INFO_NUMERIC_GAUGE_DESC_MINIMUM_VALUE.get(), 261 minimumValue); 262 } 263 264 if (maximumValue != null) 265 { 266 addMonitorAttribute(attrs, 267 "value-maximum", 268 INFO_NUMERIC_GAUGE_DISPNAME_MAXIMUM_VALUE.get(), 269 INFO_NUMERIC_GAUGE_DESC_MAXIMUM_VALUE.get(), 270 maximumValue); 271 } 272 273 if (! observedValues.isEmpty()) 274 { 275 final Double[] values = new Double[observedValues.size()]; 276 observedValues.toArray(values); 277 278 attrs.put("observed-values", 279 new MonitorAttribute("observed-values", 280 INFO_NUMERIC_GAUGE_DISPNAME_OBSERVED_VALUES.get(), 281 INFO_NUMERIC_GAUGE_DESC_OBSERVED_VALUES.get(), 282 values)); 283 } 284 285 return Collections.unmodifiableMap(attrs); 286 } 287}