Skip to content

Instantly share code, notes, and snippets.

@recklessop

recklessop/dailystats.php

Last active Feb 20, 2019
Embed
What would you like to do?
dailystats.php for zplanner
<?php
$connect = mysqli_connect("localhost","root","Zertodata1!");
mysqli_select_db($connect,"zerto"); //select the table
$query = "SELECT name FROM `vms` WHERE monitor = 'Y'";
$vms = mysqli_query($connect, $query) or die (mysqli_error($connect));
$query = "SELECT datestamp FROM `stats` GROUP BY datestamp DESC";
$dateresult = mysqli_query($connect, $query) or die (mysqli_error($connect));
while ($dates = $dateresult->fetch_array(MYSQLI_ASSOC))
{
$datestamp = $dates['datestamp'];
while( $vm = $vms->fetch_array(MYSQLI_ASSOC))
{
echo "$datestamp - ";
$vm = $vm['name'];
echo "$vm - ";
$query = "SELECT (SUM(`IOPSWriteAvg`)) as iops, (SUM(`KBWriteAvg`)) as KBWrite FROM `stats` WHERE datestamp = '$datestamp' AND vm = '$vm'";
$result = mysqli_query($connect, $query) or die (mysqli_error($connect));
$result = $result->fetch_array(MYSQLI_ASSOC);
$iopsavg = $result['iops'];
$kbwrite = $result['KBWrite'];
if ($iopsavg == '')
$iopsavg = 0;
if ($kbwrite == '')
$kbwrite = 0;
echo "$iopsavg IOps ";
echo "$kbwrite KBps ";
$query = "INSERT INTO dailystats (datestamp, vm, WriteIOps, WriteKBps) VALUES ('$datestamp', '$vm', '$iopsavg', '$kbwrite')";
$result = mysqli_query($connect, $query) or die (mysqli_error($connect));
echo "- Data Inserted to Mysql Table \n";
}
}
mysqli_close($connect);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment