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.

  

时间: 2024-07-29 11:38:05

ASP.net 服务器监控的相关文章

服务器监控cacti

第九章:服务器监控系统cacti 防伪码:海阔天空 前言:在企业网络运维过程中,管理员必须时刻关注服务器的运行状态,如CPU.内存.磁盘空间使用情况等.为了能够及时的发现问题,尽量减少故障的发生.当网络中的设备,服务器等数量较多时,可以部署一套监控系统来实时跟踪服务器,我们通常会借助一些软件来实现.今天就以Cacti套件为例,介绍服务器集中监测体系的构建和使用. 今天所讲的cacti服务器监控系统与windows操作系统中的"性能监视器"属于同一类,都是为了监控cpu占用,内存使用,运

【Linux--中级篇】服务器监控Cacti

服务器监控Cacti 1.实验环境: 主机 操作系统 IP地址 主要软件 主控端 CentOS6.5x86_64 192.168.10.15 Rrdtool-1.4.8.tar.gz Cacti-0.8.8b.tar.gz 被控端 CentOS6.5x86_64 192.168.10.18 Win7客户机 192.168.10.5 2.实验步骤: 1.主控端配置 1)配置LAMP环境 安装mysql数据库 配置apache与php 2> 安装rrdtool和net-snmp 通过yum确认并安装

Atitit.Gui控件and面板----web server区----- web服务器监控面板and控制台条目

Atitit.Gui控件and面板----web server区----- web服务器监控面板and控制台条目 1. Resin4.0.22 1 2. 查看http连接数::Summary>>tables 1 2.1.1. Open Connections 1 2.2. TCP ports? 1 3. 查看app::confgi?>>webapps 2 3.1. Host http://localhost:80 2 3.1.1. WebApps 2 4. 查看app2:::   

[转载]你需要知道的 16 个 Linux 服务器监控命令

转载自: 你需要知道的 16 个 Linux 服务器监控命令 如果你想知道你的服务器正在做干什么,你就需要了解一些基本的命令,一旦你精通了这些命令,那你就是一个 专业的 Linux 系统管理员. 有些 Linux 发行版会提供 GUI 程序来进行系统的监控,例如 SUSE Linux 就有一个非常棒而且专业的工具 YaST,KDE 的 KDE System Guard 同样很出色.当然,要使用这些工具,你必须在服务器跟前进行操作,而且这些 GUI 的程序占用了很多系统资源,所以说,尽管 GUI

jmeter服务器监控指标

以下是下载了服务器监控插件的各个组件的功能介绍,有助于以后jmeter的性能测试 [email protected] - Actiive Threads Over Time:不同时间的活动用户数量展示(图表) 当前的时间间隔是1毫秒,在setting中可以设置时间间隔以及其他的参数 2.[email protected] - AutoStop Listener :自动停止监听器 设置当发生某些预期之外的情况时自动停止测试 average Response Time is greater than

Ubuntu Server 安装部署 Cacti 服务器监控

Ubuntu Server 安装部署 Cacti 服务器监控 form :http://www.cnblogs.com/xuri/p/3379337.html

ArcGIS Server服务器监控

最近项目上需要对服务器与ArcGISServer服务进行监控,做了一个初步的原型,实现了以下功能. 一.服务器监控 注册服务器 服务器运行状态监控 在线状态 CPU.内存.存储配置监控,由于现在很多采用使用虚拟化技术,存在服务器配额被降级的风险,程序可以根据标准要求对实际配置进行监测: CPU.存储.内存的报警,超过设置的阈值时系统发出预警: 日志记录 二.ArcGIS Server服务监控 服务注册 服务启动.停止 服务访问量统计 服务响应时间记录 服务状态监控 三.短信提醒 服务器.服务的状

Android 上传图片到 Asp.Net 服务器的问题

最近在做一个手机app联合系统管理做的应用程序,管理程序管理数据的发布和增删改查,手机app负责显示和操作业务逻辑这么一个功能. 刚开始路走的都很顺,但是走到通过Android客户端上传图片到Asp.Net 服务器的时候出现很大的问题,图片是上传了,就是显示不出来,用照片查看器查看的时候显示:‘没有预览’,用画图软件打开的时候显示‘无效的位图文件或不支持文件的格式’!!! 大家想,肯定你的代码写得有问题,好吧,你们看看我的代码是什么问题吧: Stream sr = context.Request

游戏服务器监控的设计与实现(三)

系统信息采集方面,选择使用Sigar的第三方库. 对于Sigar做一个简单的梳理. 服务器监控,一方面要对游戏服务器的数据进行采集,另一方面也要对游戏服务器所在的系统信息进行采集.我打算使用sigar来获取系统信息的采集工作.其Demo非常完整,并且跨平台支持,本身对于.net,C++,php,python,java,perl,ruby都是支持的,为以后的扩展和更改留有很多的余地. sigar网址:https://support.hyperic.com/display/SIGAR/Home;js