Package org.microproxy.starlark
Class ScriptStats
java.lang.Object
org.microproxy.starlark.ScriptStats
- All Implemented Interfaces:
org.microproxy.thirdparty.starlark.eval.StarlarkValue
public final class ScriptStats
extends Object
implements org.microproxy.thirdparty.starlark.eval.StarlarkValue
The
stats module: a script's own metrics, kept in the proxy's StatsRegistry as
script.<name> next to the proxy's (and shown wherever they are: Prometheus, statsd).
stats.counter("blocked").inc() counts; stats.gauge("queue").set(n) and
stats.histogram("score").record(x) keep a value and a distribution.
A script may make at most StatsRegistry.maxScriptStats() of them (100 by default):
further names get metrics that count nothing, and a warning is logged, so that names made from
request data cannot grow the registry without bound. Without metrics (--metrics) every
metric counts nothing. A metric found once may be kept in a global, as in BLOCKED =
stats.counter("blocked") at the top level, so a hook does not look it up by name per request.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA counter of a script.static final classA gauge of a script.static final classA histogram of a script. -
Method Summary
Modifier and TypeMethodDescriptionstats.counter(name): the counterscript.<name>.stats.gauge(name): the gaugescript.<name>.stats.histogram(name): the histogramscript.<name>.voidrepr(org.microproxy.thirdparty.starlark.eval.Printer printer, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Prints an official representation of object x.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.microproxy.thirdparty.starlark.eval.StarlarkValue
checkHashable, debugPrint, getStarlarkType, isAcyclic, isImmutable, str, truth
-
Method Details
-
counter
public ScriptStats.ScriptCounter counter(String name) throws org.microproxy.thirdparty.starlark.eval.EvalException stats.counter(name): the counterscript.<name>.- Parameters:
name- the name withinscript- Returns:
- the counter (one that counts nothing once the script stats are full)
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the name is not valid, or names a metric of another kind
-
gauge
public ScriptStats.ScriptGauge gauge(String name) throws org.microproxy.thirdparty.starlark.eval.EvalException stats.gauge(name): the gaugescript.<name>.- Parameters:
name- the name withinscript- Returns:
- the gauge (one that keeps nothing once the script stats are full)
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the name is not valid, or names a metric of another kind
-
histogram
public ScriptStats.ScriptHistogram histogram(String name) throws org.microproxy.thirdparty.starlark.eval.EvalException stats.histogram(name): the histogramscript.<name>.- Parameters:
name- the name withinscript- Returns:
- the histogram (one that records nothing once the script stats are full)
- Throws:
org.microproxy.thirdparty.starlark.eval.EvalException- if the name is not valid, or names a metric of another kind
-
repr
public void repr(org.microproxy.thirdparty.starlark.eval.Printer printer, org.microproxy.thirdparty.starlark.eval.StarlarkSemantics semantics) Description copied from interface:org.microproxy.thirdparty.starlark.eval.StarlarkValuePrints an official representation of object x.Convention is that the string should be parseable back to the value x. If this isn't feasible then it should be a short human-readable description enclosed in angled brackets, e.g.
"<foo object>".- Specified by:
reprin interfaceorg.microproxy.thirdparty.starlark.eval.StarlarkValue- Parameters:
printer- a printer to be used for formatting nested values.semantics- the interpreter settings used to format nested values
-