Exemplo n.º 1
0
        private static Dictionary<string, LinkModel> getLinkModel(string ip, out PCData pcdata, out double memCount)
        {
            NetTcpBinding binging = new NetTcpBinding();
            binging.MaxBufferPoolSize = 524288;
            binging.MaxBufferSize = 2147483647;
            binging.MaxReceivedMessageSize = 2147483647;
            binging.MaxConnections = 1000;
            binging.ListenBacklog = 200;
            binging.OpenTimeout = TimeSpan.Parse("00:10:00");
            binging.ReceiveTimeout = TimeSpan.Parse("00:10:00");
            binging.TransferMode = TransferMode.Buffered;
            binging.Security.Mode = SecurityMode.None;

            binging.SendTimeout = TimeSpan.Parse("00:10:00");
            binging.ReaderQuotas.MaxDepth = 64;
            binging.ReaderQuotas.MaxStringContentLength = 2147483647;
            binging.ReaderQuotas.MaxArrayLength = 16384;
            binging.ReaderQuotas.MaxBytesPerRead = 4096;
            binging.ReaderQuotas.MaxNameTableCharCount = 16384;
            binging.ReliableSession.Ordered = true;
            binging.ReliableSession.Enabled = false;
            binging.ReliableSession.InactivityTimeout = TimeSpan.Parse("00:10:00");

            Dictionary<string, LinkModel> modellist = new Dictionary<string, LinkModel>();
            using (MonitorClient client = MonitorClient.Instance)
            {
                IMonitorControl proxy = client.getProxy(ip, binging);
                modellist = proxy.GetMonitorInfo(out pcdata, out memCount);
            }

            return modellist;
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取wcf监控信息
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, LinkModel> GetMonitorInfo(out PCData pcdata, out double memCount)
        {
            Process CurrentProcess = Process.GetCurrentProcess();
            pcdata = new PCData();
            try
            {
                pcdata.ProcessId = CurrentProcess.Id;
            }
            catch { }
            try
            {
                //创建性能计数器
                using (var p_cpu = new PerformanceCounter("Process", "% Processor Time", CurrentProcess.ProcessName))
                {
                    //注意除以CPU数量
                    pcdata.Cpu = p_cpu.NextValue() / (float)Environment.ProcessorCount;
                }
            }
            catch { }
            try
            {
                using (var p_mem = new PerformanceCounter("Process", "Working Set - Private", CurrentProcess.ProcessName))
                {
                    pcdata.Mem = p_mem.NextValue() / (1024 * 1024);
                }
            }
            catch { }
            try
            {
                pcdata.ThreadCount = CurrentProcess.Threads.Count;
            }
            catch { }
            try
            {
                #region 获取系统总内存
                if (_memcount == 1)
                {
                    lock (lockhelper)
                    {
                        if (_memcount == 1)
                        {
                            ManagementObjectSearcher searcher = new ManagementObjectSearcher();   //用于查询一些如系统信息的管理对象 
                            searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" });//设置查询条件 
                            ManagementObjectCollection collection = searcher.Get();   //获取内存容量 
                            ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

                            long capacity = 0;
                            while (em.MoveNext())
                            {
                                ManagementBaseObject baseObj = em.Current;
                                if (baseObj.Properties["Capacity"].Value != null)
                                {
                                    try
                                    {
                                        capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
                                    }
                                    catch { }
                                }
                            }
                            _memcount = (double)capacity / (double)1024 / (double)1024;
                        }
                    }
                }
                #endregion
            }
            catch { }

            memCount = _memcount;
            return MonitorData.Instance.getMonitorInfo();
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取wcf监控信息
        /// </summary>
        /// <returns></returns>
        public Dictionary <string, LinkModel> GetMonitorInfo(out PCData pcdata, out double memCount)
        {
            Process CurrentProcess = Process.GetCurrentProcess();

            pcdata = new PCData();
            try
            {
                pcdata.ProcessId = CurrentProcess.Id;
            }
            catch { }
            try
            {
                //创建性能计数器
                using (var p_cpu = new PerformanceCounter("Process", "% Processor Time", CurrentProcess.ProcessName))
                {
                    //注意除以CPU数量
                    pcdata.Cpu = p_cpu.NextValue() / (float)Environment.ProcessorCount;
                }
            }
            catch { }
            try
            {
                using (var p_mem = new PerformanceCounter("Process", "Working Set - Private", CurrentProcess.ProcessName))
                {
                    pcdata.Mem = p_mem.NextValue() / (1024 * 1024);
                }
            }
            catch { }
            try
            {
                pcdata.ThreadCount = CurrentProcess.Threads.Count;
            }
            catch { }
            try
            {
                #region 获取系统总内存
                if (_memcount == 1)
                {
                    lock (lockhelper)
                    {
                        if (_memcount == 1)
                        {
                            ManagementObjectSearcher searcher = new ManagementObjectSearcher();                         //用于查询一些如系统信息的管理对象
                            searcher.Query = new SelectQuery("Win32_PhysicalMemory ", "", new string[] { "Capacity" }); //设置查询条件
                            ManagementObjectCollection collection = searcher.Get();                                     //获取内存容量
                            ManagementObjectCollection.ManagementObjectEnumerator em = collection.GetEnumerator();

                            long capacity = 0;
                            while (em.MoveNext())
                            {
                                ManagementBaseObject baseObj = em.Current;
                                if (baseObj.Properties["Capacity"].Value != null)
                                {
                                    try
                                    {
                                        capacity += long.Parse(baseObj.Properties["Capacity"].Value.ToString());
                                    }
                                    catch { }
                                }
                            }
                            _memcount = (double)capacity / (double)1024 / (double)1024;
                        }
                    }
                }
                #endregion
            }
            catch { }

            memCount = _memcount;
            return(MonitorData.Instance.getMonitorInfo());
        }