Skip to content

Commit

Permalink
Added server bandwidth and traffice consumption views
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Feb 23, 2016
1 parent 96bfe22 commit 38ce0f5
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 27 deletions.
50 changes: 50 additions & 0 deletions src/views/server/_bandwidth_consumption.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

use hipanel\widgets\ChartJs;
use yii\helpers\Html;

list($labels, $data) = $model->groupUsesForCharts();

?>

<div class="row">
<div class="col-md-12">
<?php
if ($data === []) {
echo Yii::t('hipanel/server', 'Bandwidth consumption history is not available for this server');
} else {
echo Html::tag('div', ChartJs::widget([
'type' => 'Line',
'legend' => true,
'data' => [
'labels' => array_values($labels),
'datasets' => [
[
'label' => Yii::t('hipanel/server', '95th percentile for outgoing bandwidth, Mbit/s'),
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => $data['server_traf95']
],
[
'label' => Yii::t('hipanel/server', '95th percentile for incoming bandwidth, Mbit/s'),
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor' => "rgba(151,187,205,1)",
'pointStrokeColor' => "#fff",
'data' => $data['server_traf95_in']
]
]
],
'clientOptions' => [
'bezierCurve' => false,
'responsive' => true,
'maintainAspectRatio' => true,
]
]), ['class' => 'traffic-chart-wrapper']);
}

?>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -1,53 +1,34 @@
<?php

use dosamigos\chartjs\ChartJs;
use hipanel\widgets\ChartJs;
use yii\helpers\Html;

$labels = [];
$sets = [];

$usesPerMonth = (array)$model->uses;
list($labels, $data) = $model->groupUsesForCharts();

?>

<div class="row">
<div class="col-md-12">
<?php

if ($usesPerMonth === []) {
if ($data === []) {
echo Yii::t('hipanel/server', 'Traffic consumption history is not available for this server');
} else {
ksort($usesPerMonth);

foreach ($usesPerMonth as $month => $uses) {
$labels[] = Yii::$app->formatter->asDate(strtotime($month), 'LLL y');

foreach ($uses as $use) {
if (in_array($use['type'], ['server_traf95', 'server_traf95_in', 'server_traf95_max'])) {
$value = $use['last'];
} else {
$value = $use['total'];
}

$data[$use['type']][] = $value;
}
}

echo Html::tag('div', ChartJs::widget([
'type' => 'Line',
'legend' => true,
'data' => [
'labels' => $labels,
'labels' => array_values($labels),
'datasets' => [
[
'label' => 'out',
'label' => Yii::t('hipanel/server', 'Total outgoing traffic, Gb'),
'fillColor' => "rgba(220,220,220,0.5)",
'strokeColor' => "rgba(220,220,220,1)",
'pointColor' => "rgba(220,220,220,1)",
'pointStrokeColor' => "#fff",
'data' => $data['server_traf']
],
[
'label' => 'out',
'label' => Yii::t('hipanel/server', 'Total incoming traffic, Gb'),
'fillColor' => "rgba(151,187,205,0.5)",
'strokeColor' => "rgba(151,187,205,1)",
'pointColor' => "rgba(151,187,205,1)",
Expand All @@ -61,7 +42,7 @@
'responsive' => true,
'maintainAspectRatio' => true,
]
]));
]), ['class' => 'traffic-chart-wrapper']);
}

?>
Expand Down

0 comments on commit 38ce0f5

Please sign in to comment.