IIS经常出现假死的情况,具体什么时候会出现假死,我就不说了,今天我要写的是如何监控IIS的状态

程序的功能是:如果IIS是为运行的状态,就重启IIS,如果IIS的连接数达到了设置的连接数,也重启IIS。我写了一个window服务,时刻监控着IIS的运行状态。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Management;
using System.Diagnostics;
using System.ServiceProcess;
using System.Configuration;
namespace IISWatcher
{
public partial class IISWatcher : ServiceBase
{
public IISWatcher()
{
InitializeComponent();
} System.Timers.Timer tmr;
protected override void OnStart(string[] args)
{
tmr = new System.Timers.Timer();
tmr.Interval = ;
tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
tmr.Enabled = true;
} void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
string currentAnonymousUsers = "";
string timeOut = "";
try
{
currentAnonymousUsers = ConfigurationManager.AppSettings["CurrentAnonymousUsers"];
timeOut = ConfigurationManager.AppSettings["TimeOut"]; ServiceController winSc = new ServiceController("WAS");
if (winSc.Status != System.ServiceProcess.ServiceControllerStatus.Running && winSc.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
{
StartService("WAS");
} ServiceController sc = new ServiceController("W3SVC");
if (sc.Status != System.ServiceProcess.ServiceControllerStatus.Running && sc.Status != System.ServiceProcess.ServiceControllerStatus.StartPending)
{
StartService("W3SVC");
}
else
{
SelectQuery query = new SelectQuery("Select " + currentAnonymousUsers + " from Win32_PerfRawData_W3SVC_WebService where name=\"_total\"");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
int currentAnonUsers = ;
foreach (ManagementBaseObject disk in searcher.Get())
{
int.TryParse(disk[currentAnonymousUsers].ToString(), out currentAnonUsers);
}
if (currentAnonUsers > Convert.ToInt32(timeOut))
{
StartService("W3SVC");
}
}
}
catch (Exception ex)
{
EventLog.WriteEntry("IISWatcherRecord", "ErrorMessage:" + ex.Message, EventLogEntryType.Error);
}
} static private void StartService(string serviceName)
{
ServiceController sc = new ServiceController(serviceName);
sc.Start();
for (int i = ; i < ; i++)
{
sc.Refresh();
System.Threading.Thread.Sleep();
if (sc.Status == System.ServiceProcess.ServiceControllerStatus.Running)
{
break;
}
if (i == )
{
throw new Exception(serviceName + "启动失败!启动时间超过5秒!");
}
}
}
protected override void OnStop()
{
tmr.Stop();
}
}
}

监控IIS的运行状态的更多相关文章

  1. 监控MYSQL主从同步配置中监控从库运行状态的脚本

    代码如下: #!/bin/bash #Check MySQL Slave's Runnning Status #Crontab time 00:10 MYSQLPORT=`netstat -na|gr ...

  2. MongoDB监控之一:运行状态、性能监控,分析

    为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...

  3. 用WMI监控IIS

    参考网站:http://blog.chinaunix.net/uid-7910284-id-5774420.html 参考官方文档:https://docs.microsoft.com/en-us/p ...

  4. jProfiler远程连接Linux监控jvm的运行状态

    第一步:下载软件官网地址:https://www.ej-technologies.com/download/jprofiler/files,下载一个linux服务端,一个windows客户端 GUI界 ...

  5. 使用 pm2-web 监控 pm2 服务运行状态

    pm2-web 是一款 pm2 服务状态监控程序,基于 web . 安装 $ npm install -g pm2-web 运行(默认是在8080端口) $ pm2-web 配置 pm2-web 将会 ...

  6. Qt监控后台服务运行状态

    mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QMa ...

  7. 监控iis计数器

  8. IIS监控应用程序池和站点假死,自动重启IIS小工具

    文章技术适合初学者.高级的C#开发工程师这些估计都熟悉到烂了,望不要喷. 第一.C#代码要操作IIS 就必须先导入 Microsoft.Web.Administration.dll ,方便控制台程序做 ...

  9. 使用RPi-Monitor监控、统计Guitar的运行状态

    前言 之前发在ickey社区上的一系列文章: 犹抱琵琶半遮面,无人知是荔枝来--unboxing & interview 一.二.三 葡萄美酒夜光杯,巧妇难为无米炊--资料与社区 一支穿云箭, ...

随机推荐

  1. [LCT应用]

    维护动态生成树,建树方法:假设边edge(x,y),则建立x ->edge->y的先后顺序.

  2. 奔跑吧vivado

        上一节一上来就是Linux,不是炫耀我们的MiZ702能跑Linux,而是为了方便的把外设一次性测试完.大家都知道MiZ702精华在于FPGA与ARM的完美融合,就像太极一样阴阳调和--软中有 ...

  3. python 回溯法 子集树模板 系列 —— 4、数字组合问题

    问题 找出从自然数1.2.3.....n中任取r个数的所有组合. 例如,n=5,r=3的所有组合为: 1,2,3 1,2,4 1,2,5 1,3,4 1,3,5 1,4,5 2,3,4 2,3,5 2 ...

  4. 双面间谍(spy)

    双面间谍 链接 分析: 戳这 代码: #include<cstdio> #include<algorithm> #include<cstdio> #include& ...

  5. SQL Server 全文搜索

    SQL Server 的全文搜索(Full-Text Search)是基于分词的文本检索功能,依赖于全文索引.全文索引不同于传统的平衡树(B-Tree)索引和列存储索引,它是由数据表构成的,称作倒转索 ...

  6. Security4:授予查看定义,执行SP和只读数据的权限

    SQL Server数据库有完善的权限管理机制,对于存储过程,其权限分为查看定义,执行和修改,查看SP定义的权限是:VIEW DEFINITION ,执行存储过程的权限是:EXECUTE,修改SP的权 ...

  7. pandas 初识(一)

    基本内容 Series: Series 是有一组数据(numpy的数据类型 numpy.ndarray)以及一组数据标签(即索引)组成,可以看成一个一个定长的有序字典(索引值到数据值的一个映射) ob ...

  8. 接口自动化测试框架-AIM

    最近在做公司项目的自动化接口测试,在现有几个小框架的基础上,反复研究和实践,搭建了新的测试框架.利用业余时间,把框架总结了下来. AIM框架介绍 AIM,是Automatic Interface Mo ...

  9. LintCode——数字统计

    数字统计:计算数字k在0到n中的出现的次数,k可能是0~9的一个值 样例:例如n=12,k=1,在 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],我们发现1出现 ...

  10. IOS的开发演变历史

    对IOS开发平台一直抱有很大兴趣,正好通过这个机会好好了解一下IOS的开发历程! 通过一些查阅,我了解到IOS的开发平台主要是依靠Xcode软件来编写程序,同时又需要在MAC OS X的环境下运行,w ...