监控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 一.二.三 葡萄美酒夜光杯,巧妇难为无米炊--资料与社区 一支穿云箭, ...
随机推荐
- 网络对抗技术 2017-2018-2 20152515 Exp7 信息搜集与漏洞扫描
1. 实践内容(3.5分) 本实践的目标理解常用网络欺诈背后的原理,以提高防范意识,并提出具体防范方法. DNS欺骗就是攻击者冒充域名服务器的一种欺骗行为. 原理:如果可以冒充域名服务器,然后把查询的 ...
- flask使用sqlit3的两种方式
方式一:raw_sql import sqlite3 from flask import Flask, request, jsonify app = Flask(__name__) DATABASE_ ...
- datatables.js 简单使用--弹出编辑框或添加数据框
内容:选中某一条记录,弹出编辑框 环境:asp.net mvc , bootstrap 显示效果: 代码: 至于怎么弄多选框,在上一篇博客里已经有说明. 主要用到了bootstrap的模态窗,下面代 ...
- windows下如何查看进程、端口占用、杀死进程教程
一. 查看所有进程占用的端口 在开始-运行-cmd,输入:netstat –ano 可以查看所有进程 二.查看占用指定端口的程序 当你在用tomcat发布程序时,经常会遇到端口被占用的情况,我们想知道 ...
- WebService技术,服务端发布到Tomcat(使用Servlet发布),客户端使用axis2实现(二)
还是在WebService技术,服务端and客户端JDK-wsimport工具(一)的基础上实现.新建一个包:com.aixs2client.目录结构如下: 一.服务端: 1.还是使用com.webs ...
- 记录一次Docker For Windows10镜像加速器配置
1.访问https://www.daocloud.io 注册账号 2.访问资源->加速器,或者直接访问网址https://www.daocloud.io/mirror,页面中间有加速配置,例如我 ...
- Python+Selenium+Unittest+Ddt+HTMLReport分布式数据驱动自动化测试框架结构
1.Business:公共业务模块,如登录模块,可以把登录模块进行封装供调用 ------login_business.py from Page_Object.Common_Page.login_pa ...
- Gartner研究副总裁:人工智能的五点傲慢与偏见
对于人工智能能够为各企业机构完成哪些任务,IT与业务领导者们时常感到困惑,并深受多个人工智能错误观念的困扰.全球领先的信息技术研究和顾问公司Gartner认为,开发人工智能项目的IT与业务领导者必须分 ...
- mysql学习(4)python操作数据库
整理了一下前面3期学的内容后,现在练习使用python去操作数据库 #!python3# coding:utf-8import pymysqlclass mysql_option(): def __i ...
- 1094. The Largest Generation (25)-(dfs,树的遍历,统计每层的节点数)
题目很简单,就是统计一下每层的节点数,输出节点数最多的个数和对应的层数即可. #include <iostream> #include <cstdio> #include &l ...