Changeset 66 for client


Ignore:
Timestamp:
Jan 2, 2016, 12:17:56 AM (9 years ago)
Author:
chronos
Message:
  • Moved: Measure scripts should be part of client, not statistic web itself.
Location:
client/php
Files:
4 added
3 copied

Legend:

Unmodified
Added
Removed
  • client/php/Client.php

    r65 r66  
    11<?php
    22
    3 // Toto je ukázkový skript pro aktualizaci dat. Zkopírujte si jej jako monitor.php a upravte podle potřeby.
     3include('Global.php');
    44
    5 include('../global.php');
    6 include('system.php');
    7 include('wow.php');
     5// Various measure libraries
     6include('Linux.php');
     7include('WoW.php');
     8include('Centrala.php');
     9include('Routerboard.php');
    810
    9 //GetNetworkState();
    10 while(1)
     11function ProcessMeasure()
    1112{
     13  $Values[3] = MemoryUsage();
     14  $Values[4] = CpuUsage();
     15  $Values[5] = WoWPlayersOnline();
     16  $Values[6] = WoWEmulatorRestartCount();
     17  $Values[7] = DiskFree('/');
     18  $Values[8] = WoWAccountCount();
     19  $Values[10] = WoWGMOnline();
    1220  $NetworkState = GetNetworkState();
    13   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=3&Value='.MemoryUsage());
    14   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=4&Value='.CpuUsage());
    15   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=5&Value='.WoWPlayersOnline());
    16   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=6&Value='.WoWEmulatorRestartCount());
    17   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=7&Value='.DiskFree());
    18   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=8&Value='.WoWAccountCount());
    19   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=10&Value='.WoWGMOnline());
    20   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=11&Value='.round($NetworkState['eth1']['DownAverage']));
    21   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=12&Value='.round($NetworkState['eth1']['UpAverage']));
    22   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=13&Value='.WoWCharacterCount());
    23   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=14&Value='.WoWGuildCount());
    24   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=15&Value='.WoWEmulatorAvailability());
    25   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=16&Value='.Ping());
    26   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=17&Value='.TeamSpeak());
    27   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=18&Value='.WoWTranslatedQuestsCount());
    28   file_get_contents($Config['AddNewValueUrl'].'?MeasureId=19&Value='.DiskUtilization());
     21  $Values[11] = round($NetworkState['eth1']['DownAverage']);
     22  $Values[12] = round($NetworkState['eth1']['UpAverage']);
     23  $Values[13] = WoWCharacterCount();
     24  $Values[14] = WoWGuildCount();
     25  $Values[15] = WoWEmulatorAvailability();
     26  $Values[16] = Ping();
     27  $Values[17] = TeamSpeak();
     28  $Values[18] = WoWTranslatedQuestsCount();
     29  $Values[18] = DiskUtilization('sda');
     30  $RBNetworkState = GetRouterBoardNetworkState();
     31  $Values[19] = $RBNetworkState['DownAverage'] * 8;
     32  $Values[20] = $RBNetworkState['UpAverage'] * 8;
     33  $Values[21] = HostsOnline();
     34  $Values[22] = MemberCount();
     35  $Values[23] = ProcessorTemperature('Core0');
    2936
    30   sleep(58);  // 60(measure period) - 2(disk utilization)
     37  foreach($Values as $Index => $Value)
     38  {
     39    file_get_contents($URL.'?MeasureId='.$Index.'&Value='.$Value);
     40  }
    3141}
     42
     43function RepeatFunction($Period, $Function)
     44{
     45  while(1)
     46  {
     47    $StartTime = time();
     48    $Function();
     49    $EndTime = time();
     50    $Delay = $Period - ($EndTime - $StartTime);
     51    if($Delay < 0) $Delay = 0;
     52
     53    echo('Waiting '.$Delay.' seconds...'."\n");
     54    sleep($Delay);
     55  }
     56}
     57
     58RepeatFunction(60 * 60, 'ProcessMeasure');
  • client/php/Linux.php

    r63 r66  
    2323}
    2424
    25 function Ping()
     25function Ping($Host = 'nix.cz')
    2626
    27   exec('ping nix.cz -c 1 -W 1|grep time=', $Row);
     27  exec('ping '.$Host.' -c 1 -W 1|grep time=', $Row);
    2828  // W - timeout in seconds
    2929  // c - ping count
     
    124124}
    125125
    126 function DiskUtilization()
     126function DiskUtilization($Device = 'sda')
    127127{
    128128  $Output = array();
    129   exec('iostat -d sda -x -m 2 2', $Output);   // 2 second measure delay
     129  exec('iostat -d '.$Device.' -x -m 2 2', $Output);   // 2 second measure delay
    130130  $Row = $Output[6];
    131131  while(strpos($Row, '  ') !== false) $Row = str_replace('  ', ' ', $Row);
     
    135135}
    136136
    137 function DiskFree()
     137function DiskFree($Path)
    138138{
    139   return(disk_free_space('/'));
     139  return(disk_free_space($Path));
    140140}
    141141
  • client/php/WoW.php

    r62 r66  
    33// Funkce pro měření stavových veličin herního serveru hry World of Warcraft
    44
    5 include_once('../global.php');
    6 include_once('system.php');
     5include_once('Global.php');
     6include_once('Linux.php');
    77
    88function WoWPlayersOnline()
Note: See TracChangeset for help on using the changeset viewer.