<?php
include_once('db_system_status.php');
ini_set('max_execution_time', 120);

   header('Content-Type: application/json');
   $first = true;
   $sql = "select sql_no_cache * from ( select * from system_status where date(fecha)<= now() order by fecha desc limit 288 ) sub order by fecha asc";
   $result = $conn1->query($sql);
   if( $result->num_rows > 0 ) {
      echo "[";
      while($row = $result->fetch_assoc()) {

         $fecha = date("d-m-Y H:i", strtotime( $row["fecha"] ) );
//         $fecha = $row["fecha"];

         $active = sprintf( "%5lu", intval( $row["sessionsActive"] ) );
         $peak = $row["sessionsPeak"];
         $peak = 0;
         if( $first == false ) {
            echo ",";
         }
         echo "[\"Activas\",\"$fecha\",$active]";
//         echo "[\"Pico\",\"$fecha\",$peak]";
         $first = false;
      }
      echo "]";
   }               
   else {
      echo "[]";
   }
   if( $result != false && is_resource( $result ) ) mysql_free_result( $result ); 
   mysqli_close($conn);
?>
