1

Intento coger la información especifica de una VM a través de la API (zzantares) de proxmox. Con este código $allNodes = $proxmox->get('/nodes/proxmox/qemu/101/status/current');print_r($allNodes); y obtengo esto:

Array ( [data] => Array ( [template] => [diskread] => 277896704 [cpus] => 6 [disk] => 0 [diskwrite] => 72438272 [qmpstatus] => running [maxdisk] => 34359738368 [maxmem] => 1073741824 [blockstat] => Array ( [ide0] => Array ( [failed_rd_operations] => 0 [wr_highest_offset] => 11847032832 [rd_total_time_ns] => 106474497023 [timed_stats] => Array ( ) [invalid_wr_operations] => 0 [account_failed] => 1 [wr_total_time_ns] => 4990608743 [invalid_rd_operations] => 0 [idle_time_ns] => 33529812443 [wr_operations] => 12135 [rd_bytes] => 277822976 [rd_merged] => 0 [rd_operations] => 74939 [wr_merged] => 0 [flush_total_time_ns] => 43044472 [wr_bytes] => 72438272 [failed_flush_operations] => 0 [failed_wr_operations] => 0 [flush_operations] => 121 [invalid_flush_operations] => 0 [account_invalid] => 1 ) [ide2] => Array ( [rd_bytes] => 73728 [wr_operations] => 0 [rd_merged] => 0 [wr_bytes] => 0 [rd_operations] => 34 [wr_merged] => 0 [flush_total_time_ns] => 0 [failed_rd_operations] => 0 [rd_total_time_ns] => 3555632 [wr_highest_offset] => 0 [invalid_wr_operations] => 0 [timed_stats] => Array ( ) [account_failed] => 1 [invalid_rd_operations] => 0 [idle_time_ns] => 4409539381307 [wr_total_time_ns] => 0 [failed_wr_operations] => 0 [flush_operations] => 0 [invalid_flush_operations] => 0 [account_invalid] => 1 [failed_flush_operations] => 0 ) ) [uptime] => 4502 [nics] => Array ( [tap101i0] => Array ( [netout] => 27684 [netin] => 371054 ) ) [balloon] => 1073741824 [vmid] => 101 [mem] => 615320148 [cpu] => 0.0092101210672603 [name] => holo [netout] => 27684 [ballooninfo] => Array ( [max_mem] => 1073741824 [actual] => 1073741824 ) [netin] => 371054 [pid] => 815184 [status] => running [ha] => Array ( [managed] => 0 ) ) )

¿Cómo podría por ejemplo obtener de todo ese array únicamente la información de cpus? (a mostrar sería el 6) thanks

2
  • ¿Podrías mostrarnos el resultado de un var_dump($allNodes);. La salida que muestras impide ver la estructura real del objeto. Por ejemplo, hay dos claves seguidas: [template] => [diskread] que son muy confusas. Pulsa en editar para agregarlo. Gracias.
    – A. Cedano
    Commented el 11 mar. 2020 a las 22:51
  • Te lo pego aquí porque hay mucha cosa: pastebin.com/HHi1cnK8
    – ZeroCrazy
    Commented el 11 mar. 2020 a las 23:00

1 respuesta 1

1

Si asumimos que el array es así o parecido:

$allNodes=
    array ("data" => 
                       array ("template"=>FALSE, "diskread"=>1,  "cpus"=> 6, "disk"=>0)
          );

El valor que buscas se encontraría en la clave cpus dentro de data.

echo $allNodes["data"]["cpus"];

Salida:

6

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.