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.

  • Method Details

    • counter

      public ScriptStats.ScriptCounter counter(String name) throws org.microproxy.thirdparty.starlark.eval.EvalException
      stats.counter(name): the counter script.<name>.
      Parameters:
      name - the name within script
      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 gauge script.<name>.
      Parameters:
      name - the name within script
      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 histogram script.<name>.
      Parameters:
      name - the name within script
      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.StarlarkValue
      Prints 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:
      repr in interface org.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