热门标签 | 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 服务器监控


推荐阅读
  • 一、Web前端技术HTML:HTML、HTML5、CSS、TCPIPXML:XMLWeb脚本:JavaScript、AJAX、jQuery、JSONServ脚本:JSP、APS、P ... [详细]
  • 一,深浅拷贝看拷贝列子day19-1.py假如修改的元素是一个列表,源列表也会发生变化day19-2.py为什么会这样,因为第一次修改的是一个不可变元素对应的指针发生了变化,第二次 ... [详细]
  • D-War(8.4.3)CrawlinginprocessCrawlingfailedTimeLimit:3000MS    MemoryLimit:0KB  ... [详细]
  • 实验六提交版
    1.21.3part2共用体与结构体类型的区别?答:共用体与结构体的区别在于它们的表示方法不同。结构体内,结构体的各成员顺序排列存储,每个成员都有自己独立的存储位置,而共用体的情况 ... [详细]
  • Python对象特性0x01:所有Python对象都有三个特性以及属性*身份:每一个对象都有一个唯一的身份标识自己,任何一个都可以用内建函数id()来得到。*类型:决定了可以保存什 ... [详细]
  • RocketdecodeSimplifyDC
    https:mp.weixin.qq.coms4uWqBRrMVG6FlnBKmw8U-w介绍SimplifyDC如何简化解码逻辑。1.使用??简化从mint和maxt中查找的逻辑 ... [详细]
  • 题目:写一个函数返回参数二进制中1的个数方法1:我自己写的,运用‘%‘和‘‘,感觉挺简单的。intcount_one_bit(intnum){unsignedintcount0;w ... [详细]
  • 网络Cisco考试
    二、操作题(共80分)请将以下拓扑实验配置完毕,保存拓扑,建立一个文本文档,按照交换机-路由器1234的顺序,将每台设备的showrunning-config复制粘贴出来,将文本文 ... [详细]
  • SparkMLlib提供了一些基本的统计学的算法,下面主要说明一下:1、Summarystatistics对于RDD[Vector]类型,SparkMLlib提供了colStats ... [详细]
  • mysql在BTree上创建伪哈希索引
    构建哈希的过程select过程长字符串下,构建索引可通过自定义哈希作为索引,本人通过实验,在3百多个数据记录的下,性能效果很明显,完全不是一个等级.以下为索引前后几种情况对比在哈希 ... [详细]
  • 状压dfs。。。。GemsFight!TimeLimit:2000010000MS(JavaOthers)    MemoryLimit:327680327680K ... [详细]
  • 对于一些不符合的点来说,肯定是被他的父节点上权值最小的点转换最好。首先我们先排除不可能情况也就是01不等之后发现,交换完两个数后,0不符合的和1不符合的个数各自-1,因此不会影响其 ... [详细]
  • 8、创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更php.ini配置而无需重启php-cgiÿ ... [详细]
  • 如何绘制直观易懂的时标网络图
    时标网络图是用活动的定位和长度表示活动历时的项目网络图。是含网络逻辑的横道图,并且是任何以工作位置和长度代表其持续时间的项目网络图。项目经理圈子在时标网络图中,以实箭线表示工作,实 ... [详细]
  • TP框架 事件
    原文 http:www.cnblogs.comFushichop6600241.html1.在程序运行到应用模块的时候,先进行事件的注册:对事件进行监听注册监听注册其中,获取监听权 ... [详细]
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社区 版权所有