Ejemplo n.º 1
0
        /// <summary>
        /// Gather statistics for one or all indices.
        /// </summary>
        /// <param name="name">Optional name of the index.</param>
        /// <returns>Indices statistics.</returns>
        public IndicesStats Stats(string name)
        {
            IndicesStats ret = new IndicesStats();

            if (String.IsNullOrEmpty(name))
            {
                lock (_IndicesLock)
                {
                    foreach (KomodoIndex curr in _Indices)
                    {
                        ret.Stats.Add(curr.Stats());
                    }
                }
            }
            else
            {
                lock (_IndicesLock)
                {
                    if (_Indices.Any(i => i.Name.Equals(name)))
                    {
                        KomodoIndex idx = _Indices.First(i => i.Name.Equals(name));
                        ret.Stats.Add(idx.Stats());
                    }
                    else
                    {
                        // cannot find
                        return(ret);
                    }
                }
            }

            ret.Success  = true;
            ret.Time.End = DateTime.UtcNow;
            return(ret);
        }
Ejemplo n.º 2
0
        private static async Task GetIndexStats(RequestMetadata md)
        {
            string header = "[Komodo.Server] " + md.Http.Request.Source.IpAddress + ":" + md.Http.Request.Source.Port + " GetIndexStats ";

            string       indexName = md.Http.Request.Url.Elements[0];
            IndicesStats stats     = _Daemon.GetIndexStats(indexName);

            if (stats == null)
            {
                if (String.IsNullOrEmpty(indexName))
                {
                    _Logging.Warn(header + "index " + indexName + " does not exist");
                    md.Http.Response.StatusCode  = 404;
                    md.Http.Response.ContentType = "application/json";
                    await md.Http.Response.Send(new ErrorResponse(404, "Unknown index.", null, null).ToJson(true));
                }
                else
                {
                    _Logging.Warn(header + "no indices found");
                    md.Http.Response.StatusCode  = 404;
                    md.Http.Response.ContentType = "application/json";
                    await md.Http.Response.Send(new ErrorResponse(404, "No indices found.", null, null).ToJson(true));
                }

                return;
            }

            md.Http.Response.StatusCode  = 200;
            md.Http.Response.ContentType = "application/json";
            await md.Http.Response.Send(Common.SerializeJson(stats, md.Params.Pretty));

            return;
        }
Ejemplo n.º 3
0
        static void IndexStats()
        {
            string       indexName = Common.InputString("Index name (null for all indices):", null, true);
            IndicesStats stats     = _Komodo.GetIndexStats(indexName);

            if (stats == null)
            {
                Console.WriteLine("(none)");
            }
            else
            {
                Console.WriteLine(Common.SerializeJson(stats, true));
            }
        }
Ejemplo n.º 4
0
        public static ElasticsearchIndexStats ToElasticsearchIndexStats(this IndicesStats stats)
        {
            // Validate parameters.
            if (stats == null)
            {
                throw new ArgumentNullException(nameof(stats));
            }

            // Create the new instance and return.
            return(new ElasticsearchIndexStats(
                       stats.Total.Documents.Count,
                       (long)stats.Total.Store.SizeInBytes
                       ));
        }