国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

IIS應用程序池監控

2019-11-14 16:33:49
字體:
來源:轉載
供稿:網友

最近發現公司運行的web網站應用程序池會突然停止,做的負載均衡(路由負載)又無法監測到IIS應用程序池的情況,就想著通過某一種監控方式監測IIS應用程序池的情況,如果處關閉狀態則立刻重新啟動.所說的IIS應用程序池監控也只能算是偽監控,不喜勿噴.

運行: winform + windows計劃任務

1.首先獲取IIS版本號

    /// <summary>    /// 獲取當前計算機相關信息    /// </summary>    public static class AcquireComputerInfo    {        /// <summary>        /// 獲取當前IIS版本號        /// </summary>        /// <param name="domainname"></param>        /// <returns></returns>        public static string GetIssVersionByDri(string domainname = "")        {            //try            //{            //    if (string.IsNullOrEmpty(domainname))            //    {            //        //如果為空 則默認為本地機器            //        domainname = "LOCALHOST";            //    }            //    DirectoryEntry getEntity = new DirectoryEntry("IIS://" + domainname + "/W3SVC/INFO");            //    string Versions = getEntity.//    return Versions;            //}            //catch (Exception se)            //{            //    //說明一點:IIS5.0中沒有(int)entry.Properties["MajorIISVersionNumber"].Value;屬性,將拋出異常 證明版本為 5.0            //    //MessageBox.Show("獲取ISS的版本是發生異常信息:" + se.Message);            //    return "5.0";            //}            //RegistryKey表示 Windows 注冊表中的項級節點.此類是注冊表封裝            string issversion = string.Empty;            RegistryKey getkey = Registry.LocalMachine.OpenSubKey("software//microsoft//inetstp");            if (getkey != null)            {                issversion = Convert.ToInt32(getkey.GetValue("majorversion", -1)).ToString();                //MessageBox.Show(issversion.ToString());            }            return issversion;        }        /// <summary>        /// 獲取當前計算機信息   例如:計算機名:aaa,ip:10.10.10.10        /// </summary>        /// <returns></returns>        public static string GetComputerInfo()        {            var computerNmae = System.Net.Dns.GetHostName();//獲取當前計算機名稱            var computerIp = new System.Net.IPAddress(System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList[0].Address).ToString();//獲取局域網IP            return string.Format("PC_Name: {0},IP: {1}",computerNmae,computerIp);        }     }
獲取當前計算機相關信息

2.查看當前iis上所有的應用程序池的       

        /// <summary>
/// 檢測當前線程池是否正常開啟 /// </summary> public void MonitoringISSAppPool() { // string method_Recycle = "Recycle"; //Start開啟 Recycle回收 Stop 停止 string method_Start = "Start"; var i = 0; DirectoryEntry appPool = new DirectoryEntry("IIS://localhost/W3SVC/AppPools"); try { foreach (DirectoryEntry item in appPool.Children) { string AppPoolCommand = item.Properties["ManagedPipelineMode"].Value.ToString(); string ManagedRuntimeVersion = item.Properties["ManagedRuntimeVersion"].Value.ToString();//,net版本號 string AppPoolState = item.Properties["AppPoolState"].Value.ToString();//當前狀態 if (AppPoolState != "2") { DirectoryEntry findPool = appPool.Children.Find(item.Name, "IIsapplicationPool"); findPool.Invoke(method_Start, null); appPool.CommitChanges(); appPool.Close(); var IIsMsg = string.Format("[{0}],名稱:[{1}],NET版本:{2},標識:{3},當前狀態:[{4}],時間:{5}/n", PC_Info, item.Name, ManagedRuntimeVersion, item.SchemaClassName, "已啟動", DateTime.Now.ToString()); ClsLogHelper.m_CreateWorkLogTxt(item.Name, IIsMsg); } } //lblCount_text.Text = i.ToString(); } catch (Exception ex) { ClsLogHelper.m_CreateErrorLogTxt("MonitoringISSAppPool", string.Format("{0},時間:{1},啟動失敗", AcquireComputerInfo.GetComputerInfo(), DateTime.Now), ex.Message);//日志記錄錯誤信息 ClsLogHelper.Email("MonitoringISSAppPool", string.Format("{0},時間:{1},啟動失敗", AcquireComputerInfo.GetComputerInfo(), DateTime.Now)+" "+ ex.Message);//郵件發送錯誤信息 } }

3.那么剩下就是windows計劃任務的工作了,簡單配置一下設置觸發器時間為每隔1秒中執行一次

到此一個IIS應用程序池偽監控就已經完成,當然在啟動應用程序池時,啟動失敗時還需要記錄詳細的錯誤信息,以及將發生錯誤的服務器名稱和IP通過郵件的方式發送給管理員,管理員可以在第一時間知道具體那臺服務器IIS出現問題.

日志記錄:

通過日志記錄我們可以發現在第二條記錄中Audi這個應用程序池已經被正常啟動.

當然這種小工具只能臨時解決IIS應用程序池意外停止的問題,IIS應用程序池意外停止可能有很多原因導致,例如:內存溢出或者代碼邏輯問題,要想根本解決就只能安排程序員檢查代碼了.

 

不喜勿噴,如果有什么更好的意見或者想法歡迎提出寶貴意見哦....


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 万州区| 凤山县| 本溪市| 阳高县| 琼结县| 平江县| 彰化市| 阳朔县| 海阳市| 福建省| 吴川市| 同仁县| 微博| 阜平县| 和田市| 资阳市| 南漳县| 邹城市| 潢川县| 桐庐县| 平泉县| 谷城县| 綦江县| 江城| 曲沃县| 建始县| 长岛县| 岳阳市| 介休市| 靖江市| 武义县| 台州市| 黄大仙区| 甘泉县| 云南省| 白河县| 洮南市| 凤冈县| 同仁县| 西城区| 榕江县|