コード例 #1
0
        private string GetWarnningInfo(CollectConfig config, tb_cluster_monitorinfo_model model, tb_cluster_model cluster)
        {
            string msg = "";

            var monitorinfos = new XXF.Serialization.JsonHelper().Deserialize <List <ClusterMonitorInfo> >(model.monitorinfojson);

            foreach (var info in monitorinfos)
            {
                if (info.Name == config.CollectName)
                {
                    if (config.EqualWarningValue != null && config.EqualWarningValue.IsWarning == true && config.EqualWarningValue.Value == info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】等于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.EqualWarningValue.Value, cluster.servername);
                    }
                    if (config.LessThanWarningValue != null && config.LessThanWarningValue.IsWarning == true && config.LessThanWarningValue.Value > info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】小于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.LessThanWarningValue.Value, cluster.servername);
                    }
                    if (config.MoreThanWarningValue != null && config.MoreThanWarningValue.IsWarning == true && config.MoreThanWarningValue.Value < info.MonitorValue)
                    {
                        msg += string.Format("【id:{2},{4}】检测项【{0}】大于预警值{3},当前值为{1}\r\n", config.CollectName, info.MonitorValue, model.serverid, config.MoreThanWarningValue.Value, cluster.servername);
                    }
                }
            }
            return(msg);
        }
 public PerformanceCounterCollectTask(CollectConfig config)
 {
     this.Name            = config.CollectName;
     counter              = new PerformanceCounter();
     counter.CategoryName = config.CategoryName;
     counter.CounterName  = config.CounterName;
     counter.InstanceName = config.InstanceName;
     counter.MachineName  = ".";
     try
     {
         Collect();//开启采集
         System.Threading.Thread.Sleep(100);
     }
     catch { }
 }