Beispiel #1
0
        public void CacheServerStatistics()
        {
            ArrayList           servers      = null;
            bool                isPOR        = false;
            bool                isRegistered = true;
            List <ICacheServer> cacheServers = new List <ICacheServer>();

            if (!ValidateParameters())
            {
                return;
            }
            if (Servers != null && !Servers.Equals(""))
            {
                servers = GetServers(Servers);
            }
            else
            {
                servers = new ArrayList();
                NCacheRPCService nCache = new NCacheRPCService("");
                servers.Add(nCache.ServerName);
            }
            foreach (var server in servers)
            {
                NCacheRPCService nCache = new NCacheRPCService(server.ToString());
                try
                {
                    ICacheServer cacheServer = nCache.GetCacheServer(new TimeSpan(0, 0, 0, 30));
                    serverList.Add(cacheServer.GetBindIP());
                    NodeStatus status = GetCacheStatistics(nCache);
                    if (status.isRegistered == false)
                    {
                        throw new Exception("The specified cache is not registered on server " + server);
                    }

                    isPOR = status.Topology == Topology.POR;
                    cacheServers.Add(cacheServer);
                    //array of it ICacheServer
                }
                catch (Exception ex)
                {
                    if (ex.Message.Contains("The specified cache is not registered"))
                    {
                        OutputProvider.WriteErrorLine(ex.Message);
                        isRegistered = false;
                    }
                    else if (ex.Message.ToUpper().Contains("service".ToUpper()))
                    {
                        OutputProvider.WriteErrorLine("NCache Service could not be contacted on server " + server);
                        isRegistered = false;
                    }
                }
            }
            if (isRegistered)
            {
                _mainCounters = GetAllCounters(false);
                if (isPOR)
                {
                    _replicaCounters = GetAllCounters(true);
                }
                if (!(Format.Equals("csv", StringComparison.OrdinalIgnoreCase) || Format.Equals("tabular", StringComparison.OrdinalIgnoreCase)))
                {
                    throw new ArgumentException("Invalid Format type");
                }
                if (Continuous && MaxSamples > 0)
                {
                    throw new Exception("The Continuous parameter and the MaxSamples parameter cannot be used in the same command.");
                }
                if (Continuous && Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                {
                    FetchAndDisplayContinousulyCSV(cacheServers, isPOR);
                }
                else if (Continuous && Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                {
                    ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                    FetchAndDisplayContinousuly(cacheServers, isPOR);
                }
                else if (MaxSamples > 0)
                {
                    if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                    {
                        ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                        FetchAndDisplayMax(cacheServers, isPOR);
                    }
                    else if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                    {
                        FetchAndDisplayMaxCSV(cacheServers, isPOR);
                    }
                }
                if (!Continuous && MaxSamples == 0)
                {
                    try
                    {
                        SortedDictionary <string, string[]> CountList = FetchCounters(cacheServers, isPOR);
                        if (Format.Equals("csv", StringComparison.OrdinalIgnoreCase))
                        {
                            DisplayinCSVFormat(CountList, isPOR);
                        }
                        else if (Format.Equals("tabular", StringComparison.OrdinalIgnoreCase))
                        {
                            ToolsUtil.PrintLogo(OutputProvider, printLogo, TOOLNAME);
                            DisplayTimeStamp();
                            DisplayCounters(CountList, isPOR);
                        }
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                    catch (Exception ex)
                    {
                        OutputProvider.WriteErrorLine(ex);
                    }
                }
            }
            OutputProvider.WriteLine("\n");
        }