Esempio n. 1
0
        static void Main(string[] args)
        {
            Console.Title           = "Under Extract";
            Console.CancelKeyPress += new ConsoleCancelEventHandler(CloseConsole);
            Console.WriteLine("------------Icefish Agent------------");
            Console.WriteLine("集群分类:应用");
            Console.WriteLine("当前机器名称: {0}  处理器个数:{1}", Environment.MachineName, Environment.ProcessorCount);
            Console.WriteLine("操作系统版本:" + Environment.OSVersion);
            Console.WriteLine("运行域帐号: {0}\\{1}  收集启动时间:{2}\n\n采集引擎已启动", Environment.UserDomainName, Environment.UserName, DateTime.Now.ToString());
            //临时关闭
            cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total");
            MEMORY_INFO MemInfo;

            MemInfo = new MEMORY_INFO();

            //客户端连接服务器端,创建Socket对象
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            TerminalSocket = socket;
            //连接服务端即可
            try
            {
                socket.Connect(IPAddress.Parse("10.30.3.12"), 3331);  //应用
                Console.WriteLine("性能通道建立,数据传输中...\n (按Ctrl+C退出)");
            }
            catch
            {
                Console.WriteLine("性能数据传输通道验证失败! 〒▽〒 \n请检查主控服务端是否已经开启?\n按Ctrl+C退出...");
                Console.ReadKey();
                return;
            }
            closebtn(); //验证通道后再隐藏哈
            while (true)
            {
                GlobalMemoryStatus(ref MemInfo);
                string percentage = Convert.ToInt32(cpu.NextValue()).ToString();
                string str_data   = string.Format(":{0}:{1}", percentage, MemInfo.dwMemoryLoad.ToString());
                if (TerminalSocket.Connected)
                {
                    byte[] data = Encoding.Default.GetBytes(str_data);
                    try
                    {
                        TerminalSocket.Send(data, 0, data.Length, SocketFlags.None);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("远程服务端口异常关闭:" + ex.ToString());
                        Console.ReadKey();
                    }
                }
                System.Threading.Thread.Sleep(1000);
            }
        }
Esempio n. 2
0
 public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);