Add group name to all PromStats
Some checks failed
Java CI / build (push) Has been cancelled
Java CI / javadoc-latest (push) Has been cancelled
Java CI / build-java7 (push) Has been cancelled
Java with IzPack Snapshot Setup / setup (push) Has been cancelled

This commit is contained in:
zzz
2025-05-03 12:15:23 -04:00
parent d1b24274c7
commit 8c4fd32450
10 changed files with 56 additions and 45 deletions

View File

@@ -7,12 +7,12 @@ package net.i2p.stat.prometheus;
*/
public abstract class Counter extends PromStat {
public Counter(String name, String desc, Unit unit) {
super(name, desc, Type.COUNTER, unit);
public Counter(String name, String desc, String group, Unit unit) {
super(name, desc, group, Type.COUNTER, unit);
}
public Counter(String name, String desc, Unit unit, String label, String... values) {
super(name, desc, Type.COUNTER, unit, label, values);
public Counter(String name, String desc, String group, Unit unit, String label, String... values) {
super(name, desc, group, Type.COUNTER, unit, label, values);
}
public abstract void increment();

View File

@@ -10,12 +10,12 @@ public class FCounter extends Counter implements FloatConsumer, FloatSupplier {
private final AtomicFloat[] a;
public FCounter(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public FCounter(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public FCounter(String name, String desc, Unit unit, String label, String... values) {
super(name, desc, unit, label, values);
public FCounter(String name, String desc, String group, Unit unit, String label, String... values) {
super(name, desc, group, unit, label, values);
a = new AtomicFloat[label != null ? values.length : 1];
for (int i = 0; i < a.length; i++) {
a[i] = new AtomicFloat();

View File

@@ -11,16 +11,16 @@ public class FGauge extends Gauge implements FloatConsumer, FloatSupplier {
private final AtomicFloat[] a;
private final FloatSupplier s;
public FGauge(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public FGauge(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public FGauge(String name, String desc, Unit unit, FloatSupplier supplier) {
this(name, desc, unit, supplier, (String) null);
public FGauge(String name, String desc, String group, Unit unit, FloatSupplier supplier) {
this(name, desc, group, unit, supplier, (String) null);
}
public FGauge(String name, String desc, Unit unit, FloatSupplier supplier, String label, String... values) {
super(name, desc, unit);
public FGauge(String name, String desc, String group, Unit unit, FloatSupplier supplier, String label, String... values) {
super(name, desc, group, unit);
a = new AtomicFloat[label != null ? values.length : 1];
for (int i = 0; i < a.length; i++) {
a[i] = new AtomicFloat();

View File

@@ -7,12 +7,12 @@ package net.i2p.stat.prometheus;
*/
public abstract class Gauge extends PromStat {
public Gauge(String name, String desc, Unit unit) {
super(name, desc, Type.GAUGE, unit);
public Gauge(String name, String desc, String group, Unit unit) {
super(name, desc, group, Type.GAUGE, unit);
}
public Gauge(String name, String desc, Unit unit, String label, String... values) {
super(name, desc, Type.GAUGE, unit, label, values);
public Gauge(String name, String desc, String group, Unit unit, String label, String... values) {
super(name, desc, group, Type.GAUGE, unit, label, values);
}
public abstract void setValue(int value);

View File

@@ -13,12 +13,12 @@ public class ICounter extends Counter implements IntConsumer, IntSupplier {
private final AtomicIntegerArray a;
private final AtomicInteger c;
public ICounter(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public ICounter(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public ICounter(String name, String desc, Unit unit, String label, String... values) {
super(name, desc, unit, label, values);
public ICounter(String name, String desc, String group, Unit unit, String label, String... values) {
super(name, desc, group, unit, label, values);
if (label != null) {
a = new AtomicIntegerArray(values.length);
c = null;

View File

@@ -14,16 +14,16 @@ public class IGauge extends Gauge implements IntConsumer, IntSupplier {
private final AtomicInteger c;
private final IntSupplier s;
public IGauge(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public IGauge(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public IGauge(String name, String desc, Unit unit, IntSupplier supplier) {
this(name, desc, unit, supplier, null);
public IGauge(String name, String desc, String group, Unit unit, IntSupplier supplier) {
this(name, desc, group, unit, supplier, null);
}
public IGauge(String name, String desc, Unit unit, IntSupplier supplier, String label, String... values) {
super(name, desc, unit, label, values);
public IGauge(String name, String desc, String group, Unit unit, IntSupplier supplier, String label, String... values) {
super(name, desc, group, unit, label, values);
if (label != null) {
a = new AtomicIntegerArray(values.length);
c = null;

View File

@@ -17,16 +17,16 @@ public class Info extends PromStat implements IntSupplier, MapSupplier, MapConsu
/**
* Map returned by getValues() will be a ConcurrentHashMap
*/
public Info(String name, String desc) {
this(name, desc, null);
public Info(String name, String desc, String group) {
this(name, desc, group, null);
}
/**
* @param labels use caution, use a ConcurrentHashMap if setValue() or accept()
* will be called later to add label names or change the label values
*/
public Info(String name, String desc, Map<String, String> labels) {
super(name, desc, Type.GAUGE, Unit.NONE);
public Info(String name, String desc, String group, Map<String, String> labels) {
super(name, desc, group, Type.GAUGE, Unit.NONE);
this.labels = (labels != null) ? labels : new ConcurrentHashMap<String, String>(4);
}

View File

@@ -14,12 +14,12 @@ public class LCounter extends Counter implements LongConsumer, LongSupplier {
private final AtomicLongArray a;
private final AtomicLong c;
public LCounter(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public LCounter(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public LCounter(String name, String desc, Unit unit, String label, String... values) {
super(name, desc, unit, label, values);
public LCounter(String name, String desc, String group, Unit unit, String label, String... values) {
super(name, desc, group, unit, label, values);
if (label != null) {
a = new AtomicLongArray(values.length);
c = null;

View File

@@ -14,16 +14,16 @@ public class LGauge extends Gauge implements LongConsumer, LongSupplier {
private final AtomicLong c;
private final LongSupplier s;
public LGauge(String name, String desc, Unit unit) {
this(name, desc, unit, null);
public LGauge(String name, String desc, String group, Unit unit) {
this(name, desc, group, unit, null);
}
public LGauge(String name, String desc, Unit unit, LongSupplier supplier) {
this(name, desc, unit, supplier, null);
public LGauge(String name, String desc, String group, Unit unit, LongSupplier supplier) {
this(name, desc, group, unit, supplier, null);
}
public LGauge(String name, String desc, Unit unit, LongSupplier supplier, String label, String... values) {
super(name, desc, unit, label, values);
public LGauge(String name, String desc, String group, Unit unit, LongSupplier supplier, String label, String... values) {
super(name, desc, group, unit, label, values);
if (label != null) {
a = new AtomicLongArray(values.length);
c = null;

View File

@@ -15,6 +15,7 @@ public abstract class PromStat {
private final String desc;
private final String name;
private final String promName;
private final String groupName;
private final String labelName;
private final String[] labelValues;
private final Type type;
@@ -24,22 +25,25 @@ public abstract class PromStat {
* No label
*
* @param name [a-zA-Z0-9_.] only. '.' will be replaced with '_' for getPromName()
* @param group use same group names as RateStat and FrequencyStat
*/
public PromStat(String name, String description, Type type, Unit unit) {
this(name, description, type, unit, null);
public PromStat(String name, String description, String group, Type type, Unit unit) {
this(name, description, group, type, unit, null);
}
/*
* With one label and one or more values
*
* @param name [a-zA-Z0-9_.] only. '.' will be replaced with '_' for getPromName()
* @param group use same group names as RateStat and FrequencyStat
* @param label [a-zA-Z0-9_.] only. '.' will be replaced with '_' for getLabelName()
* for example "dir"
* @param values for example "in", "out"
*/
public PromStat(String name, String description, Type type, Unit unit, String label, String... values) {
public PromStat(String name, String description, String group, Type type, Unit unit, String label, String... values) {
this.name = name;
desc = description;
groupName = group;
this.type = type;
this.unit = unit;
String p = fixup(name);
@@ -74,6 +78,13 @@ public abstract class PromStat {
return promName;
}
/*
* @return same group names as RateStat and FrequencyStat
*/
public String getGroupName() {
return groupName;
}
/**
* @return may be null
*/