public SessionGauge(final String ctx, final AtomicLong counter) { this.role = new Role(SESSIONS_PREFIX + ctx, Unit.UNARY); this.counter = counter; }
public static <T> T processInstance(final T instance) { try { return internalProcessInstance(instance); } catch (final Exception e) { throw new SironaException(e); } }
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()); }
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 DelegatedCollectorGaugeDataStore() { try { delegateClass = Class.class.cast( DelegatedCollectorGaugeDataStore.class.getClassLoader().loadClass( // use this classloader and not TCCL to avoid issues Configuration.getProperty(Configuration.CONFIG_PROPERTY_PREFIX + "collector.gauge.store-class", InMemoryGaugeDataStore.class.getName()))); } catch (final ClassNotFoundException e) { throw new SironaException(e.getMessage(),e); } }
public static <T> T getInstance(final Class<T> clazz, String className) { try { Class<?> tClass = ClassLoaders.current().loadClass( className ); return (T) tClass.newInstance(); } catch ( Exception e ) { throw new SironaException( "cannot instantiante instance of '" + className + "'",e ); } }
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) }
protected GaugeDataStore newStore(final String marker) { try { try { final Constructor<? extends GaugeDataStore> cons = delegateClass.getConstructor(String.class); return cons.newInstance(marker); } catch (final Exception e) { // no-op: use default constructor } return delegateClass.newInstance(); } catch (final Exception e) { throw new SironaException(e); } }
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; } }
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 int hashCode() { if (hash == Integer.MIN_VALUE) { hash = name.hashCode(); hash = 31 * hash + role.hashCode(); } return hash; }
@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); }
@Override public double value() { try { return Number.class.cast(SERVER.getAttribute(name, attribute)).doubleValue(); } catch (final Exception e) { throw new SironaException(e); } } }
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); }