1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
* @file
*/
declare( strict_types=1 );
namespace Wikimedia\Stats\Metrics;
use Wikimedia\Stats\IBufferingStatsdDataFactory;
use Wikimedia\Stats\Sample;
/**
* Base Metric Interface
*
* Interface for defining a Base Metric.
*
* @author Cole White
* @since 1.41
*/
interface BaseMetricInterface {
/**
* @param string $component The component this metric will track.
* @param string $name The Metric Name.
*/
public function __construct( string $component, string $name );
/**
* Records a Metric Sample.
*
* @param Sample $sample
* @return void
*/
public function addSample( Sample $sample ): void;
/**
* Returns the configured sample rate.
*
* @return float
*/
public function getSampleRate(): float;
/**
* Sets the sample rate.
*
* @param float $sampleRate
*/
public function setSampleRate( float $sampleRate ): void;
/**
* Returns subset of samples corresponding to sample rate setting.
*
* @return Sample[]
*/
public function getSamples(): array;
/**
* Returns a count of samples recorded by the metric.
*
* @return int
*/
public function getSampleCount(): int;
/**
* Returns the Metric Name
*
* @return string
*/
public function getName(): string;
/**
* Add a label with key => value.
* Note that the order in which labels are added is significant for StatsD output.
*
* Example:
* ```php
* $statsFactory->withComponent( 'demo' )
* ->getCounter( 'testMetric_total' )
* ->setLabel( 'first', 'foo' )
* ->setLabel( 'second', 'bar' )
* ->setLabel( 'third', 'baz' )
* ->increment();
* ```
* statsd: "mediawiki.demo.testMetric_total.foo.bar.baz"
* prometheus: "mediawiki_demo_testMetric_total{first='foo',second='bar',third='baz'}
*
* @param string $key
* @param string $value
* @return void
*/
public function addLabel( string $key, string $value ): void;
/**
* Returns array of label keys.
*
* @return string[]
*/
public function getLabelKeys(): array;
/**
* Returns an array of label values in the order of label keys.
*
* @return string[]
*/
public function getLabelValues(): array;
/**
* Returns the Metric Component
*
* @return string
*/
public function getComponent(): string;
/**
* Clears the working labels.
*
* @return void
*/
public function clearLabels(): void;
/**
* Gets StatsD Data Factory instance or null.
*/
public function getStatsdDataFactory();
/**
* Validates and sets legacy StatsD namespaces.
*
* @param string|string[] $statsdNamespaces
* @return void
*/
public function setStatsdNamespaces( $statsdNamespaces ): void;
/**
* Returns the configured legacy StatsD namespaces.
*
* @return string[]
*/
public function getStatsdNamespaces(): array;
/**
* StatsD Data Factory instance to copy metrics to.
*
* @param IBufferingStatsdDataFactory $statsdDataFactory
* @return BaseMetricInterface
*/
public function withStatsdDataFactory( IBufferingStatsdDataFactory $statsdDataFactory );
}
|