public static Collection<String> names(final Collection<Role> membersGauges) { final Collection<String> names = new ArrayList<String>(membersGauges.size()); for (final Role role : membersGauges) { names.add(role.getName()); } return names; }
@Override public Role findGaugeRole(final String name) { if (name== null || name.length()<1){ return null; } for (Role role: delegate.gauges()){ if (name.equals( role.getName() )){ return role; } } return null; } }
public static Collection<Role> findByPrefixAndUnit(final String prefix, final Unit unit) { final Collection<Role> roles = new LinkedList<Role>(); for (final Role role : Repository.INSTANCE.gauges()) { if (role.getName().startsWith(prefix) && unit.equals(role.getUnit())) { roles.add(role); } } return roles; }
public static Collection<Role> findBySuffixAndUnit(final String suffix, final Unit unit) { final Collection<Role> roles = new LinkedList<Role>(); for (final Role role : Repository.INSTANCE.gauges()) { if (role.getName().endsWith(suffix) && unit.equals(role.getUnit())) { roles.add(role); } } return roles; }
@Override public String getRole() { return delegate.getKey().getRole().getName(); }
private String id(final Role role, final String marker) { // order is really important here, see keyToRole() return cassandra.generateKey(role.getName(), role.getUnit().getName(), marker); }
public CounterGauge(final Counter counter, final MetricData metric) { this.counter = counter; this.metric = metric; this.role = new Role("counter-" + counter.getKey().getRole().getName() + "-" + counter.getKey().getName() + "-" + metric.name(), Unit.UNARY); }
protected String id(final Counter.Key key, final String marker) { return cassandra.generateKey(key.getRole().getName(), key.getRole().getUnit().getName(), key.getName(), marker); }
public StringBuilder gaugeSnapshot(final StringBuilder base, final long time, final Role role, final double value) { return buildEvent(base, GAUGE_TYPE, time, new MapBuilder() .add("value", value) .add("role", role.getName()) .add("unit", role.getUnit().getName()) .map()); }
public StringBuilder counterSnapshot(final Collection<Counter> instances) { final long ts = System.currentTimeMillis(); final StringBuilder events = newEventStream(); for (final Counter counter : instances) { buildEvent(events, COUNTER_TYPE, ts, new MapBuilder() .add(NAME, counter.getKey().getName()) .add(ROLE, counter.getKey().getRole().getName()) .add(UNIT, counter.getKey().getRole().getUnit().getName()) // minimum metrics to be able to aggregate counters later .add(CONCURRENCY, counter.currentConcurrency().intValue()) .add(MEAN, counter.getMean()) .add(VARIANCE, counter.getVariance()) .add(HITS, counter.getHits()) .add(MAX, counter.getMax()) .add(MIN, counter.getMin()) .add(SUM, counter.getSum()) .add(M_2, counter.getSecondMoment()) .map()); } return events; }
protected CassandraLeafCounter save(final CassandraLeafCounter counter, final String marker) { final Counter.Key key = counter.getKey(); final String id = id(key, marker); HFactory.createMutator(keyspace, StringSerializer.get()) // counter values .addInsertion(id, family, column("role", key.getRole().getName())) .addInsertion(id, family, column("key", key.getName())) .addInsertion(id, family, column("maxConcurrency", counter.getMaxConcurrency())) .addInsertion(id, family, column("variance", counter.getVariance())) .addInsertion(id, family, column("n", counter.getHits())) .addInsertion(id, family, column("max", counter.getMax())) .addInsertion(id, family, column("min", counter.getMin())) .addInsertion(id, family, column("sum", counter.getSum())) .addInsertion(id, family, column("m2", counter.getSecondMoment())) .addInsertion(id, family, column("mean", counter.getMean())) // counter in marker .addInsertion(marker, markerFamily, emptyColumn(id)) //save it .execute(); return counter; }