Giter VIP home page Giter VIP logo

micrometer-jvm-extras's Introduction

micrometer-jvm-extras

A set of additional JVM process metrics for micrometer.io.

Apache License 2 Build status Quality Gate Status Coverage Maven Central

Motivation

  • get "real" memory usage of the JVM beyond its managed parts
  • get ahold of that info from within the JVM in environments where you can't instrument from the outside (e.g. PaaS)

Usage

<dependency>
    <groupId>io.github.mweirauch</groupId>
    <artifactId>micrometer-jvm-extras</artifactId>
    <version>x.y.z</version>
</dependency>
    /* Plain Java */
    final MeterRegistry registry = new SimpleMeterRegistry();
    new ProcessMemoryMetrics().bindTo(registry);
    new ProcessThreadMetrics().bindTo(registry);
    /* With Spring */
    @Bean
    public MeterBinder processMemoryMetrics() {
        return new ProcessMemoryMetrics();
    }

    @Bean
    public MeterBinder processThreadMetrics() {
        return new ProcessThreadMetrics();
    }

Available Metrics

ProcessMemoryMetrics

ProcessMemoryMetrics reads process-level memory information from /proc/self/status. All Meters are reporting in bytes.

Please note that procfs is only available on Linux-based systems.

  • process.memory.vss: Virtual set size. The amount of virtual memory the process can access. Mostly irrelevant, but included for completeness sake.
  • process.memory.rss: Resident set size. The amount of process memory currently in RAM.
  • process.memory.swap: The amount of process memory paged out to swap.

ProcessThreadMetrics

ProcessThreadMetrics reads process-level thread information from /proc/self/status.

Please note that procfs is only available on Linux-based systems.

  • process.threads: The number of process threads as seen by the operating system.
  • process.threads.context.switches.voluntary: The accumulated number of voluntary context switches since application start. A voluntary context switch occurs when a thread is in a waiting or blocked state and the scheduler switches control to another thread.
  • process.threads.context.switches.nonvoluntary: The accumulated number of non-voluntary context switches since application start. An involuntary context switch occurs when a thread consumed the whole time slice it was granted from the scheduler. The thread is suspended and control is switched to another thread.

Notes

  • procfs data is cached for 1000ms in order to relief the filesystem pressure when Meters based on this data are queried by the registry one after another on collection run.
  • Snapshot builds are pushed to Sonatype Nexus Snapshot Repository on successful main builds.

micrometer-jvm-extras's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar mweirauch avatar wyhasany avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

micrometer-jvm-extras's Issues

0.2.1

Maintenance release.

0.2.2

A small bugfix release with regard to double registration of process threads under the umbrella of 'ProcessMemoryMetrics'.

Number of threads metered twice

I noticed my prometheus exports had 2 thread counts listed:

# HELP process_threads The number of process threads
# TYPE process_threads gauge
process_threads 486.0

and

# HELP process_memory_threads_bytes  
# TYPE process_memory_threads_bytes gauge
process_memory_threads_bytes 486.0

The last one appears to be from the following:

Where KEY.values() contains the memory values and THREADS

I am not a 'Dev', but use this to observe monitoring my rss and vss in docker.

When I implement a simple hello world api, I use this JVM library as extra metrics to observe my rss and vss in docker. I found one issue when prometheus return me with -1.

package com.redhat.examples.hellospringboot;

/* annotations: http://zetcode.com/springboot/bean/ */
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import io.micrometer.core.instrument.Gauge;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.github.mweirauch.micrometer.jvm.extras.*;

@SpringBootApplication
public class HelloSpringbootApplication {

        /* With Spring */
        @Bean
        public MeterBinder processMemoryMetrics() {
                return new ProcessMemoryMetrics();
        }

        @Bean
        public MeterBinder processThreadMetrics() {
                return new ProcessThreadMetrics();
        }

        public static void main(String[] args) {
                SpringApplication.run(HelloSpringbootApplication.class, args);
        }

}
# curl http://localhost:8080/actuator/prometheus -sq | grep ^process
process_files_open_files 63.0
process_uptime_seconds 15.319
process_memory_rss_bytes -1.0
process_cpu_usage 0.0011735164450160725
process_files_max_files 10240.0
process_start_time_seconds 1.583642854501E9
process_memory_threads_bytes -1.0
process_threads -1.0
process_memory_vss_bytes -1.0
process_memory_swap_bytes -1.0

What would be a root cause?

0.2.0

This release removes support for the proportional set size metrics 'pss' and 'swappss'. They were quite expensive to collect and added to the metrics collection overhead quite noticeably with a CPU usage and memory allocation penalty. The go-to metrics 'rss' and 'swap' are still there of course.

Java module

Please make this library a Java module. That will make it easier to use the library in downstream libs and apps that are Java modules themselves. Probably the easiest way to do it is to make the library an automatic module.

ProcessMemoryMetrics garbage-collected in Spring Configuration

Given the following construct ...

@Configuration
@RequiredArgsConstructor
public class MicrometerConfiguration {
    private final MeterRegistry registry;
    @PostConstruct
    public void postConstruct() {
        new ProcessMemoryMetrics().bindTo(registry);
    }
}

... the instance is GCed and the WeakReference in the MeterRegistry is returning null. Resulting in NaN metric values.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.