github.com/netdata/go.d.plugin@v0.58.1/modules/windows/windows.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package windows 4 5 import ( 6 _ "embed" 7 "net/http" 8 "time" 9 10 "github.com/netdata/go.d.plugin/agent/module" 11 "github.com/netdata/go.d.plugin/pkg/prometheus" 12 "github.com/netdata/go.d.plugin/pkg/web" 13 ) 14 15 //go:embed "config_schema.json" 16 var configSchema string 17 18 func init() { 19 module.Register("windows", module.Creator{ 20 JobConfigSchema: configSchema, 21 Defaults: module.Defaults{ 22 UpdateEvery: 5, 23 }, 24 Create: func() module.Module { return New() }, 25 }) 26 } 27 28 func New() *Windows { 29 return &Windows{ 30 Config: Config{ 31 HTTP: web.HTTP{ 32 Client: web.Client{ 33 Timeout: web.Duration{Duration: time.Second * 5}, 34 }, 35 }, 36 }, 37 cache: cache{ 38 collection: make(map[string]bool), 39 collectors: make(map[string]bool), 40 cores: make(map[string]bool), 41 nics: make(map[string]bool), 42 volumes: make(map[string]bool), 43 thermalZones: make(map[string]bool), 44 processes: make(map[string]bool), 45 iis: make(map[string]bool), 46 adcs: make(map[string]bool), 47 services: make(map[string]bool), 48 netFrameworkCLRExceptions: make(map[string]bool), 49 netFrameworkCLRInterops: make(map[string]bool), 50 netFrameworkCLRJIT: make(map[string]bool), 51 netFrameworkCLRLoading: make(map[string]bool), 52 netFrameworkCLRLocksThreads: make(map[string]bool), 53 netFrameworkCLRMemory: make(map[string]bool), 54 netFrameworkCLRRemoting: make(map[string]bool), 55 netFrameworkCLRSecurity: make(map[string]bool), 56 mssqlInstances: make(map[string]bool), 57 mssqlDBs: make(map[string]bool), 58 exchangeWorkload: make(map[string]bool), 59 exchangeLDAP: make(map[string]bool), 60 exchangeHTTPProxy: make(map[string]bool), 61 hypervVMMem: make(map[string]bool), 62 hypervVMDevices: make(map[string]bool), 63 hypervVMInterfaces: make(map[string]bool), 64 hypervVswitch: make(map[string]bool), 65 }, 66 charts: &module.Charts{}, 67 } 68 } 69 70 type Config struct { 71 web.HTTP `yaml:",inline"` 72 } 73 74 type ( 75 Windows struct { 76 module.Base 77 Config `yaml:",inline"` 78 79 charts *module.Charts 80 81 doCheck bool 82 83 httpClient *http.Client 84 prom prometheus.Prometheus 85 86 cache cache 87 } 88 cache struct { 89 cores map[string]bool 90 volumes map[string]bool 91 nics map[string]bool 92 thermalZones map[string]bool 93 processes map[string]bool 94 iis map[string]bool 95 adcs map[string]bool 96 mssqlInstances map[string]bool 97 mssqlDBs map[string]bool 98 services map[string]bool 99 netFrameworkCLRExceptions map[string]bool 100 netFrameworkCLRInterops map[string]bool 101 netFrameworkCLRJIT map[string]bool 102 netFrameworkCLRLoading map[string]bool 103 netFrameworkCLRLocksThreads map[string]bool 104 netFrameworkCLRMemory map[string]bool 105 netFrameworkCLRRemoting map[string]bool 106 netFrameworkCLRSecurity map[string]bool 107 collectors map[string]bool 108 collection map[string]bool 109 exchangeWorkload map[string]bool 110 exchangeLDAP map[string]bool 111 exchangeHTTPProxy map[string]bool 112 hypervVMMem map[string]bool 113 hypervVMDevices map[string]bool 114 hypervVMInterfaces map[string]bool 115 hypervVswitch map[string]bool 116 } 117 ) 118 119 func (w *Windows) Init() bool { 120 if err := w.validateConfig(); err != nil { 121 w.Errorf("config validation: %v", err) 122 return false 123 } 124 125 httpClient, err := w.initHTTPClient() 126 if err != nil { 127 w.Errorf("init HTTP client: %v", err) 128 return false 129 } 130 w.httpClient = httpClient 131 132 prom, err := w.initPrometheusClient(w.httpClient) 133 if err != nil { 134 w.Errorf("init prometheus clients: %v", err) 135 return false 136 } 137 w.prom = prom 138 139 return true 140 } 141 142 func (w *Windows) Check() bool { 143 return len(w.Collect()) > 0 144 } 145 146 func (w *Windows) Charts() *module.Charts { 147 return w.charts 148 } 149 150 func (w *Windows) Collect() map[string]int64 { 151 ms, err := w.collect() 152 if err != nil { 153 w.Error(err) 154 } 155 156 if len(ms) == 0 { 157 return nil 158 } 159 return ms 160 } 161 162 func (w *Windows) Cleanup() { 163 if w.httpClient != nil { 164 w.httpClient.CloseIdleConnections() 165 } 166 }