Class Sampler

java.lang.Object
io.kubfly.sdk.api.usage.sampler.Sampler

public final class Sampler extends Object
Takes Usage snapshots. On Linux the host comes from /proc (stat, loadavg, meminfo) and the container from the cgroup v2 of the process (/proc/self/cgroup under /sys/fs/cgroup); elsewhere only the JVM management beans are used. The platform part always comes from the JVM, and so do the disks (FileStore) on every system: the root / and the paths of KUBFLY_USAGE_DISKS (Config.DISKS). A part that cannot be read becomes unknown (NaN or -1); a snapshot never fails because of it.

A sampler keeps the previous processor counters to compute shares over the interval, so one sampler serves one sequence of snapshots; sample() is thread-safe.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Sampler(Path proc, Path cgroups, boolean linux)
    A sampler over given roots, with the root file system only: tests pass a prepared directory instead of /proc and /sys/fs/cgroup.
    Sampler(Path proc, Path cgroups, boolean linux, List<String> disks)
    A sampler over given roots and file systems.
  • Method Summary

    Modifier and Type
    Method
    Description
    The description of a new deadlock found by the last snapshot, once: None if there is none or it was already taken (the same set of threads is not described again; a set that changes is).
    Takes a snapshot.
    static Sampler
    The sampler of this machine: /proc and /sys/fs/cgroup on Linux, the JVM elsewhere.
    void
    watch(long limit, Consumer<String> warn)
    Subscribes to the collection notifications of the JVM, once: they give the longest pause of an interval, full and explicit collections and the heap after a collection, and report a full collection or a pause of at least limit milliseconds at once, on the notification thread of the JVM (not on application threads).

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Sampler

      public Sampler(Path proc, Path cgroups, boolean linux)
      A sampler over given roots, with the root file system only: tests pass a prepared directory instead of /proc and /sys/fs/cgroup.
      Parameters:
      proc - the root of /proc
      cgroups - the root of the cgroup v2 hierarchy (/sys/fs/cgroup)
      linux - whether to read /proc and cgroup (otherwise only the JVM)
    • Sampler

      public Sampler(Path proc, Path cgroups, boolean linux, List<String> disks)
      A sampler over given roots and file systems.
      Parameters:
      proc - the root of /proc
      cgroups - the root of the cgroup v2 hierarchy (/sys/fs/cgroup)
      linux - whether to read /proc and cgroup (otherwise only the JVM)
      disks - the paths whose file systems are sampled, in order
  • Method Details

    • system

      public static Sampler system()
      The sampler of this machine: /proc and /sys/fs/cgroup on Linux, the JVM elsewhere.
      Returns:
      the sampler
    • sample

      public Usage sample()
      Takes a snapshot.
      Returns:
      the snapshot
    • watch

      public void watch(long limit, Consumer<String> warn)
      Subscribes to the collection notifications of the JVM, once: they give the longest pause of an interval, full and explicit collections and the heap after a collection, and report a full collection or a pause of at least limit milliseconds at once, on the notification thread of the JVM (not on application threads).
      Parameters:
      limit - the shortest pause reported, in milliseconds
      warn - receives the description of a full collection or a long pause
    • deadlock

      public Option<String> deadlock()
      The description of a new deadlock found by the last snapshot, once: None if there is none or it was already taken (the same set of threads is not described again; a set that changes is).
      Returns:
      the description, or None