001/* 002 * Copyright 2014-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2014-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2015-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.monitors; 037 038 039 040import java.util.ArrayList; 041import java.util.Collections; 042import java.util.LinkedHashMap; 043import java.util.List; 044import java.util.Map; 045import java.util.StringTokenizer; 046 047import com.unboundid.ldap.sdk.Entry; 048import com.unboundid.util.Debug; 049import com.unboundid.util.NotMutable; 050import com.unboundid.util.StaticUtils; 051import com.unboundid.util.ThreadSafety; 052import com.unboundid.util.ThreadSafetyLevel; 053 054import static com.unboundid.ldap.sdk.unboundidds.monitors.MonitorMessages.*; 055 056 057 058/** 059 * This class defines a numeric gauge monitor entry, which obtains its 060 * information from a numeric value in a monitor entry. 061 * <BR> 062 * <BLOCKQUOTE> 063 * <B>NOTE:</B> This class, and other classes within the 064 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 065 * supported for use against Ping Identity, UnboundID, and 066 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 067 * for proprietary functionality or for external specifications that are not 068 * considered stable or mature enough to be guaranteed to work in an 069 * interoperable way with other types of LDAP servers. 070 * </BLOCKQUOTE> 071 */ 072@NotMutable() 073@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 074public final class NumericGaugeMonitorEntry 075 extends GaugeMonitorEntry 076{ 077 /** 078 * The structural object class used in gauge monitor entries. 079 */ 080 static final String NUMERIC_GAUGE_MONITOR_OC = 081 "ds-numeric-gauge-monitor-entry"; 082 083 084 085 /** 086 * The serial version UID for this serializable class. 087 */ 088 private static final long serialVersionUID = 2049893927290436280L; 089 090 091 092 // The current value for the gauge. 093 private final Double currentValue; 094 095 // The maximum value observed for the gauge. 096 private final Double maximumValue; 097 098 // The minimum value observed for the gauge. 099 private final Double minimumValue; 100 101 // The current value for the gauge. 102 private final Double previousValue; 103 104 // The set of observed values for the gauge. 105 private final List<Double> observedValues; 106 107 108 109 /** 110 * Creates a new numeric gauge monitor entry from the provided entry. 111 * 112 * @param entry The entry to be parsed as a numeric gauge monitor entry. It 113 * must not be {@code null}. 114 */ 115 public NumericGaugeMonitorEntry(final Entry entry) 116 { 117 super(entry); 118 119 currentValue = getDouble("value"); 120 previousValue = getDouble("previous-value"); 121 minimumValue = getDouble("value-minimum"); 122 maximumValue = getDouble("value-maximum"); 123 124 final String observedStr = getString("observed-values"); 125 if ((observedStr == null) || observedStr.isEmpty()) 126 { 127 observedValues = Collections.emptyList(); 128 } 129 else 130 { 131 final ArrayList<Double> values = new ArrayList<>(10); 132 try 133 { 134 final StringTokenizer tokenizer = new StringTokenizer(observedStr, ","); 135 while (tokenizer.hasMoreTokens()) 136 { 137 values.add(Double.parseDouble(tokenizer.nextToken())); 138 } 139 } 140 catch (final Exception e) 141 { 142 Debug.debugException(e); 143 values.clear(); 144 } 145 146 observedValues = Collections.unmodifiableList(values); 147 } 148 } 149 150 151 152 /** 153 * Retrieves the current value for the gauge, if available. 154 * 155 * @return The current value for the gauge, or {@code null} if it was not 156 * included in the monitor entry. 157 */ 158 public Double getCurrentValue() 159 { 160 return currentValue; 161 } 162 163 164 165 /** 166 * Retrieves the previous value for the gauge, if available. 167 * 168 * @return The previous value for the gauge, or {@code null} if it was not 169 * included in the monitor entry. 170 */ 171 public Double getPreviousValue() 172 { 173 return previousValue; 174 } 175 176 177 178 /** 179 * Retrieves the minimum value observed for the gauge, if available. 180 * 181 * @return The minimum value observed for the gauge, or {@code null} if it 182 * was not included in the monitor entry. 183 */ 184 public Double getMinimumValue() 185 { 186 return minimumValue; 187 } 188 189 190 191 /** 192 * Retrieves the maximum value observed for the gauge, if available. 193 * 194 * @return The maximum value observed for the gauge, or {@code null} if it 195 * was not included in the monitor entry. 196 */ 197 public Double getMaximumValue() 198 { 199 return maximumValue; 200 } 201 202 203 204 /** 205 * Retrieves the set of observed values for the gauge, if available. 206 * 207 * @return The set of observed values for the gauge, or {@code null} if it 208 * was not included in the monitor entry. 209 */ 210 public List<Double> getObservedValues() 211 { 212 return observedValues; 213 } 214 215 216 217 /** 218 * {@inheritDoc} 219 */ 220 @Override() 221 public String getMonitorDisplayName() 222 { 223 return INFO_NUMERIC_GAUGE_MONITOR_DISPNAME.get(); 224 } 225 226 227 228 /** 229 * {@inheritDoc} 230 */ 231 @Override() 232 public String getMonitorDescription() 233 { 234 return INFO_NUMERIC_GAUGE_MONITOR_DESC.get(); 235 } 236 237 238 239 /** 240 * {@inheritDoc} 241 */ 242 @Override() 243 public Map<String,MonitorAttribute> getMonitorAttributes() 244 { 245 final Map<String,MonitorAttribute> superAttributes = 246 super.getMonitorAttributes(); 247 248 final LinkedHashMap<String,MonitorAttribute> attrs = new LinkedHashMap<>( 249 StaticUtils.computeMapCapacity(superAttributes.size() + 5)); 250 attrs.putAll(superAttributes); 251 252 if (currentValue != null) 253 { 254 addMonitorAttribute(attrs, 255 "value", 256 INFO_NUMERIC_GAUGE_DISPNAME_CURRENT_VALUE.get(), 257 INFO_NUMERIC_GAUGE_DESC_CURRENT_VALUE.get(), 258 currentValue); 259 } 260 261 if (previousValue != null) 262 { 263 addMonitorAttribute(attrs, 264 "previous-value", 265 INFO_NUMERIC_GAUGE_DISPNAME_PREVIOUS_VALUE.get(), 266 INFO_NUMERIC_GAUGE_DESC_PREVIOUS_VALUE.get(), 267 previousValue); 268 } 269 270 if (minimumValue != null) 271 { 272 addMonitorAttribute(attrs, 273 "value-minimum", 274 INFO_NUMERIC_GAUGE_DISPNAME_MINIMUM_VALUE.get(), 275 INFO_NUMERIC_GAUGE_DESC_MINIMUM_VALUE.get(), 276 minimumValue); 277 } 278 279 if (maximumValue != null) 280 { 281 addMonitorAttribute(attrs, 282 "value-maximum", 283 INFO_NUMERIC_GAUGE_DISPNAME_MAXIMUM_VALUE.get(), 284 INFO_NUMERIC_GAUGE_DESC_MAXIMUM_VALUE.get(), 285 maximumValue); 286 } 287 288 if (! observedValues.isEmpty()) 289 { 290 final Double[] values = new Double[observedValues.size()]; 291 observedValues.toArray(values); 292 293 attrs.put("observed-values", 294 new MonitorAttribute("observed-values", 295 INFO_NUMERIC_GAUGE_DISPNAME_OBSERVED_VALUES.get(), 296 INFO_NUMERIC_GAUGE_DESC_OBSERVED_VALUES.get(), 297 values)); 298 } 299 300 return Collections.unmodifiableMap(attrs); 301 } 302}