Skip to content

Instantly share code, notes, and snippets.

View jsanda's full-sized avatar

John Sanda jsanda

View GitHub Profile
# Cassandra storage config YAML
# NOTE:
# See http://wiki.apache.org/cassandra/StorageConfiguration for
# full explanations of configuration directives
# /NOTE
# The name of the cluster. This is mainly used to prevent machines in
# one logical cluster from joining another.
cluster_name: ${cluster.name}
public class RateLimitTest {
@Test
public void throttle() {
RateLimiter rateLimiter = RateLimiter.create(5, 5, TimeUnit.SECONDS);
for (int i = 0; i < 25; ++i) {
rateLimiter.acquire();
System.out.println("i = " + i);
}
rateLimiter.setRate(1);
CREATE TABLE metrics (
bucket text,
metric_id text,
time timestamp,
attributes map<text, text> static,
value map<int, double>,
PRIMARY KEY ((bucket, metric_id), time)
)
private void addData(final AsyncResponse asyncResponse, Set<RawNumericMetric> rawData) {
ListenableFuture<Map<RawNumericMetric,Throwable>> future = metricsService.addData(rawData);
Futures.addCallback(future, new FutureCallback<Map<RawNumericMetric, Throwable>>() {
@Override
public void onSuccess(Map<RawNumericMetric, Throwable> errors) {
Response jaxrs = Response.ok().type(MediaType.APPLICATION_JSON_TYPE).build();
asyncResponse.resume(jaxrs);
}
@Override
CREATE TYPE data_point (time timestamp, value map<int, double>);
CREATE TABLE tags (
tag_name text,
tag_value text,
metric_id text,
values list<data_point>,
PRIMARY KEY (tag_name, tag_value, metric_id)
);
@POST
@Path("/metrics")
@Consumes({"application/json","application/xml"})
public void addMetrics(@Suspended AsyncResponse asyncResponse, Collection<IdDataPoint> dataPoints) {
Set<RawNumericMetric> rawSet = new HashSet<>(dataPoints.size());
for (IdDataPoint dataPoint : dataPoints) {
RawNumericMetric rawMetric = new RawNumericMetric(dataPoint.getId(), dataPoint.getValue(),
dataPoint.getTimestamp());
rawSet.add(rawMetric);
@jsanda
jsanda / CalculateAggregate.java
Created May 14, 2014 18:42
bug in aggregation code
private AggregateNumericMetric calculateAggregate(Iterable<AggregateNumericMetric> metrics, long timestamp) {
double min = Double.NaN;
double max = min;
int count = 0;
ArithmeticMeanCalculator mean = new ArithmeticMeanCalculator();
for (AggregateNumericMetric metric : metrics) {
if (count == 0) {
min = metric.getMin();
max = metric.getMax();
@Test//(dependsOnMethods = "insertMetricsForOneId")
public void findRawMetricsForSingleId() throws Exception {
final String metricId = UUID.randomUUID().toString();
long timestamp1 = System.currentTimeMillis();
double value1 = 2.17;
ResultSetFuture insertFuture = dataAccess.insertData("raw", metricId, timestamp1,
ImmutableMap.of(DataType.RAW.ordinal(), value1), TTL);
// wait for the insert to finish
getUninterruptibly(insertFuture);
public class ServerTest extends MetricsTest {
private static final int TTL = 360;
private PlatformManager platformManager;
private DataAccess dataAccess;
private RawMetricMapper rawMapper;
@jsanda
jsanda / gist:7881321
Created December 9, 2013 21:31
RHQ's Cassandra schema for metrics data
CREATE TABLE rhq.raw_metrics (
schedule_id int,
time timestamp,
value double,
PRIMARY KEY (schedule_id, time)
) WITH COMPACT STORAGE;
CREATE TABLE rhq.one_hour_metrics (
schedule_id int,
time timestamp,