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