示例#1
0
  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Please specify the path to a properties file with your amazon keys.");
      return;
    }

    CloudWatchMetricObserver observer =
        new CloudWatchMetricObserver(
            "SampleObserver", "SampleDomain", new PropertiesCredentials(new File(args[0])));

    List<Tag> tags = new ArrayList<Tag>(2);
    tags.add(InjectableTag.HOSTNAME);
    tags.add(InjectableTag.IP);

    BasicExample example = new BasicExample(tags);

    DefaultMonitorRegistry.getInstance().register(Monitors.newObjectMonitor(example));

    PollCallable poller =
        new PollCallable(new MonitorRegistryMetricPoller(), BasicMetricFilter.MATCH_ALL);

    while (true) {
      example.counter.incrementAndGet();
      example.setSampleGauge(Math.round(Math.random() * 1000));
      observer.update(poller.call());
      Thread.sleep(60000);
    }
  }
示例#2
0
 private DynamicCounter() {
   super(BASE_CONFIG);
   final String expiration = System.getProperty(EXPIRATION_PROP, DEFAULT_EXPIRATION);
   final String expirationUnit = System.getProperty(EXPIRATION_PROP_UNIT, DEFAULT_EXPIRATION_UNIT);
   final long expirationValue = Long.parseLong(expiration);
   final TimeUnit expirationUnitValue = TimeUnit.valueOf(expirationUnit);
   final long expireAfterMs = expirationUnitValue.toMillis(expirationValue);
   counters = new ExpiringCache<>(expireAfterMs, StepCounter::new);
   DefaultMonitorRegistry.getInstance().register(this);
 }
示例#3
0
  @Test
  public void testRun() throws Exception {
    BasicCounter o1 = new BasicCounter("one");
    o1.increment();
    DefaultMonitorRegistry.getInstance().registerObject(o1);

    List<MetricObserver> observerList = new ArrayList<MetricObserver>(1);
    MemoryMetricObserver observer = new MemoryMetricObserver("test", 3);
    observerList.add(observer);

    MonitorRegistryMetricPoller poller =
        new MonitorRegistryMetricPoller(DefaultMonitorRegistry.getInstance());

    PollRunnable runnable = new PollRunnable(poller, BasicMetricFilter.MATCH_ALL, observerList);
    runnable.run();

    assertTrue(observer.getObservations().size() == 1);
    assertTrue(observer.getObservations().get(0).get(0).getValue().intValue() == 1);
  }
示例#4
0
 private DynamicTimer() {
   super(BASE_CONFIG);
   final String expiration = System.getProperty(EXPIRATION_PROP, DEFAULT_EXPIRATION);
   final String expirationUnit = System.getProperty(EXPIRATION_PROP_UNIT, DEFAULT_EXPIRATION_UNIT);
   final long expirationValue = Long.parseLong(expiration);
   final TimeUnit expirationUnitValue = TimeUnit.valueOf(expirationUnit);
   final long expireAfterMs = expirationUnitValue.toMillis(expirationValue);
   timers =
       new ExpiringCache<ConfigUnit, Timer>(
           expireAfterMs,
           new ConcurrentHashMapV8.Fun<ConfigUnit, Timer>() {
             @Override
             public Timer apply(final ConfigUnit configUnit) {
               return new BasicTimer(configUnit.config, configUnit.unit);
             }
           });
   DefaultMonitorRegistry.getInstance().register(this);
 }
  @Override
  public void initialize() {
    /* list of monitors */
    List<Monitor<?>> monitors = getServoMonitors();

    // publish metrics together under a single composite (it seems this name is ignored)
    MonitorConfig commandMetricsConfig =
        MonitorConfig.builder("HystrixCommand_" + key.name()).build();
    BasicCompositeMonitor commandMetricsMonitor =
        new BasicCompositeMonitor(commandMetricsConfig, monitors);

    DefaultMonitorRegistry.getInstance().register(commandMetricsMonitor);
    RollingCommandEventCounterStream.getInstance(key, properties)
        .startCachingStreamValuesIfUnstarted();
    CumulativeCommandEventCounterStream.getInstance(key, properties)
        .startCachingStreamValuesIfUnstarted();
    RollingCommandLatencyDistributionStream.getInstance(key, properties)
        .startCachingStreamValuesIfUnstarted();
    RollingCommandUserLatencyDistributionStream.getInstance(key, properties)
        .startCachingStreamValuesIfUnstarted();
    RollingCommandMaxConcurrencyStream.getInstance(key, properties)
        .startCachingStreamValuesIfUnstarted();
  }
 /** Creates a new instance using {@link com.netflix.servo.DefaultMonitorRegistry}. */
 public MonitorRegistryMetricPoller() {
   this(DefaultMonitorRegistry.getInstance(), 0L, TimeUnit.MILLISECONDS, true);
 }
示例#7
0
 /** Unregister all statistics from <tt>Servo</tt>. */
 public static void shutdown() {
   for (EurekaMonitors c : EurekaMonitors.values()) {
     DefaultMonitorRegistry.getInstance().unregister(Monitors.newObjectMonitor(c.name(), c));
   }
 }