@@ -156,7 +156,7 @@ public function updateHistogram(array $data): void
156
156
,
157
157
[
158
158
$ this ->toMetricKey ($ data ),
159
- self ::$ prefix. Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
159
+ self ::$ prefix . Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
160
160
json_encode (['b ' => 'sum ' , 'labelValues ' => $ data ['labelValues ' ]]),
161
161
json_encode (['b ' => $ bucketToIncrease , 'labelValues ' => $ data ['labelValues ' ]]),
162
162
$ data ['value ' ],
@@ -176,16 +176,16 @@ public function updateSummary(array $data): void
176
176
$ this ->redis ->ensureOpenConnection ();
177
177
178
178
// store meta
179
- $ summaryKey = self ::$ prefix. Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
180
- $ metaKey = $ summaryKey. ': ' . $ this ->metaKey ($ data );
179
+ $ summaryKey = self ::$ prefix . Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
180
+ $ metaKey = $ summaryKey . ': ' . $ this ->metaKey ($ data );
181
181
$ json = json_encode ($ this ->metaData ($ data ));
182
182
if ($ json === false ) {
183
183
throw new RuntimeException (json_last_error_msg ());
184
184
}
185
185
$ this ->redis ->setNx ($ metaKey , $ json );
186
186
187
187
// store value key
188
- $ valueKey = $ summaryKey. ': ' . $ this ->valueKey ($ data );
188
+ $ valueKey = $ summaryKey . ': ' . $ this ->valueKey ($ data );
189
189
$ json = json_encode ($ this ->encodeLabelValues ($ data ['labelValues ' ]));
190
190
if ($ json === false ) {
191
191
throw new RuntimeException (json_last_error_msg ());
@@ -195,7 +195,7 @@ public function updateSummary(array $data): void
195
195
// trick to handle uniqid collision
196
196
$ done = false ;
197
197
while (! $ done ) {
198
- $ sampleKey = $ valueKey. ': ' . uniqid ('' , true );
198
+ $ sampleKey = $ valueKey . ': ' . uniqid ('' , true );
199
199
$ done = $ this ->redis ->set ($ sampleKey , $ data ['value ' ], ['NX ' , 'EX ' => $ data ['maxAgeSeconds ' ]]);
200
200
}
201
201
}
@@ -229,7 +229,7 @@ public function updateGauge(array $data): void
229
229
,
230
230
[
231
231
$ this ->toMetricKey ($ data ),
232
- self ::$ prefix. Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
232
+ self ::$ prefix . Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
233
233
$ this ->getRedisCommand ($ data ['command ' ]),
234
234
json_encode ($ data ['labelValues ' ]),
235
235
$ data ['value ' ],
@@ -261,7 +261,7 @@ public function updateCounter(array $data): void
261
261
,
262
262
[
263
263
$ this ->toMetricKey ($ data ),
264
- self ::$ prefix. Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
264
+ self ::$ prefix . Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ,
265
265
$ this ->getRedisCommand ($ data ['command ' ]),
266
266
$ data ['value ' ],
267
267
json_encode ($ data ['labelValues ' ]),
@@ -288,7 +288,7 @@ protected function metaData(array $data): array
288
288
*/
289
289
protected function collectHistograms (): array
290
290
{
291
- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
291
+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Histogram::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
292
292
sort ($ keys );
293
293
$ histograms = [];
294
294
foreach ($ keys as $ key ) {
@@ -329,15 +329,15 @@ protected function collectHistograms(): array
329
329
$ bucketKey = json_encode (['b ' => $ bucket , 'labelValues ' => $ labelValues ]);
330
330
if (! isset ($ raw [$ bucketKey ])) {
331
331
$ histogram ['samples ' ][] = [
332
- 'name ' => $ histogram ['name ' ]. '_bucket ' ,
332
+ 'name ' => $ histogram ['name ' ] . '_bucket ' ,
333
333
'labelNames ' => ['le ' ],
334
334
'labelValues ' => array_merge ($ labelValues , [$ bucket ]),
335
335
'value ' => $ acc ,
336
336
];
337
337
} else {
338
338
$ acc += $ raw [$ bucketKey ];
339
339
$ histogram ['samples ' ][] = [
340
- 'name ' => $ histogram ['name ' ]. '_bucket ' ,
340
+ 'name ' => $ histogram ['name ' ] . '_bucket ' ,
341
341
'labelNames ' => ['le ' ],
342
342
'labelValues ' => array_merge ($ labelValues , [$ bucket ]),
343
343
'value ' => $ acc ,
@@ -347,15 +347,15 @@ protected function collectHistograms(): array
347
347
348
348
// Add the count
349
349
$ histogram ['samples ' ][] = [
350
- 'name ' => $ histogram ['name ' ]. '_count ' ,
350
+ 'name ' => $ histogram ['name ' ] . '_count ' ,
351
351
'labelNames ' => [],
352
352
'labelValues ' => $ labelValues ,
353
353
'value ' => $ acc ,
354
354
];
355
355
356
356
// Add the sum
357
357
$ histogram ['samples ' ][] = [
358
- 'name ' => $ histogram ['name ' ]. '_sum ' ,
358
+ 'name ' => $ histogram ['name ' ] . '_sum ' ,
359
359
'labelNames ' => [],
360
360
'labelValues ' => $ labelValues ,
361
361
'value ' => $ raw [json_encode (['b ' => 'sum ' , 'labelValues ' => $ labelValues ])],
@@ -381,9 +381,9 @@ protected function removePrefixFromKey(string $key): string
381
381
*/
382
382
protected function collectSummaries (): array
383
383
{
384
- $ math = new Math ;
385
- $ summaryKey = self ::$ prefix. Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
386
- $ keys = $ this ->redis ->keys ($ summaryKey. ':*:meta ' );
384
+ $ math = new Math () ;
385
+ $ summaryKey = self ::$ prefix . Summary::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX ;
386
+ $ keys = $ this ->redis ->keys ($ summaryKey . ':*:meta ' );
387
387
388
388
$ summaries = [];
389
389
foreach ($ keys as $ metaKeyWithPrefix ) {
@@ -404,7 +404,7 @@ protected function collectSummaries(): array
404
404
'samples ' => [],
405
405
];
406
406
407
- $ values = $ this ->redis ->keys ($ summaryKey. ': ' . $ metaData ['name ' ]. ':*:value ' );
407
+ $ values = $ this ->redis ->keys ($ summaryKey . ': ' . $ metaData ['name ' ] . ':*:value ' );
408
408
foreach ($ values as $ valueKeyWithPrefix ) {
409
409
$ valueKey = $ this ->removePrefixFromKey ($ valueKeyWithPrefix );
410
410
$ rawValue = $ this ->redis ->get ($ valueKey );
@@ -416,7 +416,7 @@ protected function collectSummaries(): array
416
416
$ decodedLabelValues = $ this ->decodeLabelValues ($ encodedLabelValues );
417
417
418
418
$ samples = [];
419
- $ sampleValues = $ this ->redis ->keys ($ summaryKey. ': ' . $ metaData ['name ' ]. ': ' . $ encodedLabelValues. ':value:* ' );
419
+ $ sampleValues = $ this ->redis ->keys ($ summaryKey . ': ' . $ metaData ['name ' ] . ': ' . $ encodedLabelValues . ':value:* ' );
420
420
foreach ($ sampleValues as $ sampleValueWithPrefix ) {
421
421
$ sampleValue = $ this ->removePrefixFromKey ($ sampleValueWithPrefix );
422
422
$ samples [] = (float ) $ this ->redis ->get ($ sampleValue );
@@ -445,15 +445,15 @@ protected function collectSummaries(): array
445
445
446
446
// Add the count
447
447
$ data ['samples ' ][] = [
448
- 'name ' => $ metaData ['name ' ]. '_count ' ,
448
+ 'name ' => $ metaData ['name ' ] . '_count ' ,
449
449
'labelNames ' => [],
450
450
'labelValues ' => $ decodedLabelValues ,
451
451
'value ' => count ($ samples ),
452
452
];
453
453
454
454
// Add the sum
455
455
$ data ['samples ' ][] = [
456
- 'name ' => $ metaData ['name ' ]. '_sum ' ,
456
+ 'name ' => $ metaData ['name ' ] . '_sum ' ,
457
457
'labelNames ' => [],
458
458
'labelValues ' => $ decodedLabelValues ,
459
459
'value ' => array_sum ($ samples ),
@@ -479,7 +479,7 @@ protected function collectSummaries(): array
479
479
*/
480
480
protected function collectGauges (bool $ sortMetrics = true ): array
481
481
{
482
- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
482
+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Gauge::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
483
483
sort ($ keys );
484
484
$ gauges = [];
485
485
foreach ($ keys as $ key ) {
@@ -521,7 +521,7 @@ protected function collectGauges(bool $sortMetrics = true): array
521
521
*/
522
522
protected function collectCounters (bool $ sortMetrics = true ): array
523
523
{
524
- $ keys = $ this ->redis ->sMembers (self ::$ prefix. Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
524
+ $ keys = $ this ->redis ->sMembers (self ::$ prefix . Counter::TYPE . self ::PROMETHEUS_METRIC_KEYS_SUFFIX );
525
525
sort ($ keys );
526
526
$ counters = [];
527
527
foreach ($ keys as $ key ) {
@@ -620,7 +620,7 @@ protected function decodeLabelValues(string $values): array
620
620
protected function throwMetricJsonException (string $ redisKey , ?string $ metricName = null ): void
621
621
{
622
622
$ metricName = $ metricName ?? 'unknown ' ;
623
- $ message = 'Json error: ' . json_last_error_msg (). ' redis key : ' . $ redisKey. ' metric name: ' . $ metricName ;
623
+ $ message = 'Json error: ' . json_last_error_msg () . ' redis key : ' . $ redisKey . ' metric name: ' . $ metricName ;
624
624
throw new MetricJsonException ($ message , 0 , null , $ metricName );
625
625
}
626
626
}
0 commit comments