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. 20155313 杨瀚 《网络对抗技术》实验九 Web安全基础

    20155313 杨瀚 <网络对抗技术>实验九 Web安全基础 一.实验目的 本实践的目标理解常用网络攻击技术的基本原理.Webgoat实践下相关实验. 二.基础问题回答 1.SQL注入攻 ...

  2. Exp1 PC平台逆向破解(5)M

    Exp1 PC平台逆向破解(5)M [ 直接修改程序机器指令,改变程序执行流程] 用命令cp pwn1 20155320备份pwn1 输入objdump -d 20155320反汇编,找到call指令 ...

  3. 2017-2018-1 20155331 嵌入式C语言

    2017-2018-1 20155331 嵌入式C语言 作业要求: 在作业本上完成附图作业,要认真看题目要求. 提交作业截图 作弊本学期成绩清零(有雷同的,不管是给别人传答案,还是找别人要答案都清零) ...

  4. Selenium-Switch与SelectApi接口详解

    Switch 我们在UI自动化测试时,总会出现新建一个tab页面.弹出一个浏览器级别的弹框或者是出现一个iframe标签,这时我们用WebDriver提供的Api接口就无法处理这些情况了.需要用到Se ...

  5. [SHOI2012]随机树[期望dp]

    题意 初始 \(1\) 个节点,每次选定一个叶子节点并加入两个儿子直到叶子总数为 \(n\),问叶子节点深度和的平均值的期望以及最大叶子深度的期望. \(n\leq 100\) . 分析 对于第一问, ...

  6. django请求的生命周期

    1. 概述 首先我们知道HTTP请求及服务端响应中传输的所有数据都是字符串. 在Django中,当我们访问一个的url时,会通过路由匹配进入相应的html网页中. Django的请求生命周期是指当用户 ...

  7. 阿里云容器服务区块链解决方案全新升级 支持Hyperledger Fabric v1.1

    摘要: 全球开源区块链领域影响最为广泛的Hyperledger Fabric日前宣布了1.1版本的正式发布,带来了一系列丰富的新功能以及在安全性.性能与扩展性等方面的显著提升.阿里云容器服务区块链解决 ...

  8. 使用tensorflow实现mnist手写识别(单层神经网络实现)

    import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_data as input_data import n ...

  9. Async 异步转同步详细流程解释

      安装 npm install async --save 地址 https://github.com/caolan/async Async的内容主要分为三部分 流程控制: 简化九种常见的流程的处理 ...

  10. zookeeper应用

    1. 下载zookeeper-3.4.10.tar.gz 2.tar zxvf zoo*.tar.gz 3. cd /usr/local/zookeeper/zookeeper-3.4.10/conf ...