Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F85823860
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
17 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/prometheus/metric/gauge.ex b/lib/prometheus/metric/gauge.ex
index d1d30fb..22356c0 100644
--- a/lib/prometheus/metric/gauge.ex
+++ b/lib/prometheus/metric/gauge.ex
@@ -1,197 +1,197 @@
defmodule Prometheus.Metric.Gauge do
@moduledoc """
Gauge metric, to report instantaneous values.
Gauge is a metric that represents a single numerical value that can
arbitrarily go up and down.
A Gauge is typically used for measured values like temperatures or current
memory usage, but also "counts" that can go up and down, like the number of
running processes.
Example use cases for Gauges:
- Inprogress requests;
- Number of items in a queue;
- Free memory;
- Total memory;
- Temperature.
Example:
```
defmodule MyPoolInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup() do
Gauge.declare([name: :my_pool_size,
help: "Pool size."])
Gauge.declare([name: :my_pool_checked_out,
help: "Number of sockets checked out from the pool"])
end
def set_size(size) do
Gauge.set([name: :my_pool_size], size)
end
def track_checked_out_sockets(checkout_fun) do
Gauge.track_inprogress([name: :my_pool_checked_out], checkout_fun)
end
end
```
"""
use Prometheus.Erlang, :prometheus_gauge
@doc """
Creates a gauge using `spec`.
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.<br>
Raises `Prometheus.Error.MFAlreadyExists` if a gauge with the same `spec` exists.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a gauge using `spec`.
If a gauge with the same `spec` exists returns `false`.
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Sets the gauge identified by `spec` to `value`.
Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro set(spec, value) do
Erlang.metric_call(spec, [value])
end
@doc """
Increments the gauge identified by `spec` by `value`.
Raises `Prometheus.Error.InvalidValue` exception if `value` isn't an integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro inc(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Decrements the gauge identified by `spec` by `value`.
Raises `Prometheus.Error.InvalidValue` exception if `value` isn't an integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro dec(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Increments the gauge identified by `spec` by `value`.
If `value` happened to be a float number even one time(!) you shouldn't use `inc/2` or `dec/2` after dinc.
Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro dinc(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Decrements the gauge identified by `spec` by `value`.
If `value` happened to be a float number even one time(!) you shouldn't use `inc/2` or `dec/2` after ddec.
Raises `Prometheus.Error.InvalidValue` exception if `value` isn't a number.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a counter for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro ddec(spec, value \\ 1) do
Erlang.metric_call(spec, [value])
end
@doc """
Sets the gauge identified by `spec` to the current unixtime.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro set_to_current_time(spec) do
Erlang.metric_call(spec)
end
@doc """
Tracks inprogress functions.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro track_inprogress(spec, fun) do
Erlang.metric_call(spec, [fun])
end
@doc """
- Tracks function execution duration.
+ Tracks the amount of seconds spent executing `fun`.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro set_duration(spec, fun) do
Erlang.metric_call(spec, [fun])
end
@doc """
Removes gauge series identified by spec.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the gauge identified by `spec`.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the gauge identified by `spec`.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
diff --git a/lib/prometheus/metric/histogram.ex b/lib/prometheus/metric/histogram.ex
index 706fdb1..4fa61b2 100644
--- a/lib/prometheus/metric/histogram.ex
+++ b/lib/prometheus/metric/histogram.ex
@@ -1,150 +1,150 @@
defmodule Prometheus.Metric.Histogram do
@moduledoc """
A Histogram tracks the size and number of events in buckets.
You can use Histograms for aggregatable calculation of quantiles.
Example use cases for Histograms:
- Response latency;
- Request size.
Histogram expects `buckets` key in a metric spec. Buckets can be:
- a list of numbers in increasing order;
- on of the generate specs (essentially shortcuts for `Prometheus.Buckets` macros)
- :default;
- {:linear, start, step, count};
- {:exponential, start, step, count}.
Example:
```
defmodule ExampleInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup do
Histogram.new([name: :http_request_duration_milliseconds,
labels: [:method],
buckets: [100, 300, 500, 750, 1000],
help: "Http Request execution time"])
end
def instrument(%{time: time, method: method}) do
Histogram.observe([name: :http_request_duration_milliseconds, labels: [method]], time)
end
end
```
"""
use Prometheus.Erlang, :prometheus_histogram
@doc """
Creates a histogram using `spec`.
Histogram cannot have a label named "le".
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
Raises `Prometheus.Error.MFAlreadyExists` if a histogram with the same `spec` exists.
Histogram Specific exceptions:
Raises `Prometheus.Error.HistogramNoBuckets` if buckets are missing, not a list, empty list or not known buckets spec.<br>
Raises `Prometheus.Error.HistogramInvalidBuckets` if buckets aren't in increasing order.<br>
Raises `Prometheus.Error.HistogramInvalidBound` if bucket bound isn't a number.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a histogram using `spec`.
Histogram cannot have a label named "le".
If a histogram with the same `spec` exists returns `false`.
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
Histogram Specific exceptions:
Raises `Prometheus.Error.HistogramNoBuckets` if buckets are missing, not a list, empty list or not known buckets spec.<br>
Raises `Prometheus.Error.HistogramInvalidBuckets` if buckets aren't in increasing order.<br>
Raises `Prometheus.Error.HistogramInvalidBound` if bucket bound isn't a number.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Observes the given amount.
Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro observe(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the given amount.
If `amount` happened to be a float number even one time(!) you shouldn't use `observe/2` after dobserve.
Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro dobserve(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
- Observes the amount of microseconds spent executing `fun`.
+ Observes the amount of seconds spent executing `fun`.
Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro observe_duration(spec, fun) do
Erlang.metric_call(spec, [fun])
end
@doc """
Removes histogram series identified by spec.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the histogram identified by `spec`.
Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the histogram identified by `spec`. If there is no histogram for
given labels combination, returns `:undefined`.
Raises `Prometheus.Error.UnknownMetric` exception if a histogram for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
diff --git a/lib/prometheus/metric/summary.ex b/lib/prometheus/metric/summary.ex
index b9c7698..af4980b 100644
--- a/lib/prometheus/metric/summary.ex
+++ b/lib/prometheus/metric/summary.ex
@@ -1,135 +1,135 @@
defmodule Prometheus.Metric.Summary do
@moduledoc """
Summary metric, to track the size of events.
Example use cases for Summaries:
- Response latency;
- Request size;
- Response size.
Example:
```
defmodule MyProxyInstrumenter do
use Prometheus.Metric
## to be called at app/supervisor startup.
## to tolerate restarts use declare.
def setup() do
Summary.declare([name: :request_size_bytes,
help: "Request size in bytes."])
Summary.declare([name: :response_size_bytes,
help: "Response size in bytes."])
end
def observe_request(size) do
Summary.observe([name: :request_size_bytes], size)
end
def observe_response(size) do
Summary.observe([name: :response_size_bytes], size)
end
end
```
"""
use Prometheus.Erlang, :prometheus_summary
@doc """
Creates a summary using `spec`.
Summary cannot have a label named "quantile".
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.<br>
Raises `Prometheus.Error.MFAlreadyExists` if a summary with the same `spec` already exists.
"""
defmacro new(spec) do
Erlang.call([spec])
end
@doc """
Creates a summary using `spec`.
Summary cannot have a label named "quantile".
If a summary with the same `spec` exists returns `false`.
Raises `Prometheus.Error.MissingMetricSpecKey` if required `spec` key is missing.<br>
Raises `Prometheus.Error.InvalidMetricName` if metric name is invalid.<br>
Raises `Prometheus.Error.InvalidMetricHelp` if help is invalid.<br>
Raises `Prometheus.Error.InvalidMetricLabels` if labels isn't a list.<br>
Raises `Prometheus.Error.InvalidMetricName` if label name is invalid.
"""
defmacro declare(spec) do
Erlang.call([spec])
end
@doc """
Observes the given amount.
Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro observe(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
Observes the given amount.
If `amount` happened to be a float number even one time(!) you shouldn't use `observe/2` after dobserve.
Raises `Prometheus.Error.InvalidValue` exception if `amount` isn't a positive integer.<br>
Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro dobserve(spec, amount \\ 1) do
Erlang.metric_call(spec, [amount])
end
@doc """
- Observes the amount of microseconds spent executing `fun`.
+ Observes the amount of seconds spent executing `fun`.
Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro observe_duration(spec, fun) do
Erlang.metric_call(spec, [fun])
end
@doc """
Removes summary series identified by spec.
Raises `Prometheus.Error.UnknownMetric` exception if a gauge for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro remove(spec) do
Erlang.metric_call(spec)
end
@doc """
Resets the value of the summary identified by `spec`.
Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro reset(spec) do
Erlang.metric_call(spec)
end
@doc """
Returns the value of the summary identified by `spec`. If there is no summary for
given labels combination, returns `:undefined`.
Raises `Prometheus.Error.UnknownMetric` exception if a summary for `spec` can't be found.<br>
Raises `Prometheus.Error.InvalidMetricArity` exception if labels count mismatch.
"""
defmacro value(spec) do
Erlang.metric_call(spec)
end
end
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Oct 29, 9:46 AM (19 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1797892
Default Alt Text
(17 KB)
Attached To
Mode
R26 prometheus.ex
Attached
Detach File
Event Timeline