@@ -292,6 +292,7 @@ public function getServerMetrics()
292
292
if (trim ($ line ) == "" ) {
293
293
continue ;
294
294
}
295
+
295
296
if ($ line [0 ] == "# " ) {
296
297
// type or help
297
298
if (!preg_match ("/^#\s*([^\s]+)\s+([^\s]+)\s+(.*)$/ " , $ line , $ matches )) {
@@ -306,10 +307,10 @@ public function getServerMetrics()
306
307
$ metrics [$ metric ][strtolower ($ matches [1 ])] = $ matches [3 ];
307
308
} else {
308
309
// metric value
309
- if (!preg_match ("/^([^\s]+? )(\{.*?\})?\s+ (.+)$\s*$/ " , $ line , $ matches )) {
310
+ if (!preg_match ("/^([^\s\{]+ )(\{.*?\})?\s* (.+)$\s*$/ " , $ line , $ matches )) {
310
311
throw new ClientException ('Invalid metrics API output line: " ' . $ line . '" ' );
311
312
}
312
-
313
+
313
314
$ metric = $ matches [1 ];
314
315
$ sub = null ;
315
316
if (preg_match ("/_(sum|count|bucket)$/ " , $ metric , $ sub )) {
@@ -325,23 +326,25 @@ public function getServerMetrics()
325
326
// labels
326
327
if ($ matches [2 ] != "" ) {
327
328
$ labels = substr ($ matches [2 ], 1 , strlen ($ matches [2 ]) - 2 );
328
- foreach (explode (", " , $ labels ) as $ label ) {
329
- $ parts = explode ("= " , $ label );
330
- $ key = trim ($ parts [0 ]);
331
- $ value = trim ($ parts [1 ], " \"" );
332
- if (!isset ($ metrics [$ metric ]["labels " ])) {
333
- $ metrics [$ metric ]["labels " ] = [];
334
- }
335
- if ($ key != "le " ) {
336
- $ metrics [$ metric ]["labels " ][$ key ] = $ value ;
337
- } else {
338
- $ le = $ value ;
329
+ if ($ labels != "" ) {
330
+ foreach (explode (", " , $ labels ) as $ label ) {
331
+ $ parts = explode ("= " , $ label );
332
+ $ key = trim ($ parts [0 ]);
333
+ $ value = trim ($ parts [1 ], " \"" );
334
+ if (!isset ($ metrics [$ metric ]["labels " ])) {
335
+ $ metrics [$ metric ]["labels " ] = [];
336
+ }
337
+ if ($ key != "le " ) {
338
+ $ metrics [$ metric ]["labels " ][$ key ] = $ value ;
339
+ } else {
340
+ $ le = $ value ;
341
+ }
339
342
}
340
343
}
341
344
}
342
345
343
346
// cast to number
344
- $ value = $ matches [3 ] + 0 ;
347
+ $ value = $ matches [3 ];
345
348
346
349
if ($ sub == null ) {
347
350
// counter
0 commit comments