|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * @file |
| 4 | + * Contains Bexio\PrometheusPHP\Metric\Histogram. |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Bexio\PrometheusPHP\Metric; |
| 8 | + |
| 9 | +use Bexio\PrometheusPHP\Action\Observe; |
| 10 | +use Bexio\PrometheusPHP\Metric; |
| 11 | +use Bexio\PrometheusPHP\Type\Observable; |
| 12 | + |
| 13 | +/** |
| 14 | + * Histogram Metric |
| 15 | + * |
| 16 | + * A Histogram counts individual observations from an event or sample stream in configurable buckets. Similar to a |
| 17 | + * summary, it also provides a sum of observations and an observation count. |
| 18 | + * |
| 19 | + * On the Prometheus server, quantiles can be calculated from a Histogram using the histogram_quantile function in the |
| 20 | + * query language. |
| 21 | + * |
| 22 | + * Note that Histograms, in contrast to Summaries, can be aggregated with the Prometheus query language (see the |
| 23 | + * documentation for detailed procedures). However, Histograms require the user to pre-define suitable buckets, and |
| 24 | + * they are in general less accurate. The Observe method of a Histogram has a very low performance overhead in |
| 25 | + * comparison with the Observe method of a Summary. |
| 26 | + */ |
| 27 | +class Histogram extends Metric implements Observable |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @param string $name The metric name |
| 31 | + * @param string $help The help information for this metric. |
| 32 | + * @param float[] $buckets The buckets upper including bounds. |
| 33 | + * @param string $namespace (optional) The metric namespace. |
| 34 | + * @param string $subsystem (optional) The metric subsystem. |
| 35 | + * @param string[] $labels (optional) Key value pairs of static metric labels. |
| 36 | + * |
| 37 | + * @return Histogram |
| 38 | + */ |
| 39 | + public static function createFromValues( |
| 40 | + $name, |
| 41 | + $help, |
| 42 | + array $buckets = null, |
| 43 | + $namespace = null, |
| 44 | + $subsystem = null, |
| 45 | + array $labels = array() |
| 46 | + ) { |
| 47 | + $options = new HistogramOptions($name, $help, $buckets, $namespace, $subsystem, $labels); |
| 48 | + |
| 49 | + return new Histogram($options); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @param HistogramOptions $options |
| 54 | + * |
| 55 | + * @return Histogram |
| 56 | + */ |
| 57 | + public static function createFromOptions(HistogramOptions $options) |
| 58 | + { |
| 59 | + return new Histogram($options); |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * Observes a value. |
| 64 | + * |
| 65 | + * @param float $value |
| 66 | + */ |
| 67 | + public function observe($value) |
| 68 | + { |
| 69 | + $this->actions[] = Observe::createFromValue($this, $value); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * The metric type identifier. |
| 74 | + * |
| 75 | + * @return string |
| 76 | + */ |
| 77 | + public function getType() |
| 78 | + { |
| 79 | + return 'histogram'; |
| 80 | + } |
| 81 | +} |
0 commit comments