@@ -485,29 +485,26 @@ public function buildCommand(string $command, string $filename, array $options =
485485 }
486486
487487 /**
488- * Get array of all rrd files for a device via rrdached or localdisk.
489- * If $hostname is empty, it will list all rrd files
488+ * Get array of all rrd files for a device,
489+ * via rrdached or localdisk.
490490 *
491491 * @param string $hostname hostname of the device
492- * @return string[] array of rrd files for this host relative to rrd_dir
492+ * @return string[] array of rrd files for this host
493493 */
494494 public function getRrdFiles (string $ hostname ): array
495495 {
496- $ dir = $ this ->dirFromHost ($ hostname );
497-
498496 if ($ this ->rrdcached ) {
499- $ output = $ this ->command ('list ' , $ dir . '/ ' , ['--recursive ' ]);
497+ $ output = $ this ->command ('list ' , '/ ' . self ::safeName ($ hostname ));
498+
500499 $ files = explode ("\n" , trim ($ output [0 ] ?? '' ));
501500 array_pop ($ files ); // remove rrdcached status line
502- $ prepend = str_replace ($ this ->rrd_dir . '/ ' , '' , $ dir ) . '/ ' ;
503-
504- return array_map (fn ($ file ) => $ prepend . $ file , $ files );
501+ } else {
502+ $ files = glob ($ this ->dirFromHost ($ hostname ) . '/*.rrd ' ) ?: [];
505503 }
506504
507- $ iterator = new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ dir ));
508- $ rrdFiles = new \RegexIterator ($ iterator , '/\.rrd$/ ' );
505+ sort ($ files );
509506
510- return array_map ( fn ( \ SplFileInfo $ file ) => str_replace ( $ this -> rrd_dir . ' / ' , '' , $ file ), iterator_to_array ( $ rrdFiles , false )) ;
507+ return $ files ;
511508 }
512509
513510 /**
@@ -525,8 +522,6 @@ public function getRrdApplicationArrays($device, $app_id, $app_name, $category =
525522 $ separator = '- ' ;
526523
527524 $ rrdfile_array = $ this ->getRrdFiles ($ device ['hostname ' ]);
528- sort ($ rrdfile_array );
529-
530525 if ($ category ) {
531526 $ pattern = sprintf ('%s-%s-%s-%s ' , 'app ' , $ app_name , $ app_id , $ category );
532527 } else {
0 commit comments