Package com.google.common.base

Examples of com.google.common.base.Stopwatch


    }

    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    public StorageNodeLoadComposite getLoad(Subject subject, StorageNode node, long beginTime, long endTime) {
        Stopwatch stopwatch = stopwatchStart();
        try {
            if (!storageClientManager.isClusterAvailable()) {
                return new StorageNodeLoadComposite(node, beginTime, endTime);
            }
            int storageNodeResourceId;
View Full Code Here


    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    public ListenableFuture<List<StorageNodeLoadComposite>> getLoadAsync(Subject subject, StorageNode node,
        long beginTime, long endTime) {
        Stopwatch stopwatch = stopwatchStart();
        final StorageNodeLoadComposite result = new StorageNodeLoadComposite(node, beginTime, endTime);
        try {
            if (!storageClientManager.isClusterAvailable()) {
                return Futures.successfulAsList(Lists.newArrayList(Futures.immediateFuture(result)));
            }
View Full Code Here

    }

    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    public PageList<StorageNodeLoadComposite> getStorageNodeComposites(Subject subject) {
        Stopwatch stopwatch = stopwatchStart();
        List<StorageNode> nodes = getStorageNodes();
        final CountDownLatch latch = new CountDownLatch(nodes.size());
        final PageList<StorageNodeLoadComposite> result = new PageList<StorageNodeLoadComposite>();
        try {
            long endTime = System.currentTimeMillis();
View Full Code Here

    }

    @Override
    @RequiredPermission(Permission.MANAGE_SETTINGS)
    public PageList<Alert> findNotAcknowledgedStorageNodeAlerts(Subject subject, StorageNode storageNode) {
        Stopwatch stopwatch = stopwatchStart();
        try {
            return findStorageNodeAlerts(subject, false, storageNode);
        } finally {
            if (log.isDebugEnabled()) {
                stopwatchEnd(stopwatch, "Retrieved unacked alerts for " + storageNode + " in ");
View Full Code Here

        return alerts;
    }

    private Map<Integer, Integer> findUnackedAlertCounts(List<StorageNode> storageNodes) {
        Stopwatch stopwatch = stopwatchStart();
        try {
            Map<Integer, StorageNode> resourceIdToStorageNodeMap = new TreeMap<Integer, StorageNode>();
            for (StorageNode storageNode : storageNodes) {
                if (storageNode.getResource() != null) { // handling the case before the s.n. autoimport
                    resourceIdToStorageNodeMap.put(storageNode.getResource().getId(), storageNode);
View Full Code Here

        }
        return new Integer[0];
    }

    private Map<Integer, Integer> findResourcesWithAlertsToStorageNodeMap(StorageNode storageNode) {
        Stopwatch stopwatch = stopwatchStart();
        List<StorageNode> initialStorageNodes = getStorageNodes();
        try {
            if (storageNode == null) {
                initialStorageNodes = getStorageNodes();
            } else {
View Full Code Here

        return successResultFound;
    }

    private Stopwatch stopwatchStart() {
        if (log.isDebugEnabled()) {
            return new Stopwatch().start();
        }
        return null;
    }
View Full Code Here

    public int execute(DateTime start, DateTime end) throws InterruptedException,
        AbortedException {

        log.info("Starting " + bucket + " data aggregation");
        Stopwatch stopwatch = Stopwatch.createStarted();
        try {
            IndexIterator iterator = new IndexIterator(start, end, bucket, dao, configuration);
            Batch batch = new Batch();
            while (iterator.hasNext()) {
                IndexEntry indexEntry = iterator.next();
                if (batch.getStartTime() == null) {
                    batch.setStartTime(indexEntry.getTimestamp());
                    batch.setEndTime(new DateTime(indexEntry.getTimestamp()).plus(timeSliceDuration));
                }
                if (batch.getStartTime().getMillis() == indexEntry.getTimestamp()) {
                    batch.add(indexEntry);
                    if (batch.size() == batchSize) {
                        submitAggregationTask(batch);
                        batch = new Batch();
                    }
                } else {
                    submitAggregationTask(batch);
                    batch = new Batch()
                        .setStartTime(indexEntry.getTimestamp())
                        .setEndTime(new DateTime(indexEntry.getTimestamp()).plus(timeSliceDuration))
                        .add(indexEntry);
                }
            }
            if (batch.size() > 0) {
                submitAggregationTask(batch);
            }
            iterator = null;
            taskTracker.finishedSchedulingTasks();
            taskTracker.waitForTasksToFinish();
        } catch (InterruptedException e) {
            log.warn("There was an interrupt while scheduling aggregation tasks.", e);
            taskTracker.abort("There was an interrupt while scheduling aggregation tasks.");
        } catch (Exception e) {
            log.warn("There was an unexpected error scheduling aggregation tasks", e);
            taskTracker.abort("There was an unexpected error scheduling aggregation tasks: " + e.getMessage());
        } finally {
            stopwatch.stop();
            log.info("Finished " + schedulesCount + " " + bucket + " data aggregations in " +
                stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
        }
        return schedulesCount.get();
    }
View Full Code Here

        return totalAggregationTime.get();
    }

    public Set<AggregateNumericMetric> run() {
        log.info("Starting metrics data aggregation");
        Stopwatch stopwatch = Stopwatch.createStarted();
        Semaphore permits = new Semaphore(batchSize * parallelism);

        log.debug("Allocating " + permits.availablePermits() + " permits");

        int num1Hour = 0;
        int num6Hour = 0;
        int num24Hour = 0;
        try {
            PersistFunctions persistFunctions = new PersistFunctions(dao, dtService);
            final Set<AggregateNumericMetric> oneHourData = new ConcurrentSkipListSet<AggregateNumericMetric>(
                AGGREGATE_COMPARATOR);
            DateTime endTime = dtService.currentHour();
            DateTime end = endTime;
            // We set the start time to the retention period minus 1 hour, or 6 days and 23
            // hours ago instead of 7 days ago because if we set the start time to the full
            // 7 days, then we could end up in a situation where data has expired and
            // aggregate metric get overwritten with partial data.
            DateTime start = end.minus(configuration.getRawRetention().toPeriod().minusHours(1));
            DataAggregator rawAggregator = createRawAggregator(persistFunctions, permits);
            rawAggregator.setBatchFinishedListener(new DataAggregator.BatchFinishedListener() {
                @Override
                public void onFinish(List<AggregateNumericMetric> metrics) {
                    oneHourData.addAll(metrics);
                }
            });
            num1Hour = rawAggregator.execute(start, end);

            end = dtService.get6HourTimeSlice(endTime);
            start = dtService.get6HourTimeSlice(endTime).minus(configuration.getRawRetention());
            num6Hour = create1HourAggregator(persistFunctions, permits).execute(start, end);

            end = dtService.get24HourTimeSlice(endTime);
            start = dtService.get24HourTimeSlice(endTime).minus(configuration.getRawRetention());
            num24Hour = create6HourAggregator(persistFunctions, permits).execute(start, end);

            return oneHourData;
        } catch (InterruptedException e) {
            log.info("There was an interrupt while waiting for aggregation to finish. Aggregation will be aborted.");
            return Collections.emptySet();
        }
        catch (AbortedException e) {
            log.warn("Aggregation has been aborted: " + e.getMessage());
            return Collections.emptySet();
        } finally {
            stopwatch.stop();
            totalAggregationTime.addAndGet(stopwatch.elapsed(TimeUnit.MILLISECONDS));
            log.info("Finished aggregation of {\"raw schedules\": " + num1Hour + ", \"1 hour schedules\": " + num6Hour +
                ", \"6 hour schedules\": " + num24Hour + "} in " + stopwatch.elapsed(TimeUnit.MILLISECONDS) + " ms");
        }
    }
View Full Code Here

        return new org.rhq.enterprise.server.measurement.MeasurementAggregate(summary.getMin(), summary.getAvg(), summary.getMax());
    }

    @Override
    public MeasurementAggregate getMeasurementAggregate(Subject subject, int scheduleId, long startTime, long endTime) {
        Stopwatch stopwatch = new Stopwatch().start();
        try {
            MeasurementScheduleCriteria criteria = new MeasurementScheduleCriteria();
            criteria.addFilterId(scheduleId);
            criteria.fetchResource(true);

            PageList<MeasurementSchedule> schedules = measurementScheduleManager.findSchedulesByCriteria(
                subjectManager.getOverlord(), criteria);
            if (schedules.isEmpty()) {
                throw new MeasurementException("Could not fine MeasurementSchedule with the id[" + scheduleId + "]");
            }
            MeasurementSchedule schedule = schedules.get(0);

            if (authorizationManager.canViewResource(subject, schedule.getResource().getId()) == false) {
                throw new PermissionException("User[" + subject.getName()
                    + "] does not have permission to view schedule[id=" + scheduleId + "]");
            }

            if (schedule.getDefinition().getDataType() != DataType.MEASUREMENT) {
                throw new IllegalArgumentException(schedule + " is not about numerical values. Can't compute aggregates");
            }

            if (startTime > endTime) {
                throw new IllegalArgumentException("Start date " + startTime + " is not before " + endTime);
            }

            MetricsServer metricsServer = storageClientManager.getMetricsServer();
            AggregateNumericMetric summary = metricsServer.getSummaryAggregate(scheduleId, startTime, endTime);

            return new MeasurementAggregate(summary.getMin(), summary.getAvg(), summary.getMax());
        } finally {
            stopwatch.stop();
            log.debug("Finished loading measurement aggregate in " + stopwatch.elapsed(TimeUnit.MILLISECONDS));
        }
    }
View Full Code Here

TOP

Related Classes of com.google.common.base.Stopwatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.