Pārlūkot izejas kodu

Se agregan reporte para consumo de OLT, sólo los últimos puntos y de
manera acumulativa.

Maximiliano Schvindt 7 gadi atpakaļ
vecāks
revīzija
f06af94492

+ 8 - 0
src/StatsBundle/Command/BaseCommand.php

@@ -59,6 +59,14 @@ abstract class BaseCommand extends ContainerAwareCommand
         return $this->collector->getString($key, $output);
     }
 
+    /**
+     * @param string|array $key
+     */
+    protected function del($key)
+    {
+        return $this->collector->del($key);
+    }
+
     /**
      * @param array $queries
      * @return 

+ 11 - 2
src/StatsBundle/Command/RedisCommand.php

@@ -18,7 +18,8 @@ class RedisCommand extends BaseCommand
                 ->setDescription('Read Redis data')
                 ->setHelp('This command allows test redis')
                 ->setDefinition(array(
-                    new InputOption('key', null, InputOption::VALUE_OPTIONAL, "Key redis", null)
+                    new InputOption('key', null, InputOption::VALUE_OPTIONAL, "Key redis", null),
+                    new InputOption('del', null, InputOption::VALUE_OPTIONAL, "Key delete", 0)
                 ))
         ;
     }
@@ -32,6 +33,7 @@ class RedisCommand extends BaseCommand
         parent::execute($input, $output);
         
         $key = $input->getOption('key');
+        $del = (int) $input->getOption('del');
 
         if(is_null($key)) {
             $this->output->writeln("key es nulo.");
@@ -44,11 +46,18 @@ class RedisCommand extends BaseCommand
             $this->output->writeln("Se requiere {$key}.");
             return true;
         }
-
+        
         print_r(PHP_EOL."######################".PHP_EOL);
         print_r($data);
         print_r(PHP_EOL."######################".PHP_EOL);
         
+        if($del) {
+            print_r(PHP_EOL."######## DELETE ########".PHP_EOL);
+            $data = $this->del($key);
+            var_dump($data);
+            print_r(PHP_EOL."######################".PHP_EOL);
+        }
+        
         
     }
 

+ 29 - 0
src/StatsBundle/Controller/OltReportController.php

@@ -222,5 +222,34 @@ class OltReportController extends Controller
             'restPercent'   => $restPercent
         ));
     }
+
+    public function oltConsumptionAction($oltServerId, $oltDeviceId) {
+        
+        $subName = "d_{$oltDeviceId}_s_{$oltServerId}";
+
+        $result = $targets = array();
+        $endpoint = $this->get('endpoint.mysql');
+
+        $targets["in_consumption"] = array("target" => "{$subName}_inconsumption_olt");
+        $targets["out_consumption"] = array("target" => "{$subName}_outconsumption_olt");
+        
+        foreach($targets as $index => $t) {
+            $search = array('targets' => array(0 => $t), 'maxDataPoints' => 50);
+            $data = $endpoint->get(json_encode($search),'last');
+
+            if(isset($data[0]) && isset($data[0]['datapoints'])) {
+                $points = $data[0]['datapoints']; krsort($points);
+                $result[$index] = $points;
+            } else {
+                $result[$index] = array();
+            }
+        }
+        
+
+        return $this->render('StatsBundle:Device:Report/oltConsumption.html.twig', array(
+            'inCons' => $result['in_consumption'],
+            'outCons' => $result['out_consumption']
+        ));
+    }
     
 }

+ 2 - 1
src/StatsBundle/Resources/translations/StatsBundle.es.yml

@@ -136,4 +136,5 @@ olt_bandwidth: Bandwidth de OLT (en Mb)
 pon_port_inBandwidth: IN
 pon_port_outBandwidth: OUT
 pon_port_totalBandwidth: Total
-pon_bandwidth: Top 10 - Bandwidth de PONPORT (en Mb)
+pon_bandwidth: Top 10 - Bandwidth de PONPORT (en Mb)
+olt_consumption: Consumo de OLT (en Gb)

+ 61 - 0
src/StatsBundle/Resources/views/Device/Report/oltConsumption.html.twig

@@ -0,0 +1,61 @@
+<div class="box box-widget">
+    <div class="box-header">
+        <h4 class="box-title">{{ 'olt_consumption'|trans({}, 'StatsBundle') }}</h4>
+        <div class="box-tools pull-right">
+            <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
+        </div>
+    </div>
+    <div class="box-body">
+        <canvas id="olt_consumption"></canvas>
+    </div>
+</div>
+
+{% if inCons|length > 0 or outCons|length > 0 %}
+<script>
+    {% set itemsIn, itemsOut, labelsIn, labelsOut, labels = [], [], [], [], [] %}
+    {% if inCons|length > 0  %}
+        {% for i,point in inCons %}
+            {% set itemsIn = itemsIn|merge([point[0]]) %}
+            {% set d = (point[1]/1000)|date('d') %}
+            {% set hour = (point[1]/1000)|date('H:i') %}
+            {% set labelsIn = labelsIn|merge([hour]) %}
+        {% endfor %}
+    {% endif %}
+    {% if outCons|length > 0  %}
+        {% for i,point in outCons %}
+            {% set itemsOut = itemsOut|merge([point[0]]) %}
+            {% set hour = (point[1]/1000)|date('H:i') %}
+            {% set labelsOut = labelsOut|merge([hour]) %}
+        {% endfor %}
+    {% endif %}
+
+    {% if labelsIn|length > 0 %}
+        {% set labels = labelsIn %}
+    {% else %}
+        {% set labels = labelsOut %}
+    {% endif %}
+    var occhart_cons = new Chart( $('#olt_consumption'), {
+        type: 'line',
+        data: {
+            datasets: [{
+                label: "IN Consumption",
+                data: [{{ itemsIn|join(',') }}],
+                borderColor: "#61C45C"
+            },{
+                label: "OUT Consumption",
+                data: [{{ itemsOut|join(',') }}],
+                borderColor: "#FF7C3F"
+            }],
+            labels: ["{{ labels|join('","')|raw }}"]
+        },
+        options: {
+            legend: {
+                display: true
+            },
+            title: {
+                display: false
+            }
+        }
+    });
+</script>
+{% endif %}

+ 8 - 1
src/StatsBundle/Resources/views/Device/report.html.twig

@@ -23,7 +23,7 @@
                 }}
             </div>
             <div class="col-sm-6">
-                {{ render_hinclude(controller("StatsBundle:OltReport:oltCommands", {'oltServerId': device.getDeviceServer.getId(), 'oltDeviceId': device.getDeviceId(), 'mark': mark}),
+                {{ render_hinclude(controller("StatsBundle:OltReport:oltConsumption", {'oltServerId': device.getDeviceServer.getId(), 'oltDeviceId': device.getDeviceId()}),
                     {'default':  include("@Stats/Device/Report/default.html.twig")})
                 }}
             </div>
@@ -40,5 +40,12 @@
                 }}
             </div>
         </div>
+        <div class="box-body">
+            <div class="col-sm-6">
+                {{ render_hinclude(controller("StatsBundle:OltReport:oltCommands", {'oltServerId': device.getDeviceServer.getId(), 'oltDeviceId': device.getDeviceId(), 'mark': mark}),
+                    {'default':  include("@Stats/Device/Report/default.html.twig")})
+                }}
+            </div>
+        </div>
     </div>
 {% endblock %}