/// <summary> /// Performance counters for the current process /// </summary> private void InitializeProcessCounters() { //create our process-specific counter group m_ProcessCounters = new PerfCounterCollection("Process Counters", "Performance counters we capture that are specific to our process"); try { m_ProcessCounters.Add("Process", "% Processor Time", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "% User Time", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "% Privileged Time", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Handle Count", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Page Faults/sec", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Page File Bytes", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Pool Nonpaged Bytes", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Pool Paged Bytes", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Private Bytes", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Thread Count", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "Virtual Bytes", PerfCounterInstanceAlias.CurrentProcess); m_ProcessCounters.Add("Process", "IO Data Bytes/sec", PerfCounterInstanceAlias.CurrentProcess); } catch (Exception exception) { GC.KeepAlive(exception); Log.Write(LogMessageSeverity.Warning, LogWriteMode.Queued, exception, "Gibraltar.Agent", "Unable to record performance information for process performance counters", "Specific exception: {0}\r\nException message: {1}", exception.GetType().FullName, exception.Message); } }
private void InitializeNetworkCounters() { //create a performance counter group for these guys m_NetworkCounters = new PerfCounterCollection("Network Counters", "System-wide network performance counters (not specific to the process being monitored)"); //register our favorite performance counters with the monitoring system try { //add in a monitor for each network interface PerformanceCounterCategory networkCounters = new PerformanceCounterCategory("Network Interface"); string[] networkInterfaceNames = networkCounters.GetInstanceNames(); foreach (string interfaceName in networkInterfaceNames) { //eliminate the loopback interface, we never care about that. if (interfaceName != "MS TCP Loopback interface" && interfaceName != "lo") { m_NetworkCounters.Add("Network Interface", "Bytes Received/sec", interfaceName); m_NetworkCounters.Add("Network Interface", "Bytes Sent/sec", interfaceName); m_NetworkCounters.Add("Network Interface", "Current Bandwidth", interfaceName); m_NetworkCounters.Add("Network Interface", "Packets Received Errors", interfaceName); m_NetworkCounters.Add("Network Interface", "Packets Outbound Errors", interfaceName); } } } catch (Exception exception) { GC.KeepAlive(exception); //some warning prevention... Log.Write(LogMessageSeverity.Warning, LogWriteMode.Queued, exception, "Gibraltar.Agent", "Unable to record performance information for network counters", "Specific exception: {0}\r\nException message: {1}", exception.GetType().FullName, exception.Message); } }
private void InitializeSystemCounters() { //create a performance counter group for these guys m_SystemCounters = new PerfCounterCollection("System Counters", "System-wide performance counters (not specific to the process being monitored)"); //register our favorite performance counters with the monitoring system try { m_SystemCounters.Add("System", "Processor Queue Length"); m_SystemCounters.Add("Processor", "% Processor Time", "_Total"); m_SystemCounters.Add("Memory", "Committed Bytes"); m_SystemCounters.Add("Memory", "Available Bytes"); m_SystemCounters.Add("Memory", "Pages/sec"); } catch (Exception exception) { GC.KeepAlive(exception); //some warning prevention... Log.Write(LogMessageSeverity.Warning, LogWriteMode.Queued, exception, "Gibraltar.Agent", "Unable to record performance information for system counters", "Specific exception: {0}\r\nException message: {1}", exception.GetType().FullName, exception.Message); } }
private void InitializeMemoryCounters() { if (CommonCentralLogic.IsNetFramework) { //create a performance counter group for these guys m_MemoryCounters = new PerfCounterCollection(".NET Memory Counters", "Detailed memory utilization counters specific to .NET"); //register our favorite performance counters with the monitoring system (These should all exist on Mono now, too) try { m_MemoryCounters.Add(".NET CLR Memory", "# GC Handles", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "# Bytes in all Heaps", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "# Gen 0 Collections", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "# Gen 1 Collections", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "# Gen 2 Collections", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "Large Object Heap Size", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "Gen 0 heap size", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "Gen 1 heap size", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "Gen 2 heap size", PerfCounterInstanceAlias.CurrentProcess); m_MemoryCounters.Add(".NET CLR Memory", "% Time in GC", PerfCounterInstanceAlias.CurrentProcess); } catch (Exception exception) { GC.KeepAlive(exception); //some warning prevention... Log.Write(LogMessageSeverity.Warning, LogWriteMode.Queued, exception, "Gibraltar.Agent", "Unable to record performance information for .NET memory counters", "Specific exception: {0}\r\nException message: {1}", exception.GetType().FullName, exception.Message); } } }
private void InitializeDiskCounters() { //create a performance counter group for these guys m_DiskCounters = new PerfCounterCollection("Disk Counters", "System-wide disk performance counters (not specific to the process being monitored)"); //register our favorite performance counters with the monitoring system try { //add in a monitor for each physical disk PerformanceCounterCategory logicalDiskCounters = new PerformanceCounterCategory("LogicalDisk"); string[] driveNames = logicalDiskCounters.GetInstanceNames(); //but before we ad the counters figure out what names are good. DriveInfo[] allDrives = DriveInfo.GetDrives(); Dictionary <string, DriveInfo> safeDrives = new Dictionary <string, DriveInfo>(allDrives.Length, StringComparer.OrdinalIgnoreCase); foreach (DriveInfo currentDrive in allDrives) { //we don't want to stumble into an odd machine-specific problem accessing the //properties of a drive that's not ready or something. try { if ((currentDrive.DriveType == DriveType.Fixed) && (currentDrive.IsReady)) { //clean up the drive name string cleanName = currentDrive.Name; int colonIndex = cleanName.IndexOf(":"); if (colonIndex > -1) { //we just want up through the colon cleanName = cleanName.Substring(0, colonIndex + 1); } safeDrives.Add(cleanName, currentDrive); } } catch { } } foreach (string driveName in driveNames) { //is it a valid drive to use? //we need to get rid of the leading number and space which we don't want in the label. string cleanName = driveName.TrimStart(new [] { ' ', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }); if (safeDrives.ContainsKey(cleanName)) { m_DiskCounters.Add("LogicalDisk", "% Disk Time", driveName); m_DiskCounters.Add("LogicalDisk", "Avg. Disk Queue Length", driveName); m_DiskCounters.Add("LogicalDisk", "Avg. Disk sec/Transfer", driveName); m_DiskCounters.Add("LogicalDisk", "Disk Transfers/sec", driveName); m_DiskCounters.Add("LogicalDisk", "Disk Reads/sec", driveName); m_DiskCounters.Add("LogicalDisk", "Disk Writes/sec", driveName); m_DiskCounters.Add("LogicalDisk", "Disk Bytes/sec", driveName); m_DiskCounters.Add("LogicalDisk", "Free Megabytes", driveName); m_DiskCounters.Add("LogicalDisk", "% Free Space", driveName); } } } catch (Exception exception) { GC.KeepAlive(exception); //some warning prevention... Log.Write(LogMessageSeverity.Warning, LogWriteMode.Queued, exception, "Gibraltar.Agent", "Unable to record performance information for disk counters", "Specific exception: {0}\r\nException message: {1}", exception.GetType().FullName, exception.Message); } }