瀏覽代碼

Estadísticas OLT

Guillermo Espinoza 8 年之前
父節點
當前提交
8464d2c356

+ 2 - 0
app/config/parameters.yml.dist

@@ -20,3 +20,5 @@ parameters:
 
     jms_serializer.camel_case_naming_strategy.class: JMS\Serializer\Naming\IdenticalPropertyNamingStrategy
     url_logout: 'http://200.50.168.111/base/app_dev.php/logout'
+
+    grafana_url: 'http://200.50.168.108:3000/dashboard-solo/db/'

+ 51 - 0
src/StatsBundle/Controller/StatsController.php

@@ -5,6 +5,8 @@ namespace StatsBundle\Controller;
 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 use StatsBundle\Services\DeviceManager;
 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\JsonResponse;
 
 class StatsController extends Controller
 {
@@ -23,4 +25,53 @@ class StatsController extends Controller
         return $this->redirect($this->generateUrl('admin_stats_statsdevice_list'));
     }
 
+    /**
+     * @Route("/admin/stats/stats/graph", name="stats_graph")
+     * 
+     * @return string
+     */
+    public function getStatsGraphAction(Request $request)
+    {
+//        $deviceType = $request->get('deviceType','FTTHBundle\Entity\OLT');
+        $grafana_url = $this->getParameter('grafana_url');
+
+        // Puertos pon
+        $pons = array();
+        for ($x = 1; $x <= 8; $x++) {
+            for ($y = 1; $y <= 8; $y++) {
+                $index = "{$x}.{$y}";
+                $pons[$index] = "PON PORT $index";
+            }
+        }
+        for ($x = 11; $x <= 18; $x++) {
+            for ($y = 1; $y <= 8; $y++) {
+                $index = "{$x}.{$y}";
+                $pons[$index] = "PON PORT {$index}";
+            }
+        }
+
+        $panelIds = array(6, 4, 5, 1, 2, 3,);
+
+        $pon = '1.1';
+        if ($request->isMethod('POST')) {
+            $pon = $request->request->get('pon', $pon);
+        }
+        $urls = array('olt-total-rate?orgId=1&panelId=1',);
+        foreach ($panelIds as $panelId) {
+            $urls[] = "olt-pon-ports?orgId=1&panelId={$panelId}&var-ponport={$pon}";
+        }
+
+        if ($request->isMethod('GET')) {
+            return $this->render('StatsBundle:Stats:graph.html.twig', array(
+                        'grafana_url' => $grafana_url,
+                        'urls' => $urls,
+                        'pons' => $pons,
+            ));
+        }
+
+        return new JsonResponse(array(
+            'urls' => $urls,
+        ));
+    }
+
 }

+ 1 - 0
src/StatsBundle/Resources/config/services.yml

@@ -15,6 +15,7 @@ services:
             - { name: sonata.admin, manager_type: orm, group: Stats, label: StatsDevice, label_catalogue: StatsBundle, label_translator_strategy: sonata.admin.label.strategy.underscore }
         calls:    
             - [setTranslationDomain, [StatsBundle]]
+            - [setTemplate, ['show','StatsBundle:StatsDevice:show.html.twig']]
 
     stats.device.manager:
         class: StatsBundle\Services\DeviceManager

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

@@ -44,4 +44,6 @@ Stats: Estadísticas
 DeviceServer: Servidor Dispositivos
 StatsDevice: Dispositivo
 
-link_action_update_devices: Actualizar dispositivos
+link_action_update_devices: Actualizar dispositivos
+
+Statistics: Estadísticas

+ 41 - 0
src/StatsBundle/Resources/views/Stats/graph.html.twig

@@ -0,0 +1,41 @@
+<div>
+    <h4>{{ 'Statistics'|trans({}, 'StatsBundle') }}</h4>
+    <div style="margin: 0 auto;">
+        {% set url_iframe = grafana_url ~ urls[0] %}
+        {% set iframe = "<iframe src='#{url_iframe}' height='450' frameborder='0' style='margin-bottom: 10px; width: 100%;'></iframe>" %}
+        {{ iframe|raw }}
+        <select id="pon" style="margin-bottom: 10px; width: 50%;">
+            {% for pon, name in pons %}
+                <option value="{{ pon }}">{{ name }}</option>
+            {% endfor %}
+        </select>
+        <div id="stats-iframe">
+        {% for url in urls|slice(1) %}
+        {% set url_iframe = grafana_url ~ url %}
+        {% set iframe = "<iframe src='#{url_iframe}' height='450' frameborder='0' style='margin-bottom: 10px; width: 100%;'></iframe>" %}
+        {{ iframe|raw }}
+        {% endfor %}
+        </div>
+    </div>
+</div>
+    
+<script type="text/javascript">
+    $(function () {
+        $('#pon').on('change', function () {
+            var pon = $('#pon').val();
+            $.ajax({
+                url: '{{ path('stats_graph') }}',
+                type: 'POST',
+                data: {
+                    pon: pon
+                },
+                success: function(data) {
+                    $('#stats-iframe').html('');
+                    for (i = 1; i < data.urls.length; i++) {
+                        $('#stats-iframe').append('<iframe src="{{ grafana_url }}'+data.urls[i]+'" height="450" frameborder="0" style="margin-bottom: 10px; width: 100%;"></iframe>');
+                    }
+                }
+            });
+        });
+    });
+</script>

+ 6 - 0
src/StatsBundle/Resources/views/StatsDevice/show.html.twig

@@ -0,0 +1,6 @@
+{% extends 'SonataAdminBundle:CRUD:base_show.html.twig' %}
+
+{% block show %}
+    {{ parent() }}
+    {{ render(controller('StatsBundle:Stats:getStatsGraph')) }}
+{% endblock %}