Package com.rackspacecloud.blueflood.types

Examples of com.rackspacecloud.blueflood.types.TimerRollup


                        CodedOutputStream.computeDoubleSizeNoTag(stat.toDouble()) :
                        CodedOutputStream.computeRawVarint64Size(stat.toLong());
                return sz;
            case Type.B_TIMER:
                sz += 1; // version
                TimerRollup rollup = (TimerRollup)o;
                sz += CodedOutputStream.computeRawVarint64Size(rollup.getSum());
                sz += CodedOutputStream.computeRawVarint64Size(rollup.getCount());
                sz += CodedOutputStream.computeDoubleSizeNoTag(rollup.getRate());
                sz += CodedOutputStream.computeRawVarint32Size(rollup.getSampleCount());
                sz += sizeOf(rollup.getAverage(), Type.B_ROLLUP_STAT);
                sz += sizeOf(rollup.getMaxValue(), Type.B_ROLLUP_STAT);
                sz += sizeOf(rollup.getMinValue(), Type.B_ROLLUP_STAT);
                sz += sizeOf(rollup.getVariance(), Type.B_ROLLUP_STAT);
               
                Map<String, TimerRollup.Percentile> percentiles = rollup.getPercentiles();
                sz += CodedOutputStream.computeRawVarint32Size(rollup.getPercentiles().size());
                for (Map.Entry<String, TimerRollup.Percentile> entry : percentiles.entrySet()) {
                    sz += CodedOutputStream.computeStringSizeNoTag(entry.getKey());
                    Number[] pctComponents = new Number[] {
                            entry.getValue().getMean(),
                    };
View Full Code Here


        // var
        statType = in.readRawByte();
        stat = getStatFromRollup(statType, statBucket);
        setStat(stat, in);
       
        TimerRollup rollup = new TimerRollup()
                .withSum(sum)
                .withCount(count)
                .withCountPS(countPs)
                .withSampleCount(sampleCount)
                .withAverage(statBucket.getAverage())
                .withMaxValue(statBucket.getMaxValue())
                .withMinValue(statBucket.getMinValue())
                .withVariance(statBucket.getVariance());
       
        int numPercentiles = in.readRawVarint32();
        for (int i = 0; i < numPercentiles; i++) {
            String name = in.readString();
            Number mean = getUnversionedDoubleOrLong(in);
            rollup.setPercentile(name, mean);
        }
       
        return rollup;
    }
View Full Code Here

    private static Collection<PreaggregatedMetric> remarshalTimers(Bundle bundle, String tenantId) {
        final Collection<Timer> timers = bundle.getTimers();
        final List<PreaggregatedMetric> metrics = new ArrayList<PreaggregatedMetric>(timers.size());
        for (Timer t : timers) {
            Locator locator = Locator.createLocatorFromPathComponents(tenantId == null ? t.getTenant() : tenantId, splitForLocator(t.getName()));
            TimerRollup rollup = new TimerRollup()
                    .withCount(t.getCount().longValue())
                    .withSampleCount(1)
                    .withAverage(t.getAvg())
                    .withMaxValue(t.getMax())
                    .withMinValue(t.getMin())
                    .withCountPS(t.getRate().doubleValue())
                    .withSum(t.getSum().longValue())
                    .withVariance(Math.pow(t.getStd().doubleValue(), 2d));
           
            // percentiles.
            for (Map.Entry<String, Number> entry : t.getPercentiles().entrySet()) {
                rollup.setPercentile(entry.getKey(), entry.getValue());
            }
           
            // histograms are ignored.
            PreaggregatedMetric metric = new PreaggregatedMetric(bundle.getCollectionTime(), locator, DEFAULT_PREAG_TTL, rollup);
            metrics.add(metric);
View Full Code Here

public class TimerSerializationTest {
   
    @Test
    public void testV1RoundTrip() throws IOException {
        // build up a Timer
        TimerRollup r0 = new TimerRollup()
                .withSum(42)
                .withCountPS(23.32d)
                .withAverage(56)
                .withVariance(853.3245d)
                .withMinValue(2)
                .withMaxValue(987)
                .withCount(345);
        r0.setPercentile("foo", 741.32d);
        r0.setPercentile("bar", 0.0323d);
       
        if (System.getProperty("GENERATE_TIMER_SERIALIZATION") != null) {
            OutputStream os = new FileOutputStream("src/test/resources/serializations/timer_version_" + Constants.VERSION_1_TIMER + ".bin", false);
            os.write(Base64.encodeBase64(new NumericSerializer.TimerRollupSerializer().toByteBuffer(r0).array()));
            os.write("\n".getBytes());
            os.close();
        }
       
        Assert.assertTrue(new File("src/test/resources/serializations").exists());
       
        // ensure historical reads work.
        int version = 0;
        int maxVersion = Constants.VERSION_1_TIMER;
       
        int count = 0;
        while (version <= maxVersion) {
            BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/serializations/timer_version_" + version + ".bin"));
            ByteBuffer bb = ByteBuffer.wrap(Base64.decodeBase64(reader.readLine().getBytes()));
            TimerRollup r1 = new NumericSerializer.TimerRollupSerializer().fromByteBuffer(bb);
            Assert.assertEquals(r0, r1);
            count++;
            version++;
        }
       
View Full Code Here

   
    public static Collection<PreaggregatedMetric> convertTimers(String tenant, long timestamp, Collection<Bundle.Timer> timers) {
        List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(timers.size());
        for (Bundle.Timer timer : timers) {
            Locator locator = Locator.createLocatorFromPathComponents(tenant, timer.getName().split(NAME_DELIMITER, -1));
            TimerRollup rollup = new TimerRollup()
                    .withCount(timer.getCount().longValue())
                    .withSampleCount(1)
                    .withAverage(resolveNumber(timer.getAvg()))
                    .withMaxValue(resolveNumber(timer.getMax()))
                    .withMinValue(resolveNumber(timer.getMin()))
                    .withCountPS(timer.getRate().doubleValue())
                    .withSum(timer.getSum().longValue()) // I wonder now if assuming sum instanceof Long is wrong.
                    .withVariance(Math.pow(timer.getStd().doubleValue(), 2d));
            for (Map.Entry<String, Bundle.Percentile> entry : timer.getPercentiles().entrySet()) {
                // throw away max and sum.
                if (entry.getValue().getAvg() != null) {
                    rollup.setPercentile(entry.getKey(), resolveNumber(entry.getValue().getAvg()));
                }
            }
            PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup);
            list.add(metric);
        }
View Full Code Here

    public static Points<TimerRollup> generateFakeTimerRollups() {
        Points<TimerRollup> points = new Points<TimerRollup>();
        long startTime = 1234567L;
        for (int i = 0; i < 5; i++) {
            long timeNow = startTime + i*1000;
            TimerRollup rollup = new TimerRollup()
                .withAverage(i)
                .withCount(i)
                .withCountPS(i*0.1d)
                .withMaxValue(i)
                .withMinValue(i)
                .withSum(i+i)
                .withVariance(i);
            rollup.setPercentile("50", i);
            rollup.setPercentile("99", i * 2 + 1);
            Points.Point<TimerRollup> point = new Points.Point<TimerRollup>(timeNow, rollup);
            points.add(point);
        }
        return points;
    }
View Full Code Here

        } else if (point.getData() instanceof SetRollup) {
            SetRollup rollup = (SetRollup)point.getData();
            numPoints += rollup.getCount();
            filterStatsObject = getFilteredStatsForRollup(rollup, filterStats);
        } else if (point.getData() instanceof TimerRollup) {
            TimerRollup rollup = (TimerRollup)point.getData();
            numPoints += rollup.getCount();
            filterStatsObject = getFilteredStatsForRollup(rollup, filterStats);
        } else if (point.getData() instanceof CounterRollup) {
            CounterRollup rollup = (CounterRollup)point.getData();
            numPoints += rollup.getCount().longValue();
            filterStatsObject = getFilteredStatsForRollup(rollup, filterStats);
        } else {
            throw new SerializationException("Unsupported data type for Point");
        }
View Full Code Here

    private AstyanaxReader reader = AstyanaxReader.getInstance();
    private static final AtomicLong timestamp = new AtomicLong(10);
   
    @Before
    public void createFixtures() throws Exception {
        simple = new TimerRollup()
            .withSampleCount(1)
            .withSum(100L)
            .withCountPS(101d)
            .withAverage(102L)
            .withVariance(103d)
View Full Code Here

        // read the raw data.
        Points<TimerRollup> points = PreaggregatedMetricsIntegrationTest.getTimerDataToRoll(reader, locator, new Range(ts, ts+1), Granularity.FULL);
        Assert.assertEquals(1, points.getPoints().size());
       
        // create the rollup
        final TimerRollup rollup = TimerRollup.buildRollupFromTimerRollups(points);
        // should be the same as simple
        Assert.assertEquals(simple, rollup);
       
        // assemble it into points, but give it a new timestamp.
        points = new Points<TimerRollup>() {{
            add(new Point<TimerRollup>(rollupTs, rollup));
        }};
        List<IMetric> toWrite = toIMetricsList(locator, points);
        writer.insertMetrics(toWrite, CassandraModel.CF_METRICS_PREAGGREGATED_5M);
       
        // we should be able to read that now.
        Points<TimerRollup> rollups5m = reader.getDataToRoll(TimerRollup.class, locator, new Range(rollupTs, rollupTs+1), CassandraModel.CF_METRICS_PREAGGREGATED_5M);
       
        Assert.assertEquals(1, rollups5m.getPoints().size());
       
        TimerRollup rollup5m = rollups5m.getPoints().values().iterator().next().getData();
        // rollups should be identical since one is just a coarse rollup of the other.
        Assert.assertEquals(rollup, rollup5m);
    }
View Full Code Here

TOP

Related Classes of com.rackspacecloud.blueflood.types.TimerRollup

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.