ASP.net 服务器监控

参考代码:
1,页面
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SMPWebPerformance.aspx.cs" Inherits="AFC_web.DataCenter.SMPWebPerformance" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="16pt" ForeColor="Red" Text="云端服务器性能监测"></asp:Label>
<br />
<br />
</div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Chart ID="Chart1" runat="server" BackColor="LightSteelBlue" BackGradientStyle="TopBottom"
BackSecondaryColor="White" EnableTheming="False" EnableViewState="True" Height="383px"
Width="521px">
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" Name="Legend1" Title="图例">
</asp:Legend>
</Legends>
<Titles>
<asp:Title Font="微软雅黑, 16pt" Name="Title1" Text="系统内存监控图表">
</asp:Title>
</Titles>
<Series>
<asp:Series BorderColor="White" BorderWidth="3" ChartArea="ChartArea1" ChartType="Spline"
Legend="Legend1" Name="已使用物理内存" XValueType="Double" YValueType="Double">
</asp:Series>
<asp:Series BorderWidth="3" ChartArea="ChartArea1" ChartType="Spline" Legend="Legend1"
Name="全部占用内存">
</asp:Series>
<asp:Series ChartArea="ChartArea2" ChartType="StackedArea" Legend="Legend1" Name="CPU">
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea BackColor="224, 224, 224" BackGradientStyle="LeftRight" Name="ChartArea1">
</asp:ChartArea>
<asp:ChartArea Name="ChartArea2">
</asp:ChartArea>
</ChartAreas>
</asp:Chart>
<asp:Timer ID="UITimer" runat="server" Interval="2000" OnTick="UITimer_Tick">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
2,页面后台
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.DataVisualization.Charting;
using System.Diagnostics;
namespace AFC_web.DataCenter
{
public partial class SMPWebPerformance : System.Web.UI.Page
{
static PerformanceCounter pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
protected void Page_Load(object sender, EventArgs e)
{ } protected void UITimer_Tick(object sender, EventArgs e)
{
MEMORY_INFO MemInfo = new MEMORY_INFO();
ComputerInfo.GlobalMemoryStatus(ref MemInfo);
//UseMemory
Series series = Chart1.Series[0];
int xCount = series.Points.Count == 0 ? 0 : series.Points.Count - 1;
double lastXValue = series.Points.Count == 0 ? 1 : series.Points[xCount].XValue + 1;
double lastYValue = (double)(MemInfo.dwTotalPhys - MemInfo.dwAvailPhys) / 1024 / 1024;
series.Points.AddXY(lastXValue, lastYValue);
//Total Memory
series = Chart1.Series[1];
lastYValue = (double)(MemInfo.dwTotalVirtual + MemInfo.dwTotalPhys - MemInfo.dwAvailPhys - MemInfo.dwAvailVirtual) / 1024 / 1024;
series.Points.AddXY(lastXValue, lastYValue); //CPU
series = Chart1.Series[2];
lastYValue = (double)pc.NextValue();
series.Points.AddXY(lastXValue, lastYValue); // Remove points from the left chart side if number of points exceeds 100.
while (this.Chart1.Series[0].Points.Count > 80)
{
// Remove series points
foreach (Series s in this.Chart1.Series)
{
s.Points.RemoveAt(0);
}
}
// Adjust categorical scale
double axisMinimum = this.Chart1.Series[0].Points[0].XValue;
this.Chart1.ChartAreas[0].AxisX.Minimum = axisMinimum;
this.Chart1.ChartAreas[0].AxisX.Maximum = axisMinimum + 99; //------------------------------------------------------------------
//Random rand = new Random(); //// Add several random point into each series
//foreach (Series series in this.Chart1.Series)
//{
// double lastYValue = series.Points[series.Points.Count - 1].YValues[0];
// double lastXValue = series.Points[series.Points.Count - 1].XValue + 1;
// for (int pointIndex = 0; pointIndex < 5; pointIndex++)
// {
// lastYValue += rand.Next(-3, 4);
// if (lastYValue >= 100.0)
// {
// lastYValue -= 25.0;
// }
// else if (lastYValue <= 10.0)
// {
// lastYValue += 25.0;
// }
// series.Points.AddXY(lastXValue++, lastYValue);
// }
//} //// Remove points from the left chart side if number of points exceeds 100.
//while (this.Chart1.Series[0].Points.Count > 100)
//{
// // Remove series points
// foreach (Series series in this.Chart1.Series)
// {
// series.Points.RemoveAt(0);
// } //} //// Adjust categorical scale
//double axisMinimum = this.Chart1.Series[0].Points[0].XValue;
//this.Chart1.ChartAreas[0].AxisX.Minimum = axisMinimum;
//this.Chart1.ChartAreas[0].AxisX.Maximum = axisMinimum + 100;
}
}
}
3,获取CPU 内存 信息
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management; // 添加System.Management引用
using System.Text;
using System.Management.Instrumentation;
using System.Runtime.InteropServices; using System.Diagnostics;
using System.Threading;
namespace AFC_web
{ public class ComputerInfo
{
/// <summary>
/// 取得Windows的目录
/// </summary>
/// <param name="WinDir"></param>
/// <param name="count"></param>
[DllImport("kernel32")]
public static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
/// <summary>
/// 获取系统路径
/// </summary>
/// <param name="SysDir"></param>
/// <param name="count"></param>
[DllImport("kernel32")]
public static extern void GetSystemDirectory(StringBuilder SysDir, int count);
/// <summary>
/// 取得CPU信息
/// </summary>
/// <param name="cpuinfo"></param>
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
/// <summary>
/// 取得内存状态
/// </summary>
/// <param name="meminfo"></param>
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
/// <summary>
/// 取得系统时间
/// </summary>
/// <param name="stinfo"></param>
[DllImport("kernel32")]
public static extern void GetSystemTime(ref SYSTEMTIME_INFO stinfo); public ComputerInfo()
{ }
} //定义CPU的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct CPU_INFO
{
public uint dwOemId;
public uint dwPageSize;
public uint lpMinimumApplicationAddress;
public uint lpMaximumApplicationAddress;
public uint dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public uint dwProcessorLevel;
public uint dwProcessorRevision;
}
//定义内存的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct MEMORY_INFO
{
public uint dwLength;
public uint dwMemoryLoad;
public uint dwTotalPhys;
public uint dwAvailPhys;
public uint dwTotalPageFile;
public uint dwAvailPageFile;
public uint dwTotalVirtual;
public uint dwAvailVirtual;
}
//定义系统时间的信息结构
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME_INFO
{
public ushort wYear;
public ushort wMonth;
public ushort wDayOfWeek;
public ushort wDay;
public ushort wHour;
public ushort wMinute;
public ushort wSecond;
public ushort wMilliseconds;
} } // auxiliary print methods // constants used to select the performance counter.
ASP.net 服务器监控的更多相关文章
- 『Asp.Net 组件』Asp.Net 服务器组件 内嵌JS:让自己的控件动起来
代码: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ...
- zabbix服务器监控suse系统教程
zabbix服务器监控suse系统教程 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 花了近一个星期才学会了如何监控window和linux主机的基本信息以及报价情况(我已经把笔记 ...
- Android 上传图片到 Asp.Net 服务器的问题
最近在做一个手机app联合系统管理做的应用程序,管理程序管理数据的发布和增删改查,手机app负责显示和操作业务逻辑这么一个功能. 刚开始路走的都很顺,但是走到通过Android客户端上传图片到Asp. ...
- 1. SQL Server服务器监控实现方法
对于服务器的监控,和对数据库的监控,很少有合二为一的工具,如果有的话,一般是付费软件,或者自行开发的工具.所以如果不想购买软件,也不想花精力去开发的话,可以结合一些免费/开源的工具.自定义脚本,来完成 ...
- 『Asp.Net 组件』Asp.Net 服务器组件 内嵌CSS:将CSS封装到程序集中
代码: <span style="font-family:Microsoft YaHei; font-size:12px">using System; using Sy ...
- [转载]你需要知道的 16 个 Linux 服务器监控命令
转载自: 你需要知道的 16 个 Linux 服务器监控命令 如果你想知道你的服务器正在做干什么,你就需要了解一些基本的命令,一旦你精通了这些命令,那你就是一个 专业的 Linux 系统管理员. 有些 ...
- Ubuntu Server 安装部署 Cacti 服务器监控
本文的英文版本链接是 http://xuri.me/2013/10/20/install-the-cacti-server-monitor-on-ubuntu-server.html Cacti是一套 ...
- Atitit.Gui控件and面板----web server区----- web服务器监控面板and控制台条目
Atitit.Gui控件and面板----web server区----- web服务器监控面板and控制台条目 1. Resin4.0.22 1 2. 查看http连接数::Summary>& ...
- Linux下 高性能、易用、免费的ASP.NET服务器
Linux下 高性能.易用.免费的ASP.NET服务器 http://www.jexus.org/#
随机推荐
- hbase+hive应用场景
一.Hive应用场景本文主要讲述使用 Hive 的实践,业务不是关键,简要介绍业务场景,本次的任务是对搜索日志数据进行统计分析.集团搜索刚上线不久,日志量并不大 .这些日志分布在 5 台前端机,按小时 ...
- bjfu1277 简单递归
比较简单的递归问题.对于第k时刻的图形,可以平均分成四块,左上,右上,左下这三块的图形是一模一样的,右下的那一块不包含红毛僵尸,所以把那三块里的加起来就是结果了. /* * Author : ben ...
- Worm
Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过程,Le ...
- ifstream 流 判断文件是否结尾的函数eof(.xml
pre{ line-height:1; color:#800080; font-size:16px;}.sysFunc{color:#627cf6;font-style:italic;font-wei ...
- HTML5_布局and音视频
HTML5_布局and音视频 I.HTML5标签的改变1.文档声明HTML语法是不区分大小写的HTML5的DTD声明为:<!doctype html>确保浏览器能在HTML5的标准模式下进 ...
- linux 为开机菜单加密码·
首先是在/boot/grub/menu.lst 里面添加密码的,但是需要是加密过后的,否则人家直接跑到你的menu.lst里面查看密码不就行了.... 于是,可以使用grub提供的md5加密功能: # ...
- JNI编程,C++调用Java
本地代码中使用Java对象 通过使用合适的JNI函数,你可以创建Java对象,get.set 静态(static)和 实例(instance)的域,调用静态(static)和实例(instance)函 ...
- java类与对象的动手动脑和其他小问题
在Java中,我们可以通过组合一私有字段和一对get/set方法来定义一个属性.私有的变量,共有的方法. package sample; /** * 自定义Java类的示例 */ class MyCl ...
- log4net--帮助程序员将日志信息输出到各种目标(控制台、文件、数据库等)的工具
1. log4net库是Apache log4j框架在Microsoft .NET平台的实现,是一个帮助程序员将日志信息输出到各种目标(控制台.文件.数据库等)的工具. 2. Log4net的结构如下 ...
- WS之cxf处理的复杂类型(Map)
一.服务端: 1.创建接口: package cn.tdtk.ws.dao; import java.util.List;import java.util.Map; import javax.jws. ...