Пример #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 virtual tb_cluster_monitorinfo_model CreateModel(DataRow dr)
        {
            var o = new tb_cluster_monitorinfo_model();

            //
            if (dr.Table.Columns.Contains("id"))
            {
                o.id = dr["id"].Toint();
            }
            //服务器id
            if (dr.Table.Columns.Contains("serverid"))
            {
                o.serverid = dr["serverid"].Toint();
            }
            //服务器监控得到的各项指标信息
            if (dr.Table.Columns.Contains("monitorinfojson"))
            {
                o.monitorinfojson = dr["monitorinfojson"].Tostring();
            }
            //上次服务器更新时间
            if (dr.Table.Columns.Contains("lastupdatetime"))
            {
                o.lastupdatetime = dr["lastupdatetime"].ToDateTime();
            }
            return(o);
        }
        public virtual bool Add(DbConn PubConn, tb_cluster_monitorinfo_model model)
        {
            List <ProcedureParameter> Par = new List <ProcedureParameter>()
            {
                //服务器id
                new ProcedureParameter("@serverid", model.serverid),
                //服务器监控得到的各项指标信息
                new ProcedureParameter("@monitorinfojson", model.monitorinfojson),
                //上次服务器更新时间
                new ProcedureParameter("@lastupdatetime", model.lastupdatetime)
            };
            int rev = PubConn.ExecuteSql(@"insert into tb_cluster_monitorinfo(serverid,monitorinfojson,lastupdatetime)
										   values(@serverid,@monitorinfojson,@lastupdatetime)"                                        , Par);

            return(rev == 1);
        }
        public virtual bool Edit(DbConn PubConn, tb_cluster_monitorinfo_model model)
        {
            List <ProcedureParameter> Par = new List <ProcedureParameter>()
            {
                //服务器id
                new ProcedureParameter("@serverid", model.serverid),
                //服务器监控得到的各项指标信息
                new ProcedureParameter("@monitorinfojson", model.monitorinfojson),
                //上次服务器更新时间
                new ProcedureParameter("@lastupdatetime", model.lastupdatetime)
            };

            Par.Add(new ProcedureParameter("@id", model.id));

            int rev = PubConn.ExecuteSql("update tb_cluster_monitorinfo set serverid=@serverid,monitorinfojson=@monitorinfojson,lastupdatetime=@lastupdatetime where id=@id", Par);

            return(rev == 1);
        }
Пример #5
0
        public void AddOrUpdate(DbConn PubConn, tb_cluster_monitorinfo_model model)
        {
            SqlHelper.Visit(ps =>
            {
                ps.Add("@monitorinfojson", model.monitorinfojson);
                ps.Add("@lastupdatetime", model.lastupdatetime);
                ps.Add("@serverid", model.serverid);

                string updatecmd = "update tb_cluster_monitorinfo set monitorinfojson=@monitorinfojson,lastupdatetime=@lastupdatetime where serverid=@serverid";
                string insertcmd = @"insert into tb_cluster_monitorinfo(serverid,monitorinfojson,lastupdatetime)
										   values(@serverid,@monitorinfojson,@lastupdatetime)"                                        ;
                if (PubConn.ExecuteSql(updatecmd, ps.ToParameters()) <= 0)
                {
                    PubConn.ExecuteSql(insertcmd, ps.ToParameters());
                }
                return(1);
            });
        }
Пример #6
0
        /// <summary>
        /// 检查监控信息的预警
        /// </summary>
        private void CheckMonitorInfoWarning()
        {
            try
            {
                string waringmsg = "";
                List <tb_cluster_model> clusters = new List <tb_cluster_model>();
                SqlHelper.ExcuteSql(GlobalConfig.MonitorPlatformManageConnectString, (c) =>
                {
                    tb_cluster_dal dal = new tb_cluster_dal();
                    clusters           = dal.GetAllList(c);
                });
                clusters.ForEach(o =>
                {
                    if (o.ifmonitor == true)
                    {
                        tb_cluster_monitorinfo_model monitorinfo = null;
                        SqlHelper.ExcuteSql(MonitorClusterConnectString, (c) =>
                        {
                            tb_cluster_monitorinfo_dal dal = new tb_cluster_monitorinfo_dal();
                            monitorinfo = dal.GetByServerId(c, o.id);
                        });
                        if (monitorinfo != null)
                        {
                            var collectconfigs = new XXF.Serialization.JsonHelper().Deserialize <List <CollectConfig> >(o.monitorcollectconfigjson);
                            foreach (var config in collectconfigs)
                            {
                                waringmsg += GetWarnningInfo(config, monitorinfo, o);
                            }
                        }
                    }
                });

                if (waringmsg != "")
                {
                    TaskLogHelper.Error("检查监控信息的预警", "服务器性能检查(预警值检查)" + "\r\n" + waringmsg, "集群性能预警任务");
                }
            }
            catch (Exception exp)
            {
                this.OpenOperator.Error("【集群性能预警任务】检查监控信息的预警", exp);
            }
        }
Пример #7
0
        public List <tb_cluster_monitorinfo_model> GetList(DbConn PubConn, string keyword, string serverid, string monitorjsonkeyword, int pagesize, int pageindex, out int count)
        {
            int _count = 0;
            List <tb_cluster_monitorinfo_model> model = new List <tb_cluster_monitorinfo_model>();
            DataSet dsList = SqlHelper.Visit <DataSet>(ps =>
            {
                string sqlwhere = " and 1=1 ";
                DateTime date   = DateTime.Now;
                if (!string.IsNullOrWhiteSpace(serverid))
                {
                    ps.Add("serverid", serverid);
                    sqlwhere += " and M.serverid = @serverid ";
                }
                if (!string.IsNullOrWhiteSpace(keyword))
                {
                    ps.Add("keyword", keyword);
                    sqlwhere += " and (C.serverip like '%'+@keyword+'%' or C.servername like '%'+@keyword+'%') ";
                }
                if (!string.IsNullOrWhiteSpace(monitorjsonkeyword))
                {
                    ps.Add("monitorjsonkeyword", monitorjsonkeyword);
                    sqlwhere += " and (M.monitorinfojson like '%'+@monitorjsonkeyword+'%') ";
                }
                StringBuilder sql = new StringBuilder();
                sql.Append("select ROW_NUMBER() over(order by M.id desc) as rownum,M.*,C.serverip,C.servername from tb_cluster_monitorinfo M with (nolock), [dyd_bs_monitor_platform_manage].[dbo].[tb_cluster] C with (nolock) where M.serverid=C.id ");
                _count        = Convert.ToInt32(PubConn.ExecuteScalar("select count(1) from tb_cluster_monitorinfo M left join [dyd_bs_monitor_platform_manage].[dbo].[tb_cluster] C on M.serverid=C.id where 1=1 " + sqlwhere, ps.ToParameters()));
                DataSet ds    = new DataSet();
                string sqlSel = "select * from (" + sql + sqlwhere + ") A where rownum between " + ((pageindex - 1) * pagesize + 1) + " and " + pagesize * pageindex;
                PubConn.SqlToDataSet(ds, sqlSel, ps.ToParameters());
                return(ds);
            });

            foreach (DataRow dr in dsList.Tables[0].Rows)
            {
                tb_cluster_monitorinfo_model m = CreateModel(dr);
                m.serverip   = dr["serverip"].Tostring();
                m.servername = dr["servername"].Tostring();
                model.Add(m);
            }
            count = _count;
            return(model);
        }