• 大小: 33.73 KB
    文件类型: .rar
    金币: 1
    下载: 1 次
    发布日期: 2024-12-13
  • 语言: C#
  • 标签: C#  监控  

资源简介

自己写的用于监控CPU、内存、网络使用情况,以及进程使用CPU、内存情况的控制台程序。对需要进行服务器端性能监控的有一定参考价值。

资源截图

代码片段和文件信息

using System;
using System.Diagnostics;

namespace SysInfoTest
{
    /// 
    /// 网络适配器类
    /// developer:wuxinyong
    /// 

    public class NetworkAdapter
    {

        internal NetworkAdapter(string name)
        {
            this.name = name;
        }

        private long dlSpeed ulSpeed;
        private long dlValue ulValue; // 当前值
        private long dlValueOld ulValueOld; // 一秒以前的值

        internal string name;
        internal PerformanceCounter dlCounter ulCounter; // 性能计算器来计算download及upload speed

        //初始化
        internal void init()
        {
            this.dlValueOld = this.dlCounter.NextSample().RawValue;
            this.ulValueOld = this.ulCounter.NextSample().RawValue;
        }

        //更新性能计算器的值
        internal void refresh()
        {
            this.dlValue = this.dlCounter.NextSample().RawValue;
            this.ulValue = this.ulCounter.NextSample().RawValue;

            // Calculates download and upload speed.
            this.dlSpeed = this.dlValue - this.dlValueOld;
            this.ulSpeed = this.ulValue - this.ulValueOld;

            this.dlValueOld = this.dlValue;
            this.ulValueOld = this.ulValue;
        }


        public override string ToString()
        {
            return this.name;
        }


        public string Name
        {
            get
            {
                return this.name;
            }
        }

        public long DownloadSpeed
        {
            get
            {
                return this.dlSpeed;
            }
        }

        public long UploadSpeed
        {
            get
            {
                return this.ulSpeed;
            }
        }

        public double DownloadSpeedKbps
        {
            get
            {
                return this.dlSpeed / 1024.0;
            }
        }

        public double UploadSpeedKbps
        {
            get
            {
                return this.ulSpeed / 1024.0;
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      10240  2009-11-04 17:04  SysInfoTest\SysInfoTest\bin\Debug\SysInfoTest.exe

     文件      26112  2009-11-04 17:04  SysInfoTest\SysInfoTest\bin\Debug\SysInfoTest.pdb

     文件      14328  2009-11-04 17:04  SysInfoTest\SysInfoTest\bin\Debug\SysInfoTest.vshost.exe

     文件        490  2007-07-21 01:33  SysInfoTest\SysInfoTest\bin\Debug\SysInfoTest.vshost.exe.manifest

     文件        680  2009-11-04 17:04  SysInfoTest\SysInfoTest\obj\Debug\SysInfoTest.csproj.FileListAbsolute.txt

     文件      10240  2009-11-04 17:04  SysInfoTest\SysInfoTest\obj\Debug\SysInfoTest.exe

     文件      26112  2009-11-04 17:04  SysInfoTest\SysInfoTest\obj\Debug\SysInfoTest.pdb

     文件       5649  2009-10-31 16:28  SysInfoTest\SysInfoTest\Program.cs

     文件       1378  2009-10-30 19:20  SysInfoTest\SysInfoTest\Properties\AssemblyInfo.cs

     文件       2632  2009-10-31 12:55  SysInfoTest\SysInfoTest\SysInfoTest.csproj

     文件        923  2009-10-30 19:20  SysInfoTest\SysInfoTest.sln

    ..A..H.     13312  2009-11-04 17:04  SysInfoTest\SysInfoTest.suo

     目录          0  2009-10-30 19:20  SysInfoTest\SysInfoTest\obj\Debug\TempPE

     目录          0  2009-10-30 19:28  SysInfoTest\SysInfoTest\bin\Debug

     目录          0  2009-11-04 17:04  SysInfoTest\SysInfoTest\obj\Debug

     目录          0  2009-10-30 19:20  SysInfoTest\SysInfoTest\bin

     目录          0  2009-10-30 19:20  SysInfoTest\SysInfoTest\obj

     目录          0  2009-10-30 19:20  SysInfoTest\SysInfoTest\Properties

     目录          0  2009-10-31 16:29  SysInfoTest\SysInfoTest

     目录          0  2009-10-30 19:20  SysInfoTest

     文件       2177  2009-10-31 16:29  SysInfoTest\SysInfoTest\NetworkAdapter.cs

     文件       2813  2009-10-31 16:28  SysInfoTest\SysInfoTest\NetworkMonitor.cs

----------- ---------  ---------- -----  ----

               117086                    22


评论

共有 条评论