com.yammer.metrics.core.VirtualMachineMetrics Java Examples

The following examples show how to use com.yammer.metrics.core.VirtualMachineMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestMetricsService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetVirtualMachineMetrics() {
    final VirtualMachineMetrics virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    final MetricsService service = new MetricsService();

    final Map<String,String> metrics = service.getMetrics(virtualMachineMetrics);
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE));
}
 
Example #2
Source File: TestMetricsService.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetVirtualMachineMetrics() {
    final VirtualMachineMetrics virtualMachineMetrics = VirtualMachineMetrics.getInstance();

    final Map<String, Double> metrics = metricsService.getJVMMetrics(virtualMachineMetrics);
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE));
}
 
Example #3
Source File: TestDataDogReportingTask.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private void initContexts() {
    configurationContext = Mockito.mock(ConfigurationContext.class);
    context = Mockito.mock(ReportingContext.class);
    Mockito.when(context.getProperty(DataDogReportingTask.ENVIRONMENT))
            .thenReturn(new MockPropertyValue(env, null));
    Mockito.when(context.getProperty(DataDogReportingTask.METRICS_PREFIX))
            .thenReturn(new MockPropertyValue(prefix, null));
    Mockito.when(context.getProperty(DataDogReportingTask.API_KEY))
            .thenReturn(new MockPropertyValue("agent", null));
    Mockito.when(context.getProperty(DataDogReportingTask.DATADOG_TRANSPORT))
            .thenReturn(new MockPropertyValue("DataDog Agent", null));
    EventAccess eventAccess = Mockito.mock(EventAccess.class);
    Mockito.when(eventAccess.getControllerStatus()).thenReturn(status);
    Mockito.when(context.getEventAccess()).thenReturn(eventAccess);

    logger = Mockito.mock(Logger.class);
    initContext = Mockito.mock(ReportingInitializationContext.class);
    Mockito.when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString());
    //Mockito.when(initContext.getLogger()).thenReturn(logger);
    metricsMap = new ConcurrentHashMap<>();
    metricRegistry = Mockito.mock(MetricRegistry.class);
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    metricsService = Mockito.mock(MetricsService.class);

}
 
Example #4
Source File: TestMetricsService.java    From nifi-prometheus-reporter with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetVirtualMachineMetrics() {
    final VirtualMachineMetrics virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    final MetricsService service = new MetricsService();

    final Map<String, String> metrics = service.getMetrics(virtualMachineMetrics);
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_UPTIME));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_NON_HEAP_USAGE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_RUNNABLE));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_BLOCKED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TIMED_WAITING));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_STATES_TERMINATED));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_DAEMON_THREAD_COUNT));
    Assert.assertTrue(metrics.containsKey(MetricNames.JVM_FILE_DESCRIPTOR_USAGE));
}
 
Example #5
Source File: ScriptedReportingTask.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Performs setup operations when the processor is scheduled to run. This includes evaluating the processor's
 * properties, as well as reloading the script (from file or the "Script Body" property)
 *
 * @param context the context in which to perform the setup operations
 */
@OnScheduled
public void setup(final ConfigurationContext context) {
    scriptingComponentHelper.setScriptEngineName(context.getProperty(scriptingComponentHelper.SCRIPT_ENGINE).getValue());
    scriptingComponentHelper.setScriptPath(context.getProperty(ScriptingComponentUtils.SCRIPT_FILE).evaluateAttributeExpressions().getValue());
    scriptingComponentHelper.setScriptBody(context.getProperty(ScriptingComponentUtils.SCRIPT_BODY).getValue());
    String modulePath = context.getProperty(ScriptingComponentUtils.MODULES).getValue();
    if (!StringUtils.isEmpty(modulePath)) {
        scriptingComponentHelper.setModules(modulePath.split(","));
    } else {
        scriptingComponentHelper.setModules(new String[0]);
    }
    // Create a script engine for each possible task
    scriptingComponentHelper.setup(1, getLogger());
    scriptToRun = scriptingComponentHelper.getScriptBody();

    try {
        String scriptPath = scriptingComponentHelper.getScriptPath();
        if (scriptToRun == null && scriptPath != null) {
            try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) {
                scriptToRun = IOUtils.toString(scriptStream, Charset.defaultCharset());
            }
        }
    } catch (IOException ioe) {
        throw new ProcessException(ioe);
    }

    vmMetrics = VirtualMachineMetrics.getInstance();
}
 
Example #6
Source File: AmbariReportingTask.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(final ConfigurationContext context) throws IOException {
    final Map<String, ?> config = Collections.emptyMap();
    factory = Json.createBuilderFactory(config);
    client = createClient();
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    previousMetrics = null;
}
 
Example #7
Source File: DataDogReportingTask.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public void setup(final ConfigurationContext context) {
    metricsService = getMetricsService();
    ddMetricRegistryBuilder = getMetricRegistryBuilder();
    metricRegistry = getMetricRegistry();
    metricsMap = getMetricsMap();
    metricsPrefix = METRICS_PREFIX.getDefaultValue();
    environment = ENVIRONMENT.getDefaultValue();
    virtualMachineMetrics = VirtualMachineMetrics.getInstance();
    ddMetricRegistryBuilder.setMetricRegistry(metricRegistry)
            .setTags(metricsService.getAllTagsList());
}
 
Example #8
Source File: TestDataDogReportingTask.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnTrigger() throws InitializationException, IOException {
    DataDogReportingTask dataDogReportingTask = new TestableDataDogReportingTask();
    dataDogReportingTask.initialize(initContext);
    dataDogReportingTask.setup(configurationContext);
    dataDogReportingTask.onTrigger(context);

    verify(metricsService, atLeast(1)).getProcessorMetrics(Mockito.<ProcessorStatus>any());
    verify(metricsService, atLeast(1)).getJVMMetrics(Mockito.<VirtualMachineMetrics>any());
}
 
Example #9
Source File: PrometheusMetricsFactory.java    From nifi-prometheus-reporter with Apache License 2.0 4 votes vote down vote up
public static CollectorRegistry createJvmMetrics(VirtualMachineMetrics jvmMetrics) {
    JVM_HEAP.labels("used").set(jvmMetrics.heapUsed());
    JVM_HEAP.labels("usage").set(jvmMetrics.heapUsage());
    JVM_HEAP.labels("non_usage").set(jvmMetrics.nonHeapUsage());

    JVM_THREAD.labels("count").set(jvmMetrics.threadCount());
    JVM_THREAD.labels("daemon_count").set(jvmMetrics.daemonThreadCount());

    JVM_STATUS.labels("uptime").set(jvmMetrics.uptime());
    JVM_STATUS.labels("file_descriptor").set(jvmMetrics.fileDescriptorUsage());
    JVM_STATUS.labels("total_init").set(jvmMetrics.totalInit());
    JVM_STATUS.labels("total_max").set(jvmMetrics.totalMax());
    JVM_STATUS.labels("total_committed").set(jvmMetrics.totalCommitted());
    JVM_STATUS.labels("total_used").set(jvmMetrics.totalUsed());

    // Append thread states
    jvmMetrics.threadStatePercentages()
            .forEach((state, usage) -> {
                String name = state.name().toLowerCase().replaceAll("\\s", "_");
                JVM_THREAD.labels("state_" + name).set(usage);
            });

    // Append GC stats
    jvmMetrics.garbageCollectors()
            .forEach((name, stat) -> {
                name = name.toLowerCase().replaceAll("\\s", "_");
                JVM_GC.labels(name + "_runs").set(stat.getRuns());
                JVM_GC.labels(name + "_time_ms").set(stat.getTime(TimeUnit.MILLISECONDS));
            });

    // Append pool stats
    jvmMetrics.memoryPoolUsage()
            .forEach((name, usage) -> {
                name = name.toLowerCase().replaceAll("\\s", "_");
                JVM_POOL.labels("mem_pool_" + name).set(usage);
            });
    jvmMetrics.getBufferPoolStats()
            .forEach((name, stat) -> {
                name = name.toLowerCase().replaceAll("\\s", "_");
                JVM_POOL.labels("buff_pool_" + name + "_count").set(stat.getCount());
                JVM_POOL.labels("buff_pool_" + name + "_mem_used").set(stat.getMemoryUsed());
                JVM_POOL.labels("buff_pool_" + name + "_capacity").set(stat.getTotalCapacity());
            });

    return JVM_REGISTRY;
}