Exemplo n.º 1
0
        /// <summary>
        /// Compare la valeur de 2 axes d'un cube.
        /// Les valeurs utilisés dépendent des paramètres du constructeur.
        /// </summary>
        /// <param name="x">Premier axe de comparaison.</param>
        /// <param name="y">Second axe de comparaison.</param>
        /// <returns>Résultat de la comparaison des valeurs.</returns>
        int IComparer <string> .Compare(string x, string y)
        {
            ICube cube1 = _hyperCube.GetCube(new CubeKey(_date, x, _level));
            ICube cube2 = _hyperCube.GetCube(new CubeKey(_date, y, _level));

            double v1 = double.NaN;
            double v2 = double.NaN;

            if (cube1 != null)
            {
                ICounter counter1 = cube1.GetCounter(_counterDefinitionCode);
                if (counter1 != null)
                {
                    v1 = counter1.GetValue(_statType);
                }
            }

            if (cube2 != null)
            {
                ICounter counter2 = cube2.GetCounter(_counterDefinitionCode);
                if (counter2 != null)
                {
                    v2 = counter2.GetValue(_statType);
                }
            }

            // Tri descendant
            return(-v1.CompareTo(v2));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Rend un axe au format CSV.
        /// </summary>
        /// <param name="hyperCube">HyperCube.</param>
        /// <param name="context">Contexte.</param>
        /// <param name="writer">Writer CSV.</param>
        /// <param name="activeCounters">Compteur actifs.</param>
        /// <param name="axis">Axe.</param>
        private static void CreateCsvAxis(IHyperCube hyperCube, Context context, TextWriter writer, Dictionary <string, string> activeCounters, string axis)
        {
            CounterCubeCriteria criteria = new CounterCubeCriteria(axis, TimeLevel.Hour);
            CubeKey             key      = criteria.CreateCubeKey(context.EndDate);
            ICube cube = hyperCube.GetCube(key);

            if (cube != null && IsShown(context.EndDate, context.Filtre, hyperCube, criteria))
            {
                writer.Write(axis);
                writer.Write(";");

                double total = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Total);
                writer.Write(Convert.ToString(total, CultureInfo.CurrentCulture));
                writer.Write(";");

                double hits = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Hits);
                writer.Write(Convert.ToString(hits, CultureInfo.CurrentCulture));
                writer.Write(";");

                double avg;
                foreach (ICounterDefinition definition in hyperCube.AllDefinitions)
                {
                    if (activeCounters.ContainsKey(definition.Code))
                    {
                        ICounter counter = cube.GetCounter(definition.Code);
                        avg = (counter != null) ? counter.GetValue(CounterStatType.Avg) : 0;
                        writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", avg));
                        writer.Write(";");
                    }
                }

                writer.WriteLine();
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Crée un axe en HTML.
        /// </summary>
        /// <param name="hyperCube">Cube.</param>
        /// <param name="context">Contexte.</param>
        /// <param name="writer">Writer HTML.</param>
        /// <param name="requestName">Nom de la requête.</param>
        /// <param name="activeCounters">Compteurs actifs.</param>
        /// <param name="odd">Parité.</param>
        /// <param name="axis">Axe.</param>
        /// <param name="criteria">Critères.</param>
        /// <param name="cube">Cube.</param>
        private static void CreateHtmlAxis(IHyperCube hyperCube, Context context, HtmlTextWriter writer, string requestName, Dictionary <string, string> activeCounters, bool odd, string axis, CounterCubeCriteria criteria, ICube cube)
        {
            writer.Write(HtmlPageRenderer.Indent);
            writer.WriteLine("<tr " + (odd ? "class=\"odd\"" : string.Empty) + '>');

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<td class=\"monitoring\">");

            Context localContext = context.Zoom(hyperCube.Name, axis);

            writer.Write(HtmlPageRenderer.GetLink(localContext, axis, !axis.Equals(requestName)));
            writer.WriteLine("</td>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<td class=\"monitoring\" align=\"right\">");
            double total = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Total);

            writer.Write(Convert.ToString(total, CultureInfo.CurrentCulture));
            writer.WriteLine("</td>");

            writer.Write(HtmlPageRenderer.Indent2);
            double avg = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Avg);

            writer.Write("<td class=\"monitoring\" align=\"right\" "
                         + GetHtmlStyle(1000, 10000, avg) + '>');
            writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", avg));
            writer.WriteLine("</td>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<td class=\"monitoring\" align=\"right\">");
            double hits = cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Hits);

            writer.Write(Convert.ToString(hits, CultureInfo.CurrentCulture));
            writer.WriteLine("</td>");

            writer.Write(HtmlPageRenderer.Indent2);
            PrintChartSparkLines(hyperCube, new CounterCubeCriteria(axis, TimeLevel.Minute), writer, localContext);

            double midValue;

            foreach (ICounterDefinition counterDefinition in hyperCube.AllDefinitions)
            {
                if (activeCounters.ContainsKey(counterDefinition.Code))
                {
                    ICounter counter = hyperCube.GetCube(criteria.CreateCubeKey(context.EndDate)).GetCounter(counterDefinition.Code);
                    midValue = (counter != null) ? counter.GetValue(CounterStatType.Avg) : 0;
                    writer.Write(HtmlPageRenderer.Indent2);
                    writer.Write("<td class=\"monitoring\" align=\"right\" "
                                 + GetHtmlStyle(counterDefinition, midValue) + '>');
                    writer.Write(string.Format(CultureInfo.CurrentCulture, "{0:0.##}", midValue));
                    writer.WriteLine("</td>");
                }
            }

            writer.Write(HtmlPageRenderer.Indent);
            writer.WriteLine("</tr>");
        }
Exemplo n.º 4
0
        /// <summary>
        /// Réalise le rendu du résumé d'un hypercube.
        /// </summary>
        /// <param name="hyperCube">Hypercube à rendre.</param>
        /// <param name="context">Context courant de la requête.</param>
        /// <param name="writer">Writer HTML.</param>
        internal static void ToSummary(IHyperCube hyperCube, Context context, HtmlTextWriter writer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            string requestName = context.GetRequestName(hyperCube.Name);

            writer.WriteLine("<ul>");
            writer.Write("<li>");
            writer.WriteLine(HtmlPageRenderer.GetLink(context, "Rafraîchir", true));
            writer.WriteLine("</li>");
            if (hyperCube.IsResetable)
            {
                writer.Write("<li>");
                writer.WriteLine(HtmlPageRenderer.GetLink(context.Reset(hyperCube.Name), "Remettre à zéro", true));
                writer.WriteLine("</li>");
            }

            // Si on est sur une page locale on rend accès aux statistiques globales
            if (requestName != null)
            {
                writer.Write("<li>");
                writer.WriteLine(HtmlPageRenderer.GetLink(context.Zoom(null, null), "Statistiques globales", true));
                writer.WriteLine("</li>");
            }

            writer.WriteLine("</ul>");
            Context targetContext;

            if (requestName == null)
            {
                writer.Write("<h2>Statistiques globales</h2>");
                targetContext = context;
            }
            else
            {
                writer.Write("<h2>Statistiques pour ");
                writer.Write(requestName);
                writer.WriteLine("</h2>");
                targetContext = context.Zoom(null, null);
            }

            ICube cube = hyperCube.GetCube(new CounterCubeCriteria(requestName, TimeLevel.Hour).CreateCubeKey(context.EndDate));

            if (cube != null)
            {
                // On affiche les données relative au cube
                bool link = requestName == null; // Si pas de request précisé on met les liens.
                RenderCube(hyperCube, cube, writer, link, targetContext);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Rendu d'un hypercube en sparklines.
        /// </summary>
        /// <param name="context">Context courant de la requête.</param>
        /// <param name="hyperCube">Hypercube contenant les données.</param>
        /// <param name="criteria">Critères de lecture de l'hypercube.</param>
        /// <param name="s">Stream de sortie.</param>
        private static void RenderGraphSparklines(Context context, IHyperCube hyperCube, CounterCubeCriteria criteria, Stream s)
        {
            long now = context.EndDate.Ticks;
            long timeStampInterval = criteria.Level.TimeStampInterval;

            decimal[] datas = new decimal[10];

            for (int i = 0; i < datas.Length; i++)
            {
                DateTime d    = new DateTime(now - (i * timeStampInterval * 10000000));
                ICube    cube = hyperCube.GetCube(criteria.CreateCubeKey(d));
                datas[datas.Length - 1 - i] = (cube == null) ? 0 : (decimal)cube.GetCounter(Analytics.ElapsedTime).GetValue(CounterStatType.Hits);
            }

            SparklinesBar sparklines = new SparklinesBar();

            sparklines.CreateChart(s, datas, Color.Blue, Color.Magenta);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Réalise le rendu des labels.
        /// </summary>
        /// <param name="writer">Writer.</param>
        /// <param name="hyperCube">Hypercube contenant les valeurs.</param>
        /// <param name="context">Contexte de la requête.</param>
        /// <param name="requestName">Element demandé.</param>
        /// <returns>Liste des compteurs à rendre.</returns>
        private static Dictionary <string, string> RenderLabels(TextWriter writer, IHyperCube hyperCube, Context context, string requestName)
        {
            bool renderToHtml = writer is HtmlTextWriter;
            Dictionary <string, string> activeCounters = new Dictionary <string, string>();
            ICube globalCube = hyperCube.GetCube(new CounterCubeCriteria(requestName, TimeLevel.Hour).CreateCubeKey(context.EndDate));

            if (globalCube != null)
            {
                foreach (ICounterDefinition counterDefinition in hyperCube.AllDefinitions)
                {
                    ICounter counter = globalCube.GetCounter(counterDefinition.Code);
                    if (counter != null && counter.GetValue(CounterStatType.Hits) > 0)
                    {
                        activeCounters.Add(counterDefinition.Code, counterDefinition.Code);

                        if (renderToHtml)
                        {
                            writer.Write(HtmlPageRenderer.Indent2);
                            writer.Write("<th>");
                            string newSort = counterDefinition.Code;

                            // Le lien n'est actif que si le tri n'est pas déjà effectué
                            writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(newSort), counterDefinition.Label, !newSort.Equals(context.Sort)));
                            writer.WriteLine("</th>");
                        }
                        else
                        {
                            writer.Write(counterDefinition.Label);
                            writer.Write(";");
                        }
                    }
                }

                writer.WriteLine();
            }

            return(activeCounters);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Indique si l'axe d'un hypercube doit être affiché pour un niveau d'alerte.
        /// </summary>
        /// <param name="endDate">Date de fin.</param>
        /// <param name="filtre">Niveau d'alerte (NONE, WARNING, ERROR).</param>
        /// <param name="hyperCube">Hypercube contenant les données.</param>
        /// <param name="criteria">Critère de lecture de l'hypercube.</param>
        /// <returns>True si l'axe doit être affiché.</returns>
        private static bool IsShown(DateTime endDate, string filtre, IHyperCube hyperCube, CounterCubeCriteria criteria)
        {
            bool showIt = false;

            if ("NONE".Equals(filtre))
            {
                showIt = true;
            }
            else
            {
                bool  showWarning = "WARNING".Equals(filtre);
                ICube cube        = hyperCube.GetCube(criteria.CreateCubeKey(endDate));
                if (cube == null)
                {
                    return(false);
                }

                foreach (ICounterDefinition counterDefinition in hyperCube.AllDefinitions)
                {
                    ICounter counter = cube.GetCounter(counterDefinition.Code);
                    if (counter == null)
                    {
                        continue;
                    }

                    // Par défaut, on n'affiche que le niveau critique
                    double midValue = counter.GetValue(CounterStatType.Avg);
                    showIt = (counterDefinition.CriticalThreshold >= 0 && midValue > counterDefinition.CriticalThreshold) ||
                             (showWarning && counterDefinition.WarningThreshold >= 0 && midValue > counterDefinition.WarningThreshold);
                    if (showIt)
                    {
                        break;
                    }
                }
            }

            return(showIt);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Réalise le rendu d'un hypercube axe par axe.
        /// </summary>
        /// <param name="hyperCube">Hypercube contenant les valeurs.</param>
        /// <param name="context">Contexte de la requête.</param>
        /// <param name="writer">Writer HTML.</param>
        internal static void ToTable(IHyperCube hyperCube, Context context, HtmlTextWriter writer)
        {
            string        requestName = context.GetRequestName(hyperCube.Name);
            List <string> axisList    = GetAllAxis(context.EndDate, hyperCube, context.Sort);

            writer.WriteLine("<h2>Nombre de requêtes (" + axisList.Count + ")</h2>");

            writer.Write("Filtre : ");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeFiltre("NONE"), "aucun", !"NONE".Equals(context.Filtre)));
            writer.Write(", ");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeFiltre("WARNING"), "warning", !"WARNING".Equals(context.Filtre)));
            writer.Write(", ");
            writer.WriteLine(HtmlPageRenderer.GetLink(context.ChangeFiltre(null), "critique", context.Filtre != null));
            writer.WriteLine(string.Empty);

            writer.WriteLine("<table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" width=\"100%\">");

            writer.Write(HtmlPageRenderer.Indent);
            writer.WriteLine("<tr>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<th>");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(null), "Requête", context.Sort != null));
            writer.WriteLine("</th>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<th>");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort("TOTAL"), "total (ms)", !"TOTAL".Equals(context.Sort)));
            writer.WriteLine("</th>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<th>");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort(Analytics.ElapsedTime), "avg (ms)", !Analytics.ElapsedTime.Equals(context.Sort)));
            writer.WriteLine("</th>");

            writer.Write(HtmlPageRenderer.Indent2);
            writer.Write("<th colspan='2'>");
            writer.Write(HtmlPageRenderer.GetLink(context.ChangeSort("HITS"), "hits", !"HITS".Equals(context.Sort)));
            writer.WriteLine("</th>");

            Dictionary <string, string> activeCounters = RenderLabels(writer, hyperCube, context, requestName);

            writer.Write(HtmlPageRenderer.Indent);
            writer.WriteLine("</tr>");

            bool odd = true;

            foreach (string axis in axisList)
            {
                CounterCubeCriteria criteria = new CounterCubeCriteria(axis, TimeLevel.Hour);
                ICube cube = hyperCube.GetCube(criteria.CreateCubeKey(context.EndDate));
                if (cube != null && IsShown(context.EndDate, context.Filtre, hyperCube, criteria))
                {
                    CreateHtmlAxis(hyperCube, context, writer, requestName, activeCounters, odd, axis, criteria, cube);
                    odd = !odd;
                }
            }

            writer.WriteLine("</table>");
            writer.WriteLine(string.Empty);
            writer.WriteLine("<a href=\"" + context.Export(hyperCube.Name).GetHandlerUrl() + "\">Exporter</a>");
        }