IIS应用程序池监控
最近发现公司运行的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.Properties["MajorIISVersionNumber"].Value.ToString();
// 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", -)).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[].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 = ;
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 != "")
{
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应用程序池意外停止可能有很多原因导致,例如:内存溢出或者代码逻辑问题,要想根本解决就只能安排程序员检查代码了.
不喜勿喷,如果有什么更好的意见或者想法欢迎提出宝贵意见哦....
IIS应用程序池监控的更多相关文章
- C# IIS应用程序池辅助类 分类: C# Helper 2014-07-19 09:50 249人阅读 评论(0) 收藏
using System.Collections.Generic; using System.DirectoryServices; using System.Linq; using Microsoft ...
- 检测IIS应用程序池对象 回收
function RecycleYourAppPool([string] $poolName){ Import-Module WebAdministration #获取所有Application Po ...
- IIS 应用程序池自动停止
IIS7 .NET Runtime version 2.0.50727.5420 - 执行引擎错误(000007FEE77AAF0E) (80131506) 装完系统,配置完IIS,发现.NET程序报 ...
- 故障公告:IIS应用程序池停止工作造成博客站点无法访问
非常抱歉,今天凌晨博客站点负载均衡中所有3台服务器的IIS应用程序池突然停止工作,造成 1:20-7:45 左右博客站点无法正常访问,由此给您带来很大的麻烦,请您谅解. 服务器操作系统是 Window ...
- IIS应用程序池权限与虚拟目录身份验证权限
IIS应用程序池用户权限决定了IIS进程对资源的访问权限.例如在服务器aspx代码中修改web.config或者在某个目录写入文件,就需要应用程序池用户对指定文件或目录修改权限. 虚拟目录身份验证权限 ...
- IIS应用程序池_缓存回收
本人最近由于公司业务,需要把问卷的问题和答案存入缓存中已提高问卷加载速度,减少数据库压力. 缓存关键代码(公司代码已做封装,这里只贴出关键代码): HttpRuntime.Cache.Insert(k ...
- 转:IIS 应用程序池 内存 自动回收
原文地址:https://www.cnblogs.com/guohu/p/5209209.html IIS可以设置定时自动回收,默认回收是1740分钟,也就是29小时.IIS自动回收相当于服务器IIS ...
- IIS应用程序池自动回收问题的解决办法
windows 2012 的w3wp.exe(IIS Worker Process)进程不及时释放导致占用内存过高,以下解决方法: IIS可以设置定时自动回收,默认回收是1740分钟,也就是29小时. ...
- 什么是IIS应用程序池
IIS应用程序池是将一个或多个应用程序链接到一个或多个工作进程集合的配置.因为应用程序池中的应用程序与其他应用程序被工作进程边界分隔,所以某个应用程序池中的应用程序不会受到其他应用程序池中应用程序所产 ...
随机推荐
- [Linked List]Remove Linked List Elements
Total Accepted: 43183 Total Submissions: 160460 Difficulty: Easy Remove all elements from a linked l ...
- [Linked List]Remove Nth Node From End of List
Total Accepted: 84303 Total Submissions: 302714 Difficulty: Easy Given a linked list, remove the nth ...
- GetRect:通过提供点和宽度返回对应矩形RECT
RECT GetRect(int x,int y,int width,int height); 描述:通过提供点和宽度返回对应矩形RECT 返回:矩形结构RECT 参数: x:X轴坐标 y:Y轴坐标 ...
- WebApp开发技巧大全 看了就明白了
[转载]阅读原文 自Iphone和Android这两个牛逼的手机操作系统发布以来,在互联网界从此就多了一个新的名词-WebApp(意为基于WEB形式的应用程 序,运行在高端的移动终端设备).开发者们都 ...
- matplotlib中使用imshow绘制二维图
#coding:utf-8 from matplotlib import mpl import matplotlib.pyplot as plt#载入matplotlib快速绘图的函数库 import ...
- 【转】C++虚函数解析
本文转自陈皓大叔(左耳朵耗子)的博客www.coolshell.com. 文章是很久之前所写,去年还在写C++时有幸拜读,现在想起来还是相当有价值一转的,如果有一定C++基础(特别是读过<深度探 ...
- Delphi实现全局鼠标钩子
其中涉及到的一些API,网上均能查到详细的解释,这里不再熬述.源码下载 因为是全局钩子,所以要用dll注入.用到的鼠标消息结构如下: PMouseHookStruct = ^TMouseHookStr ...
- [置顶] 实习总结3-job hunting(西安工作)
开始整理关于西安top level的IT企业的工作从去年开始实习就慢慢展开了,到了北京之后一直关注的比较密切,因此前前后后也整理了很多.本来不打算那么急着写这一篇的,但是在因为在公司呆着,对于西安的一 ...
- 在magento中定义static block
在magento中如何调用static block?(系统面板内CMS---->static block) 解答:若想在站点页面的某个地方放点静态的内容,比如广告,或者是促销信息之类的,这样的东 ...
- [转]Asp.Net MVC使用HtmlHelper渲染,并传递FormCollection参数的陷阱 【转】
在Asp.Net MVC 1.0编程中,我们经常遇见这样的场景,在新建一个对象时候,通过HtmlHelper的方式在View模型中渲染Html控件,当填写完相关内容后,通过Form把需要新建的内容Po ...