bosun.org@v0.0.0-20210513094433-e25bc3e69a1f/cmd/scollector/collectors/ras_windows.go (about) 1 package collectors 2 3 import ( 4 "fmt" 5 "time" 6 7 "bosun.org/collect" 8 "bosun.org/slog" 9 10 "bosun.org/metadata" 11 "bosun.org/opentsdb" 12 "github.com/StackExchange/wmi" 13 ) 14 15 func init() { 16 c := &IntervalCollector{ 17 F: c_remote_access_services, 18 Interval: time.Minute, 19 } 20 dst := []Win32_PerfRawData_RamgmtSvcCounterProvider_RaMgmtSvc{} 21 query := wmi.CreateQuery(&dst, "") 22 err := queryWmi(query, &dst) 23 if err != nil && collect.Debug { 24 slog.Error(err) 25 } 26 // If RaMgmtSvc and has at least one entry - we monitor it 27 if err == nil && len(dst) > 0 { 28 collectors = append(collectors, c) 29 } 30 } 31 32 const rasPrefix = "win.ras." 33 34 func c_remote_access_services() (opentsdb.MultiDataPoint, error) { 35 var dst []Win32_PerfRawData_RemoteAccess_RASTotal 36 query := wmi.CreateQuery(&dst, "") 37 err := queryWmi(query, &dst) 38 if err != nil { 39 return nil, err 40 } 41 if len(dst) != 1 { 42 return nil, fmt.Errorf("unexpected length for remote access (ras) total WMI query response, got %v expected 1", len(dst)) 43 } 44 totals := dst[0] 45 var md opentsdb.MultiDataPoint 46 tags := opentsdb.TagSet{} 47 ts := TSys100NStoEpoch(totals.Timestamp_Sys100NS) 48 Add(&md, rasPrefix+"total_connections", totals.TotalConnections, tags, metadata.Gauge, metadata.Connection, descWinRasTotalConnections) 49 AddTS(&md, rasPrefix+"total_bytes", ts, totals.BytesReceived, opentsdb.TagSet{"direction": "in"}, metadata.Counter, metadata.Bytes, descWinRasTotalBytes) 50 AddTS(&md, rasPrefix+"total_bytes", ts, totals.BytesTransmitted, opentsdb.TagSet{"direction": "out"}, metadata.Counter, metadata.Bytes, descWinRasTotalBytes) 51 AddTS(&md, rasPrefix+"total_frames", ts, totals.FramesReceived, opentsdb.TagSet{"direction": "in"}, metadata.Counter, metadata.Frame, descWinRasFrames) 52 AddTS(&md, rasPrefix+"total_frames", ts, totals.FramesTransmitted, opentsdb.TagSet{"direction": "out"}, metadata.Counter, metadata.Frame, descWinRasFrames) 53 AddTS(&md, rasPrefix+"total_errors_by_type", ts, totals.AlignmentErrors, opentsdb.TagSet{"type": "alignment"}, metadata.Counter, metadata.Error, descWinRasErrorByType) 54 AddTS(&md, rasPrefix+"total_errors_by_type", ts, totals.BufferOverrunErrors, opentsdb.TagSet{"type": "buffer_overrun"}, metadata.Counter, metadata.Error, descWinRasErrorByType) 55 AddTS(&md, rasPrefix+"total_errors_by_type", ts, totals.CRCErrors, opentsdb.TagSet{"type": "crc"}, metadata.Counter, metadata.Error, descWinRasErrorByType) 56 AddTS(&md, rasPrefix+"total_errors_by_type", ts, totals.SerialOverrunErrors, opentsdb.TagSet{"type": "serial_overrun"}, metadata.Counter, metadata.Error, descWinRasErrorByType) 57 AddTS(&md, rasPrefix+"total_errors_by_type", ts, totals.TimeoutErrors, opentsdb.TagSet{"type": "timeout"}, metadata.Counter, metadata.Error, descWinRasErrorByType) 58 AddTS(&md, rasPrefix+"total_errors", ts, totals.TotalErrors, tags, metadata.Counter, metadata.Error, descWinRasTotalErrors) 59 return md, nil 60 } 61 62 // Win32_PerfRawData_RemoteAccess_RASTotal has aggregate stats for Windows Remote Access Services 63 // MSDN Reference https://msdn.microsoft.com/en-us/library/aa394330(v=vs.85).aspx 64 // Only one or zero rows (instances) are expected in a query reply 65 type Win32_PerfRawData_RemoteAccess_RASTotal struct { 66 AlignmentErrors uint32 67 BufferOverrunErrors uint32 68 BytesReceived uint64 69 BytesTransmitted uint64 70 CRCErrors uint32 71 FramesReceived uint32 72 FramesTransmitted uint32 73 Frequency_Sys100NS uint64 74 SerialOverrunErrors uint32 75 TimeoutErrors uint32 76 Timestamp_Sys100NS uint64 77 TotalConnections uint32 78 TotalErrors uint32 79 } 80 81 const ( 82 descWinRasTotalConnections = "The total number of current Remote Access connections." 83 descWinRasTotalBytes = "The total number of bytes transmitted and received for Remote Access connections." 84 descWinRasFrames = "The total number of frames transmitted and received for Remote Access connections." 85 descWinRasErrorByType = "The total number of errors on Remote Access connections by type: Alignment Errors occur when a byte received is different from the byte expected. Buffer Overrun Errors when the software cannot handle the rate at which data is received. CRC Errors occur when the frame received contains erroneous data. Serial Overrun Errors occur when the hardware cannot handle the rate at which data is received. Timeout Errors occur when an expected is not received in time." 86 descWinRasTotalErrors = "The total number of errors on Remote Access connections." 87 ) 88 89 // Win32_PerfRawData_RamgmtSvcCounterProvider_RaMgmtSvc is used only to check for the existence of 90 // an active ras service on the host to decide if we want to monitor it. We are not interested 91 // in the actual values 92 type Win32_PerfRawData_RamgmtSvcCounterProvider_RaMgmtSvc struct { 93 Timestamp_Sys100NS uint64 94 }