<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SMPWebPerformance.aspx.cs" Inherits="AFC_web.DataCenter.SMPWebPerformance" %>
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;
}
}
}
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
{
///
/// 取得Windows的目录
///
///
///
[DllImport("kernel32")]
public static extern void GetWindowsDirectory(StringBuilder WinDir, int count);
///
/// 获取系统路径
///
///
///
[DllImport("kernel32")]
public static extern void GetSystemDirectory(StringBuilder SysDir, int count);
///
/// 取得CPU信息
///
///
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
///
/// 取得内存状态
///
///
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO meminfo);
///
/// 取得系统时间
///
///
[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.