예제 #1
0
        /// <summary>
        /// 监控系统整体性能
        /// </summary>
        public void MonitorAll()
        {
            PC.CategoryName = "Processor";        //指定获取计算机进程信息  如果传Processor参数代表查询计算机CPU
            PC.CounterName  = "% Processor Time"; //占有率
            PC.InstanceName = "_Total";
            float cpuValue = PC.NextValue();

            Thread.Sleep(TimeSpan.FromSeconds(1));
            cpuValue = PC.NextValue();
            PostDataToServer(Math.Round(cpuValue, 2).ToString(), saveDir, "");

            if (ConfigContext.GetInstance().MaxCPU < cpuValue)
            {
                if (ContinuousManage.GetInstance().GetIsWaring(CpuMonitorKey + _serverIP + PC.CounterName))
                {
                    string title   = _serverIP + "机器CPU过高";
                    string content = string.Format("IP:{2} CPU:{0},高于警戒值:{1}", cpuValue.ToString(), ConfigContext.GetInstance().MaxCPU.ToString(), _serverIP);

                    //Modify post trace
                    string planName  = string.Format("{0},CPU高于警戒值", _serverIP);
                    string planValue = string.Format("{0}/{1}", Math.Round(cpuValue, 2), ConfigContext.GetInstance().MaxCPU);
                    OaSimplePlanHelper.PostDataToServer(planName, planValue);
                    LogHelper.WriteException("CPU监视[" + _serverIP + "]>>", new Exception(content));
                    Mail139Helper.SendMail(title, content, ConfigContext.GetInstance().SendTo139Mail, true);
                }
            }
            else
            {
                ContinuousManage.GetInstance().Reset(CpuMonitorKey + _serverIP + PC.CounterName);
            }
        }
예제 #2
0
        public void SearchSimplePlanInfo()
        {
            try
            {
                string pcName      = Dns.GetHostName();
                var    messageList = MessageQueue.GetPrivateQueuesByMachine(pcName);
                foreach (var queue in messageList)
                {
                    int queueCount = -1;
                    try
                    {
                        queueCount = queue.GetAllMessages().Length;
                    }
                    catch (Exception ex)
                    {
                    }
                    OaSimplePlanHelper.PostDataToServer(PlanType.msmq, queue.QueueName, queueCount);

                    if ((queueCount > MaxErrorQueue && queue.QueueName.ToLower().IndexOf("errorlogcmdsql") != -1) ||
                        (queueCount > ConfigContext.GetInstance().CitQueueMaxCount))
                    {
                        if (ContinuousManage.GetInstance().GetIsWaring(SimplePlanInfoKey + _serverIP + queue.QueueName))
                        {
                            string title   = _serverIP + "服务器消息队列异常";
                            string content = string.Format("队列服务器:{0}<br />队列名称:{1}<br />队列总数:{2}<br />",
                                                           _serverIP,
                                                           queue.QueueName,
                                                           queueCount
                                                           );
                            int maxQueueCount = ConfigContext.GetInstance().CitQueueMaxCount;
                            if (queue.QueueName.ToLower().IndexOf("errorlogcmdsql") != -1)
                            {
                                maxQueueCount = MaxErrorQueue;
                            }
                            //Modify post trace
                            string planName  = string.Format("{0},消息队列{1}高于警戒值", _serverIP, queue.QueueName);
                            string planValue = string.Format("{0}/{1}", queueCount, maxQueueCount);
                            OaSimplePlanHelper.PostDataToServer(planName, planValue);
                            LogHelper.WriteException("服务器消息队列监视[" + _serverIP + "]>>", new Exception(content));

                            Mail139Helper.SendMail(title, content, ConfigContext.GetInstance().SendTo139Mail, true);
                        }
                    }
                    else
                    {
                        ContinuousManage.GetInstance().Reset(SimplePlanInfoKey + _serverIP + queue.QueueName);
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteException("MSMQ information error", ex);
            }
        }
예제 #3
0
        private void RequestServer(object state)
        {
            if (state is ServerInfo)
            {
                var server = state as ServerInfo;
                //Logger.SaveLog(string.Format("游戏登录监视>>{0}[{1}]请求开始", server.GameName, server.Name));
                StringBuilder requestParams = new StringBuilder();
                requestParams.AppendFormat("{0}={1}", "ActionID", 1004);
                requestParams.AppendFormat("&{0}={1}", "Sid", "");
                requestParams.AppendFormat("&{0}={1}", "Uid", "");
                requestParams.AppendFormat("&{0}={1}", "MobileType", 1);
                requestParams.AppendFormat("&{0}={1}", "Pid", GameLogin_Id);
                requestParams.AppendFormat("&{0}={1}", "Pwd", GameLogin_pwd);
                requestParams.AppendFormat("&{0}={1}", "DeviceID", HttpUtility.UrlEncode("00-00-00-00-00-4A", Encoding.UTF8));
                requestParams.AppendFormat("&{0}={1}", "GameType", server.GameID);
                requestParams.AppendFormat("&{0}={1}", "ServerID", server.ID);
                requestParams.AppendFormat("&{0}={1}", "RetailID", "0000");
                requestParams.AppendFormat("&{0}={1}", "RetailUser", "");

                string  errorInfo = string.Empty;
                Message msg       = new Message();
                using (MessageReader msgReader = MessageReader.Create(server.BaseUrl, requestParams.ToString(), msg))
                {
                    if (msgReader == null)
                    {
                        return;
                    }

                    if (msg.ErrorCode != 0)
                    {
                        errorInfo = string.Format("游戏登录监视>>{0}[{4}服-{1}]登录出错,Error:{2}-{3}", server.GameName, server.Name, msg.ErrorCode, msg.ErrorInfo, server.ID);
                        Logger.SaveLog(new Exception(errorInfo));


                        //Modify post trace
                        string planName  = string.Format("监视游戏:{0},服:{1}登录失败", server.GameName, server.Name);
                        string planValue = string.Format("{0}:{1}", msg.ErrorCode, msg.ErrorInfo);
                        OaSimplePlanHelper.PostDataToServer(planName, planValue);
                    }
                    else
                    {
                        Logger.SaveLog(string.Format("Game login surveillance >> {0} {2} dress - {1}] successful login", server.GameName, server.Name, server.ID));
                    }
                }

                if (!string.IsNullOrEmpty(errorInfo))
                {
                    SendToMail(errorInfo);
                }
            }
        }
예제 #4
0
        //public void Test()
        //{
        //    try
        //    {
        //        string dbName = "CkTjx5Data";
        //        string path = IsNetBackup ? _netWorkPath : DbBackupPath;
        //        if (!OpenNetAddress(path, _netWorkUser, _netWorkPassword))
        //        {
        //            Logger.SaveLog("网络路径" + path + "找开失败");
        //            return;
        //        }
        //        BackupDatabase(path, dbName);
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine(ex.Message);
        //    }
        //}

        protected override bool DoProcess(object obj)
        {
            try
            {
                string path = IsNetBackup ? _netWorkPath : DbBackupPath;
                Logger.SaveLog("DbBackupWatch start...");
                if (IsNetBackup)
                {
                    if (!OpenNetAddress(path, _netWorkUser, _netWorkPassword))
                    {
                        Logger.SaveLog("Network path " + path + " Unable to connect.");
                        string planName = string.Format("{0}数据库自动备份", GetServerIP());
                        OaSimplePlanHelper.PostDataToServer(planName, "网络路径" + path + "无法连接");
                        return(false);
                    }

                    Logger.SaveLog("Is to clean up the database backup...");
                    ClearBackupDb(path);
                    Logger.SaveLog("The end of the clean database backup.");
                    BackupAll(path);
                }
                else
                {
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    lock (thisLock)
                    {
                        Logger.SaveLog("Is to clean up the database backup...");
                        ClearBackupDb(path);
                        Logger.SaveLog("The end of the clean database backup.");
                        BackupAll(path);
                    }
                }
                Logger.SaveLog("DbBackupWatch end.");
                return(true);
            }
            catch (Exception ex)
            {
                Logger.SaveLog(ex);
                return(false);
            }
        }
예제 #5
0
파일: BaseWatch.cs 프로젝트: dongliang/Scut
 public string GetServerIP()
 {
     return(OaSimplePlanHelper.GetServerIP());
 }
예제 #6
0
        /// <summary>
        /// 检查服务器磁盘空间容量
        /// </summary>
        public void CheckDriveInfo()
        {
            try
            {
                DriveInfo[]   alldrive   = DriveInfo.GetDrives();
                List <string> listWaring = new List <string>();
                foreach (DriveInfo d in alldrive)
                {
                    if (d.DriveType == DriveType.Fixed)
                    {
                        DriveWaring checkItem = null;
                        foreach (DriveWaring driveItem in ConfigContext.GetInstance().DriveWaringSet)
                        {
                            if (d.Name.IndexOf(driveItem.DriveName) != -1)
                            {
                                checkItem = driveItem;
                                break;
                            }
                        }

                        int curFreeSpace = Convert.ToInt32(d.TotalFreeSpace / 1048576); //计算剩余多少M
                        int waringSize   = 10000;
                        if (checkItem != null)
                        {
                            waringSize = checkItem.WaringSize;
                        }

                        PostDataToServer(_serverIP, d.Name, curFreeSpace);

                        string waringKey = DriveInfoKey + _serverIP + d.Name;
                        if (curFreeSpace < waringSize)
                        {
                            if (ContinuousManage.GetInstance().GetIsWaring(waringKey))
                            {
                                string content = string.Format("磁盘:{0},剩余空间:{1}MB,低于警戒值:{2}MB<br />", d.Name,
                                                               curFreeSpace, waringSize);
                                listWaring.Add(content);

                                //Modify post trace
                                string planName  = string.Format("{0},磁盘:{1}低于警戒值", _serverIP, d.Name);
                                string planValue = string.Format("{0}/{1}MB", curFreeSpace, waringSize);
                                OaSimplePlanHelper.PostDataToServer(planName, planValue);
                            }
                        }
                        else
                        {
                            ContinuousManage.GetInstance().Reset(waringKey);
                        }
                    }
                }
                if (listWaring.Count > 0)
                {
                    if (ContinuousManage.GetInstance().GetIsWaring(DriveInfoKey + _serverIP))
                    {
                        string title   = _serverIP + "磁盘空间不足";
                        string content = string.Format("共{0}个磁盘空间不足<br />", listWaring.Count);
                        foreach (string item in listWaring)
                        {
                            content += item;
                        }

                        LogHelper.WriteException("Disk monitoring [" + _serverIP + "]>>", new Exception(content));
                        Mail139Helper.SendMail(title, content, ConfigContext.GetInstance().SendTo139Mail, true);
                    }
                }
                else
                {
                    ContinuousManage.GetInstance().Reset(DriveInfoKey + _serverIP);
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteException("Check server disk space remaining capacity error", ex);
            }
        }