监控IIS的运行状态
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的运行状态的更多相关文章
- 监控MYSQL主从同步配置中监控从库运行状态的脚本
代码如下: #!/bin/bash #Check MySQL Slave's Runnning Status #Crontab time 00:10 MYSQLPORT=`netstat -na|gr ...
- MongoDB监控之一:运行状态、性能监控,分析
为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...
- 用WMI监控IIS
参考网站:http://blog.chinaunix.net/uid-7910284-id-5774420.html 参考官方文档:https://docs.microsoft.com/en-us/p ...
- jProfiler远程连接Linux监控jvm的运行状态
第一步:下载软件官网地址:https://www.ej-technologies.com/download/jprofiler/files,下载一个linux服务端,一个windows客户端 GUI界 ...
- 使用 pm2-web 监控 pm2 服务运行状态
pm2-web 是一款 pm2 服务状态监控程序,基于 web . 安装 $ npm install -g pm2-web 运行(默认是在8080端口) $ pm2-web 配置 pm2-web 将会 ...
- Qt监控后台服务运行状态
mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QMainWindow> #include <QMa ...
- 监控iis计数器
- IIS监控应用程序池和站点假死,自动重启IIS小工具
文章技术适合初学者.高级的C#开发工程师这些估计都熟悉到烂了,望不要喷. 第一.C#代码要操作IIS 就必须先导入 Microsoft.Web.Administration.dll ,方便控制台程序做 ...
- 使用RPi-Monitor监控、统计Guitar的运行状态
前言 之前发在ickey社区上的一系列文章: 犹抱琵琶半遮面,无人知是荔枝来--unboxing & interview 一.二.三 葡萄美酒夜光杯,巧妇难为无米炊--资料与社区 一支穿云箭, ...
随机推荐
- 《Effective Java》学习笔记 —— 枚举、注解与方法
Java的枚举.注解与方法... 第30条 用枚举代替int常量 第31条 用实例域代替序数 可以考虑定义一个final int 代替枚举中的 ordinal() 方法. 第32条 用EnumSet代 ...
- linux之awk基础
第一章 1.awk 简介 awk不仅仅时linux系统中的一个命令,而且是一种编程语言,可以用来处理数据和生成报告(excel).处理的数据可以是一个或多个文件,可以是来自标准输入,也可以通过管道获取 ...
- Python_xlutils.copy
import xlrd import xlwt from xlutils.copy import copy # 读取工作簿 objWB = xlrd.open_workbook(r'C:\Users\ ...
- GitHub 新手教程 一,GitHub 注册
1,注册地址: https://github.com/ 2,输入账号.邮箱.密码: 3,选择 Free 免费账号: 4,选择一些基本信息(翻译后中文见下面的图): 翻译如下: 5,打开你注册用的邮箱, ...
- cocos2d-x学习之路(一)——安装cocos2d-x
这两天想从pygame和SDL换到cocos2d-x上(主要还是为了跨平台开发),所以这里先来看看如何安装cocos2d-x. 首先到官网去下载cocos2d-x:传送门 点击上方菜单栏的Produc ...
- mark一下岗位
一.中国移动杭州研发中心——测试开发工程师 https://campusresume.zhaopin.com/resume/14375/1 等内推信息 岗位描述:作为产品的质量守护者,在全面理解被 ...
- 容器flappybird游戏——图文操作指引贴
第一步:打开华为云容器引擎产品首页,点击免费体验馆 第二步:进入免费体验馆,点击体验按钮,获得3天免费集群 第三步:创建免费集群完成后,进入产品console页,如图所示: 第四步:如 ...
- linux内核分析第三次实验
http://blog.sina.com.cn/s/blog_78e559950102wo67.html
- A01-java学习环境准备
1, 需要去oracle官网下载,JDK https://www.oracle.com/technetwork/java/javase/downloads/index.html 点击SE Do ...
- msgpack生成lib,vs新建lib等
记录导师交给的任务 新建一个c++项目,运行老师的msgpack的cpp文件,然后会生成相应的lib,我做的东西需要调用到它(这是老师改写后的msgpack的lib) 我的任务是建一个静态库,将客户端 ...