MetricManager.java (eucalyptus-4.4.1) | : | MetricManager.java (eucalyptus-4.4.2) | ||
---|---|---|---|---|
skipping to change at line 22 | skipping to change at line 22 | |||
* | * | |||
* You should have received a copy of the GNU General Public License | * You should have received a copy of the GNU General Public License | |||
* along with this program. If not, see http://www.gnu.org/licenses/. | * along with this program. If not, see http://www.gnu.org/licenses/. | |||
* | * | |||
* Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta | * Please contact Eucalyptus Systems, Inc., 6755 Hollister Ave., Goleta | |||
* CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need | * CA 93117, USA or visit http://www.eucalyptus.com/licenses/ if you need | |||
* additional information or have any questions. | * additional information or have any questions. | |||
************************************************************************/ | ************************************************************************/ | |||
package com.eucalyptus.cloudwatch.common.internal.domain.metricdata; | package com.eucalyptus.cloudwatch.common.internal.domain.metricdata; | |||
import java.text.DateFormat; | ||||
import java.text.SimpleDateFormat; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | |||
import java.util.Collection; | import java.util.Collection; | |||
import java.util.Date; | import java.util.Date; | |||
import java.util.HashMap; | import java.util.HashMap; | |||
import java.util.List; | import java.util.List; | |||
import java.util.Map; | import java.util.Map; | |||
import java.util.Set; | ||||
import java.util.TreeMap; | import java.util.TreeMap; | |||
import java.util.TreeSet; | import java.util.TreeSet; | |||
import javax.persistence.EntityTransaction; | ||||
import com.eucalyptus.cloudwatch.common.internal.domain.AbstractPersistentWithDi mensions; | import com.eucalyptus.cloudwatch.common.internal.domain.AbstractPersistentWithDi mensions; | |||
import com.eucalyptus.configurable.ConfigurableClass; | ||||
import com.eucalyptus.configurable.ConfigurableField; | ||||
import com.eucalyptus.configurable.PropertyChangeListeners; | ||||
import com.eucalyptus.entities.TransactionResource; | import com.eucalyptus.entities.TransactionResource; | |||
import com.google.common.collect.Iterables; | import com.google.common.collect.Iterables; | |||
import com.google.common.collect.LinkedListMultimap; | import com.google.common.collect.LinkedListMultimap; | |||
import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | |||
import org.hibernate.CacheMode; | import org.hibernate.CacheMode; | |||
import org.hibernate.Criteria; | import org.hibernate.Criteria; | |||
import org.hibernate.ScrollMode; | import org.hibernate.ScrollMode; | |||
import org.hibernate.ScrollableResults; | import org.hibernate.ScrollableResults; | |||
import org.hibernate.criterion.Junction; | import org.hibernate.criterion.Junction; | |||
import org.hibernate.criterion.Order; | import org.hibernate.criterion.Order; | |||
import org.hibernate.criterion.ProjectionList; | import org.hibernate.criterion.ProjectionList; | |||
import org.hibernate.criterion.Projections; | import org.hibernate.criterion.Projections; | |||
import org.hibernate.criterion.Restrictions; | import org.hibernate.criterion.Restrictions; | |||
import com.eucalyptus.cloudwatch.common.internal.domain.DimensionEntity; | import com.eucalyptus.cloudwatch.common.internal.domain.DimensionEntity; | |||
import com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricEntity. MetricType; | import com.eucalyptus.cloudwatch.common.internal.domain.metricdata.MetricEntity. MetricType; | |||
import com.eucalyptus.cloudwatch.common.internal.hashing.HashUtils; | import com.eucalyptus.cloudwatch.common.internal.hashing.HashUtils; | |||
import com.eucalyptus.entities.Entities; | import com.eucalyptus.entities.Entities; | |||
import com.eucalyptus.records.Logs; | ||||
import com.google.common.collect.ArrayListMultimap; | import com.google.common.collect.ArrayListMultimap; | |||
import com.google.common.collect.Lists; | import com.google.common.collect.Lists; | |||
import com.google.common.collect.Maps; | import com.google.common.collect.Maps; | |||
import com.google.common.collect.Multimap; | import com.google.common.collect.Multimap; | |||
import com.google.common.collect.Sets; | ||||
public class MetricManager { | public class MetricManager { | |||
public static volatile Integer METRIC_DATA_NUM_DB_OPERATIONS_PER_TRANSACTION = 10000; | public static volatile Integer METRIC_DATA_NUM_DB_OPERATIONS_PER_TRANSACTION = 10000; | |||
public static volatile Integer METRIC_DATA_NUM_DB_OPERATIONS_UNTIL_SESSION_FLU SH = 50; | public static volatile Integer METRIC_DATA_NUM_DB_OPERATIONS_UNTIL_SESSION_FLU SH = 50; | |||
public static final Logger LOG = Logger.getLogger(MetricManager.class); | public static final Logger LOG = Logger.getLogger(MetricManager.class); | |||
public static void addMetric(String accountId, | public static void addMetric(String accountId, | |||
String metricName, String namespace, Map<String, String> dimensionMap, | String metricName, String namespace, Map<String, String> dimensionMap, | |||
MetricType metricType, Units units, Date timestamp, Double sampleSize, | MetricType metricType, Units units, Date timestamp, Double sampleSize, | |||
skipping to change at line 393 | skipping to change at line 383 | |||
projectionList.add(Projections.groupProperty("units")); | projectionList.add(Projections.groupProperty("units")); | |||
projectionList.add(Projections.groupProperty("timestamp")); | projectionList.add(Projections.groupProperty("timestamp")); | |||
projectionList.add(Projections.groupProperty("accountId")); | projectionList.add(Projections.groupProperty("accountId")); | |||
projectionList.add(Projections.groupProperty("metricName")); | projectionList.add(Projections.groupProperty("metricName")); | |||
projectionList.add(Projections.groupProperty("metricType")); | projectionList.add(Projections.groupProperty("metricType")); | |||
projectionList.add(Projections.groupProperty("namespace")); | projectionList.add(Projections.groupProperty("namespace")); | |||
projectionList.add(Projections.groupProperty("dimensionHash")); | projectionList.add(Projections.groupProperty("dimensionHash")); | |||
criteria.setProjection(projectionList); | criteria.setProjection(projectionList); | |||
criteria.addOrder(Order.asc("timestamp")); | criteria.addOrder(Order.asc("timestamp")); | |||
ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE).scro | final ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE | |||
ll(ScrollMode.FORWARD_ONLY); | ).scroll(ScrollMode.FORWARD_ONLY); | |||
while (results.next()) { | try { | |||
MetricEntity me = getMetricEntity(results); | while ( results.next( ) ) { | |||
for (GetMetricStatisticsParams getMetricStatisticsParams : hashGroupMa | MetricEntity me = getMetricEntity( results ); | |||
p.get(metricEntityClass)) { | for ( GetMetricStatisticsParams getMetricStatisticsParams : hashGrou | |||
if (metricDataMatches(getMetricStatisticsParams, me)) { | pMap.get( metricEntityClass ) ) { | |||
Map<GetMetricStatisticsAggregationKey, MetricStatistics> aggregati | if ( metricDataMatches( getMetricStatisticsParams, me ) ) { | |||
onMap = multiAggregationMap.get(getMetricStatisticsParams); | Map<GetMetricStatisticsAggregationKey, MetricStatistics> aggrega | |||
GetMetricStatisticsAggregationKey key = new GetMetricStatisticsAgg | tionMap = multiAggregationMap.get( getMetricStatisticsParams ); | |||
regationKey(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsPar | GetMetricStatisticsAggregationKey key = new GetMetricStatisticsA | |||
ams.getPeriod(), getMetricStatisticsParams.getDimensionHash()); | ggregationKey( me, getMetricStatisticsParams.getStartTime( ), getMetricStatistic | |||
MetricStatistics item = new MetricStatistics(me, getMetricStatisti | sParams.getPeriod( ), getMetricStatisticsParams.getDimensionHash( ) ); | |||
csParams.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatist | MetricStatistics item = new MetricStatistics( me, getMetricStati | |||
icsParams.getDimensions()); | sticsParams.getStartTime( ), getMetricStatisticsParams.getPeriod( ), getMetricSt | |||
if (!aggregationMap.containsKey(key)) { | atisticsParams.getDimensions( ) ); | |||
aggregationMap.put(key, item); | if ( !aggregationMap.containsKey( key ) ) { | |||
} else { | aggregationMap.put( key, item ); | |||
MetricStatistics totalSoFar = aggregationMap.get(key); | } else { | |||
totalSoFar.setSampleMax(Math.max(item.getSampleMax(), totalSoFar | MetricStatistics totalSoFar = aggregationMap.get( key ); | |||
.getSampleMax())); | totalSoFar.setSampleMax( Math.max( item.getSampleMax( ), total | |||
totalSoFar.setSampleMin(Math.min(item.getSampleMin(), totalSoFar | SoFar.getSampleMax( ) ) ); | |||
.getSampleMin())); | totalSoFar.setSampleMin( Math.min( item.getSampleMin( ), total | |||
totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSa | SoFar.getSampleMin( ) ) ); | |||
mpleSize()); | totalSoFar.setSampleSize( totalSoFar.getSampleSize( ) + item.g | |||
totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSamp | etSampleSize( ) ); | |||
leSum()); | totalSoFar.setSampleSum( totalSoFar.getSampleSum( ) + item.get | |||
SampleSum( ) ); | ||||
} | ||||
} | } | |||
} | } | |||
} | } | |||
} finally { | ||||
results.close( ); | ||||
} | } | |||
for (GetMetricStatisticsParams getMetricStatisticsParams : multiAggregat ionMap.keySet()) { | for (GetMetricStatisticsParams getMetricStatisticsParams : multiAggregat ionMap.keySet()) { | |||
resultMap.put(getMetricStatisticsParams, multiAggregationMap.get(getMe tricStatisticsParams).values()); | resultMap.put(getMetricStatisticsParams, multiAggregationMap.get(getMe tricStatisticsParams).values()); | |||
} | } | |||
} | } | |||
} | } | |||
List<Collection<MetricStatistics>> resultList = Lists.newArrayList(); | List<Collection<MetricStatistics>> resultList = Lists.newArrayList(); | |||
for (GetMetricStatisticsParams getMetricStatisticsParams : getMetricStatisti csParamses) { | for (GetMetricStatisticsParams getMetricStatisticsParams : getMetricStatisti csParamses) { | |||
if (resultMap.get(getMetricStatisticsParams) == null) { | if (resultMap.get(getMetricStatisticsParams) == null) { | |||
resultList.add(new ArrayList<MetricStatistics>()); | resultList.add(new ArrayList<MetricStatistics>()); | |||
skipping to change at line 468 | skipping to change at line 462 | |||
ProjectionList projectionList = Projections.projectionList(); | ProjectionList projectionList = Projections.projectionList(); | |||
projectionList.add(Projections.max("sampleMax")); | projectionList.add(Projections.max("sampleMax")); | |||
projectionList.add(Projections.min("sampleMin")); | projectionList.add(Projections.min("sampleMin")); | |||
projectionList.add(Projections.sum("sampleSize")); | projectionList.add(Projections.sum("sampleSize")); | |||
projectionList.add(Projections.sum("sampleSum")); | projectionList.add(Projections.sum("sampleSum")); | |||
projectionList.add(Projections.groupProperty("units")); | projectionList.add(Projections.groupProperty("units")); | |||
projectionList.add(Projections.groupProperty("timestamp")); | projectionList.add(Projections.groupProperty("timestamp")); | |||
criteria.setProjection(projectionList); | criteria.setProjection(projectionList); | |||
criteria.addOrder(Order.asc("timestamp")); | criteria.addOrder(Order.asc("timestamp")); | |||
ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE).scroll | final ScrollableResults results = criteria.setCacheMode(CacheMode.IGNORE). | |||
(ScrollMode.FORWARD_ONLY); | scroll(ScrollMode.FORWARD_ONLY); | |||
while (results.next()) { | try { | |||
MetricEntity me = getMetricEntity(getMetricStatisticsParams.getAccountId | while ( results.next( ) ) { | |||
(), getMetricStatisticsParams.getMetricName(), getMetricStatisticsParams.getName | MetricEntity me = getMetricEntity( getMetricStatisticsParams.getAccoun | |||
space(), getMetricStatisticsParams.getMetricType(), getMetricStatisticsParams.ge | tId( ), getMetricStatisticsParams.getMetricName( ), getMetricStatisticsParams.ge | |||
tDimensionHash(), results); | tNamespace( ), getMetricStatisticsParams.getMetricType( ), getMetricStatisticsPa | |||
GetMetricStatisticsAggregationKey key = new GetMetricStatisticsAggregati | rams.getDimensionHash( ), results ); | |||
onKey(me, getMetricStatisticsParams.getStartTime(), getMetricStatisticsParams.ge | GetMetricStatisticsAggregationKey key = new GetMetricStatisticsAggrega | |||
tPeriod(), getMetricStatisticsParams.getDimensionHash()); | tionKey( me, getMetricStatisticsParams.getStartTime( ), getMetricStatisticsParam | |||
MetricStatistics item = new MetricStatistics(me, getMetricStatisticsPara | s.getPeriod( ), getMetricStatisticsParams.getDimensionHash( ) ); | |||
ms.getStartTime(), getMetricStatisticsParams.getPeriod(), getMetricStatisticsPar | MetricStatistics item = new MetricStatistics( me, getMetricStatisticsP | |||
ams.getDimensions()); | arams.getStartTime( ), getMetricStatisticsParams.getPeriod( ), getMetricStatisti | |||
if (!aggregationMap.containsKey(key)) { | csParams.getDimensions( ) ); | |||
aggregationMap.put(key, item); | if ( !aggregationMap.containsKey( key ) ) { | |||
} else { | aggregationMap.put( key, item ); | |||
MetricStatistics totalSoFar = aggregationMap.get(key); | } else { | |||
totalSoFar.setSampleMax(Math.max(item.getSampleMax(), totalSoFar.getSa | MetricStatistics totalSoFar = aggregationMap.get( key ); | |||
mpleMax())); | totalSoFar.setSampleMax( Math.max( item.getSampleMax( ), totalSoFar. | |||
totalSoFar.setSampleMin(Math.min(item.getSampleMin(), totalSoFar.getSa | getSampleMax( ) ) ); | |||
mpleMin())); | totalSoFar.setSampleMin( Math.min( item.getSampleMin( ), totalSoFar. | |||
totalSoFar.setSampleSize(totalSoFar.getSampleSize() + item.getSampleSi | getSampleMin( ) ) ); | |||
ze()); | totalSoFar.setSampleSize( totalSoFar.getSampleSize( ) + item.getSamp | |||
totalSoFar.setSampleSum(totalSoFar.getSampleSum() + item.getSampleSum( | leSize( ) ); | |||
)); | totalSoFar.setSampleSum( totalSoFar.getSampleSum( ) + item.getSample | |||
Sum( ) ); | ||||
} | ||||
} | } | |||
} finally { | ||||
results.close( ); | ||||
} | } | |||
} | } | |||
return Lists.newArrayList(aggregationMap.values()); | return Lists.newArrayList(aggregationMap.values()); | |||
} | } | |||
private static MetricEntity getMetricEntity(ScrollableResults results) { | private static MetricEntity getMetricEntity(ScrollableResults results) { | |||
Double sampleMax = (Double) results.get(0); | Double sampleMax = (Double) results.get(0); | |||
Double sampleMin = (Double) results.get(1); | Double sampleMin = (Double) results.get(1); | |||
Double sampleSize = (Double) results.get(2); | Double sampleSize = (Double) results.get(2); | |||
Double sampleSum = (Double) results.get(3); | Double sampleSum = (Double) results.get(3); | |||
End of changes. 10 change blocks. | ||||
62 lines changed or deleted | 60 lines changed or added |