public SessionGauge(final String ctx, final AtomicLong counter) { this.role = new Role(SESSIONS_PREFIX + ctx, Unit.UNARY); this.counter = counter; }
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; }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; final Key key = (Key) o; return name.equals(key.name) && role.equals(key.role); }
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 void add(final double delta, final Unit deltaUnit) { add(key.getRole().getUnit().convert(delta, deltaUnit)); }
@Override public int hashCode() { if (hash == Integer.MIN_VALUE) { hash = name.hashCode(); hash = 31 * hash + role.hashCode(); } return hash; }
@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 void add(final double delta, Unit unit) { add(key.getRole().getUnit().convert(delta, unit)); }
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; }
public JMXAttributeGaugeBase(final ObjectName name, final String attribute, final String role, final Unit unit) { this.name = name; this.attribute = attribute; this.role = new Role(role, unit); }
@Override public String getRole() { return delegate.getKey().getRole().getName(); }
private static StatusGauge statusGauge(final String prefix, final ConcurrentMap<Integer, StatusGauge> gauges, final int status) { final StatusGauge gauge = gauges.get(status); if (gauge != null) { return gauge; } final StatusGauge newGauge = new StatusGauge(new Role(prefix + "-HTTP-" + Integer.toString(status), Unit.UNARY)); final StatusGauge old = gauges.putIfAbsent(status, newGauge); if (old != null) { return old; } return newGauge; } }
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; }
@Override public void contextInitialized(final ServletContextEvent sce) { String contextPath = sce.getServletContext().getContextPath(); if (contextPath == null || contextPath.isEmpty()) { contextPath = "/"; } counter = Repository.INSTANCE.getCounter(new Counter.Key(new Role("session-durations", Unit.Time.NANOSECOND), "session-durations-" + contextPath)); gauge = new SessionGauge(contextPath, sessionNumber); Repository.INSTANCE.addGauge(gauge); }
private Role keyToRole(final String key) { final String[] segments = key.split(cassandra.keySeparator()); return new Role(segments[0], Unit.get(segments[1])); // no need of segments[2] (= marker) }
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; }