Beispiel #1
0
        public async Task <string> GetClusterTableAsync()
        {
            Cluster[] clusters = await ClusterInfo.GetClustersAsync();

            StringBuilder sb = new StringBuilder();

            sb.AppendLine(
                "<tr><th>Cluster name</th>" +
                "<th>Elasticsearch url/Index</th>" +
                "<th class='number'>Indices</th>" +
                "<th class='number'>Documents</th>" +
                "<th class='number'>Size</th>" +
                "<th>Kibana url</th></tr>");

            foreach (var cluster in clusters.OrderBy(c => c.name))
            {
                long   clustersize       = cluster.indices.Sum(i => i.storesize);
                string prettysizetooltip = GetPrettyTooltip(clustersize);
                if (cluster.kibanaurl != null)
                {
                    sb.AppendLine(
                        $"<tr><td>{cluster.name}</td>" +
                        $"<td><a href='{cluster.url}' target='_blank'>{cluster.url}</a></td>" +
                        $"<td class='number'>{cluster.indices.Count}</td>" +
                        $"<td class='number'>{cluster.indices.Sum(i => i.documentcount)}</td>" +
                        $"<td class='number'{prettysizetooltip}>{clustersize}</td>" +
                        $"<td><a href='{cluster.kibanaurl}' target='_blank'>{cluster.kibanaurl}</a></td></tr>");
                }
                else
                {
                    sb.AppendLine(
                        $"<tr><td>{cluster.name}</td>" +
                        $"<td><a href='{cluster.url}' target='_blank'>{cluster.url}</a></td>" +
                        $"<td class='number'>{cluster.indices.Count}</td>" +
                        $"<td class='number'>{cluster.indices.Sum(i => i.documentcount)}</td>" +
                        $"<td class='number'{prettysizetooltip}>{clustersize}</td></tr>");
                }

                foreach (var index in cluster.compactindices.OrderBy(i => i.name))
                {
                    sb.AppendLine(
                        $"<tr><td></td>" +
                        $"<td>{index.name}</td>" +
                        $"<td class='number'>{index.realindices.Count}</td>" +
                        $"<td class='number'>{index.documentcount}</td>" +
                        $"<td class='number'{GetPrettyTooltip(index.storesize)}>{index.storesize}</td></tr>");
                }
            }

            long   storesize      = clusters.Sum(c => c.compactindices.Sum(i => i.storesize));
            string storesizeshort = GetPrettySize(storesize);

            if (storesizeshort != string.Empty)
            {
                storesizeshort = $" ({storesizeshort})";
            }

            string content =
                "<html><body>" + Environment.NewLine +
                "<style>" + Environment.NewLine +
                "table { border-collapse: collapse; }" + Environment.NewLine +
                "p { font-family: sans-serif; }" + Environment.NewLine +
                "td, th { font-family: sans-serif; text-align: left; white-space: nowrap; }" + Environment.NewLine +
                "td.number, th.number { text-align: right; }" + Environment.NewLine +
                "</style>" + Environment.NewLine +
                "<table border='1'>" + Environment.NewLine +
                sb.ToString() +
                "</table>" + Environment.NewLine +
                $"<p>Total clusters: {clusters.Length}<br/>" + Environment.NewLine +
                $"Total indices: {clusters.Sum(c => c.indices.Count)}<br/>" + Environment.NewLine +
                $"Total documents: {clusters.Sum(c => c.compactindices.Sum(i => i.documentcount))}<br/>" + Environment.NewLine +
                $"Total storesize: {storesize}{storesizeshort}</p>" + Environment.NewLine +
                "</html></body>" + Environment.NewLine;

            return(content);
        }