bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/system_windows.go (about)

     1  package collectors
     2  
     3  import (
     4  	"bosun.org/metadata"
     5  	"bosun.org/opentsdb"
     6  	"github.com/StackExchange/wmi"
     7  )
     8  
     9  func init() {
    10  	collectors = append(collectors, &IntervalCollector{F: c_system_windows})
    11  	collectors = append(collectors, &IntervalCollector{F: c_windows_process_total})
    12  }
    13  
    14  func c_system_windows() (opentsdb.MultiDataPoint, error) {
    15  	var dst []Win32_PerfRawData_PerfOS_System
    16  	var q = wmi.CreateQuery(&dst, "")
    17  	err := queryWmi(q, &dst)
    18  	if err != nil {
    19  		return nil, err
    20  	}
    21  	var md opentsdb.MultiDataPoint
    22  	for _, v := range dst {
    23  		if v.Frequency_Object != 0 {
    24  			//see http://microsoft.public.win32.programmer.wmi.narkive.com/09kqthVC/lastbootuptime
    25  			var uptime = (v.Timestamp_Object - v.SystemUpTime) / v.Frequency_Object
    26  			Add(&md, "win.system.uptime", uptime, nil, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
    27  			Add(&md, osSystemUptime, uptime, nil, metadata.Gauge, metadata.Second, osSystemUptimeDesc)
    28  		}
    29  		Add(&md, "win.system.context_switches", v.ContextSwitchesPersec, nil, metadata.Counter, metadata.ContextSwitch, descWinSystemContextSwitchesPersec)
    30  		Add(&md, "win.system.exceptions", v.ExceptionDispatchesPersec, nil, metadata.Counter, metadata.PerSecond, descWinSystemExceptionDispatchesPersec)
    31  		Add(&md, "win.system.cpu_queue", v.ProcessorQueueLength, nil, metadata.Gauge, metadata.Count, descWinSystemProcessorQueueLength)
    32  		Add(&md, "win.system.syscall", v.SystemCallsPersec, nil, metadata.Counter, metadata.Syscall, descWinSystemSystemCallsPersec)
    33  		Add(&md, "win.system.threads", v.Threads, nil, metadata.Gauge, metadata.Count, descWinSystemThreads)
    34  		Add(&md, "win.system.processes", v.Processes, nil, metadata.Gauge, metadata.Count, descWinSystemProcesses)
    35  
    36  	}
    37  	return md, nil
    38  }
    39  
    40  const (
    41  	descWinSystemContextSwitchesPersec     = "Context Switches/sec is the combined rate at which all processors on the computer are switched from one thread to another.  Context switches occur when a running thread voluntarily relinquishes the processor, is preempted by a higher priority ready thread, or switches between user-mode and privileged (kernel) mode to use an Executive or subsystem service.  It is the sum of Thread\\Context Switches/sec for all threads running on all processors in the computer and is measured in numbers of switches."
    42  	descWinSystemExceptionDispatchesPersec = "Exception Dispatches/sec is the rate, in incidents per second, at which exceptions were dispatched by the system."
    43  	descWinSystemProcesses                 = "The number of processes running on the system."
    44  	descWinSystemProcessorQueueLength      = "Processor Queue Length is the number of threads in the processor queue.  Unlike the disk counters, this counter shows ready threads only, not threads that are running.  There is a single queue for processor time even on computers with multiple processors. Therefore, if a computer has multiple processors, you need to divide this value by the number of processors servicing the workload. A sustained processor queue of less than 10 threads per processor is normally acceptable, dependent on the workload."
    45  	descWinSystemSystemCallsPersec         = "System Calls/sec is the combined rate of calls to operating system service routines by all processes running on the computer. These routines perform all of the basic scheduling and synchronization of activities on the computer, and provide access to non-graphic devices, memory management, and name space management."
    46  	descWinSystemThreads                   = "The number of threads running on the system."
    47  )
    48  
    49  type Win32_PerfRawData_PerfOS_System struct {
    50  	ContextSwitchesPersec     uint32
    51  	ExceptionDispatchesPersec uint32
    52  	Frequency_Object          uint64
    53  	Processes                 uint32
    54  	ProcessorQueueLength      uint32
    55  	SystemCallsPersec         uint32
    56  	SystemUpTime              uint64
    57  	Threads                   uint32
    58  	Timestamp_Object          uint64
    59  }
    60  
    61  func c_windows_process_total() (opentsdb.MultiDataPoint, error) {
    62  	var dst []Win32_PerfRawData_PerfProc_Process
    63  	var q = wmi.CreateQuery(&dst, `WHERE Name = '_Total'`)
    64  	err := queryWmi(q, &dst)
    65  	if err != nil {
    66  		return nil, err
    67  	}
    68  	var md opentsdb.MultiDataPoint
    69  	for _, v := range dst {
    70  		Add(&md, "win.system.handle_count", v.HandleCount, nil, metadata.Gauge, metadata.Count, descWinSystemHandle_count)
    71  	}
    72  	return md, nil
    73  }
    74  
    75  const (
    76  	descWinSystemHandle_count = "Total number of handles open across all threads."
    77  )