92 && !(
$stability === self::STABILITY_MIXED &&
$type === self::TYPE_COLLECTION)
94 throw new \InvalidArgumentException(
95 "Invalid stability for metric: $stability" 103 $type !== self::TYPE_BOOL
104 &&
$type !== self::TYPE_COUNTER
105 &&
$type !== self::TYPE_GAUGE
106 &&
$type !== self::TYPE_TIMESTAMP
107 &&
$type !== self::TYPE_TEXT
108 &&
$type !== self::TYPE_COLLECTION
110 throw new \InvalidArgumentException(
111 "Invalid type for metric: $type" 120 || (
$type === self::TYPE_COUNTER && !is_int(
$value))
123 || (
$type === self::TYPE_TEXT && !is_string(
$value))
124 || (
$type === self::TYPE_COLLECTION && !is_array(
$value))
126 throw new \InvalidArgumentException(
127 "Invalid type " . gettype(
$value) .
" for metric of type $type" 131 if (
$type === self::TYPE_COLLECTION) {
133 if (!($v instanceof
Metric)) {
134 throw new \InvalidArgumentException(
135 "Every element of a collection needs to be a metric, found " . gettype($v)
165 public function toYAML(
int $indentation = 0) : string
169 case self::TYPE_BOOL:
176 case self::TYPE_COUNTER:
178 case self::TYPE_GAUGE:
182 return sprintf(
"%.03f",
$value);
183 case self::TYPE_TIMESTAMP:
184 return $value->format(\DateTimeInterface::ISO8601);
185 case self::TYPE_TEXT:
186 if (substr_count(
$value,
"\n") > 0) {
187 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
190 case self::TYPE_COLLECTION:
194 function ($k, $v) use ($indentation) {
195 if ($v->getType() === self::TYPE_COLLECTION) {
200 return $this->
getIndentation($indentation) .
"$k:$split" . $v->toYAML($indentation + 1);
207 throw new \LogicException(
"Unknown type: " . $this->
getType());
216 case self::TYPE_BOOL:
222 case self::TYPE_COUNTER:
224 case self::TYPE_GAUGE:
228 return sprintf(
"%.03f",
$value);
229 case self::TYPE_TIMESTAMP:
230 return $value->format(\DateTimeInterface::ISO8601);
231 case self::TYPE_TEXT:
232 if (substr_count(
$value,
"\n") > 0) {
233 return ">" . str_replace(
"\n",
"\n" . $this->
getIndentation($indentation),
"\n$value");
236 case self::TYPE_COLLECTION:
238 foreach (
$value as $key => $val) {
239 $result[$key] = $val->toArray($indentation + 1);
243 throw new \LogicException(
"Unknown type: " . $this->
getType());
250 while ($indentation--) {
264 if ($stability === self::STABILITY_MIXED) {
265 throw new \LogicException(
"Can not extract by mixed.");
269 return [$this, null];
271 if ($this->
getType() !== self::TYPE_COLLECTION) {
272 return [null, $this];
279 foreach ($values as $k => $v) {
280 list(
$e, $r) = $v->extractByStability($stability);
289 if (count($extracted)) {
292 self::TYPE_COLLECTION,
303 self::TYPE_COLLECTION,
311 return [$extracted,
$rest];
317 $sub = $f->panel()->sub(
"", $f->legacy(
"<pre>" . $yaml .
"</pre>"));
318 return $f->panel()->report($name, [$sub]);
extractByStability(string $stability)
The extracted part will be the first entry of the array, the second will be the rest of the metrics...
toArray(int $indentation=0)
const TYPE_BOOL
The type of the metric tells what to expect of the values.
A metric is something we can measure about the system.
This describes how a Report could be modified during construction of UI.
foreach($_POST as $key=> $value) $res
checkValue($type, $value)
toYAML(int $indentation=0)
toUIReport(Factory $f, string $name)
__construct(string $stability, string $type, $value, string $description=null)
getIndentation(int $indentation=0)
checkStability($stability, $type)
const STABILITY_CONFIG
The stability of a metric tells how often we expect changes in the metric.