首页 > 代码库 > ASP.net 服务器监控
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 = http://www.mamicode.com/series.Points.Count == 0 ? 1 : series.Points[xCount].XValue + 1;>
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 服务器监控
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。