热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ASP.net服务器监控

参考

,

参考代码:

1,页面

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SMPWebPerformance.aspx.cs" Inherits="AFC_web.DataCenter.SMPWebPerformance" %>






    
    


    
        


  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
  {
  /// 
  /// 取得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.

 

ASP.net 服务器监控


推荐阅读
  • 深入理解Cookie与Session会话管理
    本文详细介绍了如何通过HTTP响应和请求处理浏览器的Cookie信息,以及如何创建、设置和管理Cookie。同时探讨了会话跟踪技术中的Session机制,解释其原理及应用场景。 ... [详细]
  • QUIC协议:快速UDP互联网连接
    QUIC(Quick UDP Internet Connections)是谷歌开发的一种旨在提高网络性能和安全性的传输层协议。它基于UDP,并结合了TLS级别的安全性,提供了更高效、更可靠的互联网通信方式。 ... [详细]
  • 深入理解OAuth认证机制
    本文介绍了OAuth认证协议的核心概念及其工作原理。OAuth是一种开放标准,旨在为第三方应用提供安全的用户资源访问授权,同时确保用户的账户信息(如用户名和密码)不会暴露给第三方。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • Windows服务与数据库交互问题解析
    本文探讨了在Windows 10(64位)环境下开发的Windows服务,旨在定期向本地MS SQL Server (v.11)插入记录。尽管服务已成功安装并运行,但记录并未正确插入。我们将详细分析可能的原因及解决方案。 ... [详细]
  • CSS 布局:液态三栏混合宽度布局
    本文介绍了如何使用 CSS 实现液态的三栏布局,其中各栏具有不同的宽度设置。通过调整容器和内容区域的属性,可以实现灵活且响应式的网页设计。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 深入理解 SQL 视图、存储过程与事务
    本文详细介绍了SQL中的视图、存储过程和事务的概念及应用。视图为用户提供了一种灵活的数据查询方式,存储过程则封装了复杂的SQL逻辑,而事务确保了数据库操作的完整性和一致性。 ... [详细]
  • 本文介绍了一款用于自动化部署 Linux 服务的 Bash 脚本。该脚本不仅涵盖了基本的文件复制和目录创建,还处理了系统服务的配置和启动,确保在多种 Linux 发行版上都能顺利运行。 ... [详细]
  • PHP 编程疑难解析与知识点汇总
    本文详细解答了 PHP 编程中的常见问题,并提供了丰富的代码示例和解决方案,帮助开发者更好地理解和应用 PHP 知识。 ... [详细]
  • 2023 ARM嵌入式系统全国技术巡讲旨在分享ARM公司在半导体知识产权(IP)领域的最新进展。作为全球领先的IP提供商,ARM在嵌入式处理器市场占据主导地位,其产品广泛应用于90%以上的嵌入式设备中。此次巡讲将邀请来自ARM、飞思卡尔以及华清远见教育集团的行业专家,共同探讨当前嵌入式系统的前沿技术和应用。 ... [详细]
  • 本文介绍如何解决在 IIS 环境下 PHP 页面无法找到的问题。主要步骤包括配置 Internet 信息服务管理器中的 ISAPI 扩展和 Active Server Pages 设置,确保 PHP 脚本能够正常运行。 ... [详细]
  • 国内BI工具迎战国际巨头Tableau,稳步崛起
    尽管商业智能(BI)工具在中国的普及程度尚不及国际市场,但近年来,随着本土企业的持续创新和市场推广,国内主流BI工具正逐渐崭露头角。面对国际品牌如Tableau的强大竞争,国内BI工具通过不断优化产品和技术,赢得了越来越多用户的认可。 ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 本文详细介绍了如何使用 Yii2 的 GridView 组件在列表页面实现数据的直接编辑功能。通过具体的代码示例和步骤,帮助开发者快速掌握这一实用技巧。 ... [详细]
author-avatar
miedao1592_460
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有