github.com/netdata/go.d.plugin@v0.58.1/modules/windows/collect_exchange.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package windows
     4  
     5  import (
     6  	"strings"
     7  
     8  	"github.com/netdata/go.d.plugin/pkg/prometheus"
     9  )
    10  
    11  const (
    12  	metricExchangeActiveSyncPingCmdsPending  = "windows_exchange_activesync_ping_cmds_pending"
    13  	metricExchangeActiveSyncRequestsTotal    = "windows_exchange_activesync_requests_total"
    14  	metricExchangeActiveSyncCMDsTotal        = "windows_exchange_activesync_sync_cmds_total"
    15  	metricExchangeAutoDiscoverRequestsTotal  = "windows_exchange_autodiscover_requests_total"
    16  	metricExchangeAvailServiceRequestsPerSec = "windows_exchange_avail_service_requests_per_sec"
    17  	metricExchangeOWACurrentUniqueUsers      = "windows_exchange_owa_current_unique_users"
    18  	metricExchangeOWARequestsTotal           = "windows_exchange_owa_requests_total"
    19  	metricExchangeRPCActiveUserCount         = "windows_exchange_rpc_active_user_count"
    20  	metricExchangeRPCAvgLatencySec           = "windows_exchange_rpc_avg_latency_sec"
    21  	metricExchangeRPCConnectionCount         = "windows_exchange_rpc_connection_count"
    22  	metricExchangeRPCOperationsTotal         = "windows_exchange_rpc_operations_total"
    23  	metricExchangeRPCRequests                = "windows_exchange_rpc_requests"
    24  	metricExchangeRPCUserCount               = "windows_exchange_rpc_user_count"
    25  
    26  	metricExchangeTransportQueuesActiveMailboxDelivery        = "windows_exchange_transport_queues_active_mailbox_delivery"
    27  	metricExchangeTransportQueuesExternalActiveRemoteDelivery = "windows_exchange_transport_queues_external_active_remote_delivery"
    28  	metricExchangeTransportQueuesExternalLargestDelivery      = "windows_exchange_transport_queues_external_largest_delivery"
    29  	metricExchangeTransportQueuesInternalActiveRemoteDelivery = "windows_exchange_transport_queues_internal_active_remote_delivery"
    30  	metricExchangeTransportQueuesInternalLargestDelivery      = "windows_exchange_transport_queues_internal_largest_delivery"
    31  	metricExchangeTransportQueuesPoison                       = "windows_exchange_transport_queues_poison"
    32  	metricExchangeTransportQueuesRetryMailboxDelivery         = "windows_exchange_transport_queues_retry_mailbox_delivery"
    33  	metricExchangeTransportQueuesUnreachable                  = "windows_exchange_transport_queues_unreachable"
    34  
    35  	metricExchangeWorkloadActiveTasks    = "windows_exchange_workload_active_tasks"
    36  	metricExchangeWorkloadCompletedTasks = "windows_exchange_workload_completed_tasks"
    37  	metricExchangeWorkloadQueuedTasks    = "windows_exchange_workload_queued_tasks"
    38  	metricExchangeWorkloadYieldedTasks   = "windows_exchange_workload_yielded_tasks"
    39  	metricExchangeWorkloadIsActive       = "windows_exchange_workload_is_active"
    40  
    41  	metricExchangeLDAPLongRunningOPSPerSec = "windows_exchange_ldap_long_running_ops_per_sec"
    42  	metricExchangeLDAPReadTimeSec          = "windows_exchange_ldap_read_time_sec"
    43  	metricExchangeLDAPSearchTmeSec         = "windows_exchange_ldap_search_time_sec"
    44  	metricExchangeLDAPWriteTimeSec         = "windows_exchange_ldap_write_time_sec"
    45  	metricExchangeLDAPTimeoutErrorsTotal   = "windows_exchange_ldap_timeout_errors_total"
    46  
    47  	metricExchangeHTTPProxyAvgAuthLatency                    = "windows_exchange_http_proxy_avg_auth_latency"
    48  	metricExchangeHTTPProxyAvgCASProcessingLatencySec        = "windows_exchange_http_proxy_avg_cas_proccessing_latency_sec"
    49  	metricExchangeHTTPProxyMailboxProxyFailureRate           = "windows_exchange_http_proxy_mailbox_proxy_failure_rate"
    50  	metricExchangeHTTPProxyMailboxServerLocatorAvgLatencySec = "windows_exchange_http_proxy_mailbox_server_locator_avg_latency_sec"
    51  	metricExchangeHTTPProxyOutstandingProxyRequests          = "windows_exchange_http_proxy_outstanding_proxy_requests"
    52  	metricExchangeHTTPProxyRequestsTotal                     = "windows_exchange_http_proxy_requests_total"
    53  )
    54  
    55  func (w *Windows) collectExchange(mx map[string]int64, pms prometheus.Series) {
    56  	if !w.cache.collection[collectorExchange] {
    57  		w.cache.collection[collectorExchange] = true
    58  		w.addExchangeCharts()
    59  	}
    60  
    61  	if pm := pms.FindByName(metricExchangeActiveSyncPingCmdsPending); pm.Len() > 0 {
    62  		mx["exchange_activesync_ping_cmds_pending"] = int64(pm.Max())
    63  	}
    64  	if pm := pms.FindByName(metricExchangeActiveSyncRequestsTotal); pm.Len() > 0 {
    65  		mx["exchange_activesync_requests_total"] = int64(pm.Max())
    66  	}
    67  	if pm := pms.FindByName(metricExchangeActiveSyncCMDsTotal); pm.Len() > 0 {
    68  		mx["exchange_activesync_sync_cmds_total"] = int64(pm.Max())
    69  	}
    70  	if pm := pms.FindByName(metricExchangeAutoDiscoverRequestsTotal); pm.Len() > 0 {
    71  		mx["exchange_autodiscover_requests_total"] = int64(pm.Max())
    72  	}
    73  	if pm := pms.FindByName(metricExchangeAvailServiceRequestsPerSec); pm.Len() > 0 {
    74  		mx["exchange_avail_service_requests_per_sec"] = int64(pm.Max())
    75  	}
    76  	if pm := pms.FindByName(metricExchangeOWACurrentUniqueUsers); pm.Len() > 0 {
    77  		mx["exchange_owa_current_unique_users"] = int64(pm.Max())
    78  	}
    79  	if pm := pms.FindByName(metricExchangeOWARequestsTotal); pm.Len() > 0 {
    80  		mx["exchange_owa_requests_total"] = int64(pm.Max())
    81  	}
    82  	if pm := pms.FindByName(metricExchangeRPCActiveUserCount); pm.Len() > 0 {
    83  		mx["exchange_rpc_active_user_count"] = int64(pm.Max())
    84  	}
    85  	if pm := pms.FindByName(metricExchangeRPCAvgLatencySec); pm.Len() > 0 {
    86  		mx["exchange_rpc_avg_latency_sec"] = int64(pm.Max() * precision)
    87  	}
    88  	if pm := pms.FindByName(metricExchangeRPCConnectionCount); pm.Len() > 0 {
    89  		mx["exchange_rpc_connection_count"] = int64(pm.Max())
    90  	}
    91  	if pm := pms.FindByName(metricExchangeRPCOperationsTotal); pm.Len() > 0 {
    92  		mx["exchange_rpc_operations_total"] = int64(pm.Max())
    93  	}
    94  	if pm := pms.FindByName(metricExchangeRPCRequests); pm.Len() > 0 {
    95  		mx["exchange_rpc_requests"] = int64(pm.Max())
    96  	}
    97  	if pm := pms.FindByName(metricExchangeRPCUserCount); pm.Len() > 0 {
    98  		mx["exchange_rpc_user_count"] = int64(pm.Max())
    99  	}
   100  
   101  	w.collectExchangeAddTransportQueueMetric(mx, pms)
   102  	w.collectExchangeAddWorkloadMetric(mx, pms)
   103  	w.collectExchangeAddLDAPMetric(mx, pms)
   104  	w.collectExchangeAddHTTPProxyMetric(mx, pms)
   105  }
   106  
   107  func (w *Windows) collectExchangeAddTransportQueueMetric(mx map[string]int64, pms prometheus.Series) {
   108  	pms = pms.FindByNames(
   109  		metricExchangeTransportQueuesActiveMailboxDelivery,
   110  		metricExchangeTransportQueuesExternalActiveRemoteDelivery,
   111  		metricExchangeTransportQueuesExternalLargestDelivery,
   112  		metricExchangeTransportQueuesInternalActiveRemoteDelivery,
   113  		metricExchangeTransportQueuesInternalLargestDelivery,
   114  		metricExchangeTransportQueuesPoison,
   115  		metricExchangeTransportQueuesRetryMailboxDelivery,
   116  		metricExchangeTransportQueuesUnreachable,
   117  	)
   118  
   119  	for _, pm := range pms {
   120  		if name := pm.Labels.Get("name"); name != "" && name != "total_excluding_priority_none" {
   121  			metric := strings.TrimPrefix(pm.Name(), "windows_")
   122  			mx[metric+"_"+name] += int64(pm.Value)
   123  		}
   124  	}
   125  }
   126  
   127  func (w *Windows) collectExchangeAddWorkloadMetric(mx map[string]int64, pms prometheus.Series) {
   128  	seen := make(map[string]bool)
   129  
   130  	for _, pm := range pms.FindByNames(
   131  		metricExchangeWorkloadActiveTasks,
   132  		metricExchangeWorkloadCompletedTasks,
   133  		metricExchangeWorkloadQueuedTasks,
   134  		metricExchangeWorkloadYieldedTasks,
   135  	) {
   136  		if name := pm.Labels.Get("name"); name != "" {
   137  			seen[name] = true
   138  			metric := strings.TrimPrefix(pm.Name(), "windows_exchange_workload_")
   139  			mx["exchange_workload_"+name+"_"+metric] += int64(pm.Value)
   140  		}
   141  	}
   142  
   143  	for _, pm := range pms.FindByName(metricExchangeWorkloadIsActive) {
   144  		if name := pm.Labels.Get("name"); name != "" {
   145  			seen[name] = true
   146  			mx["exchange_workload_"+name+"_is_active"] += boolToInt(pm.Value == 1)
   147  			mx["exchange_workload_"+name+"_is_paused"] += boolToInt(pm.Value == 0)
   148  		}
   149  	}
   150  
   151  	for name := range seen {
   152  		if !w.cache.exchangeWorkload[name] {
   153  			w.cache.exchangeWorkload[name] = true
   154  			w.addExchangeWorkloadCharts(name)
   155  		}
   156  	}
   157  	for name := range w.cache.exchangeWorkload {
   158  		if !seen[name] {
   159  			delete(w.cache.exchangeWorkload, name)
   160  			w.removeExchangeWorkloadCharts(name)
   161  		}
   162  	}
   163  }
   164  
   165  func (w *Windows) collectExchangeAddLDAPMetric(mx map[string]int64, pms prometheus.Series) {
   166  	seen := make(map[string]bool)
   167  
   168  	for _, pm := range pms.FindByNames(
   169  		metricExchangeLDAPLongRunningOPSPerSec,
   170  		metricExchangeLDAPTimeoutErrorsTotal,
   171  	) {
   172  		if name := pm.Labels.Get("name"); name != "" {
   173  			seen[name] = true
   174  			metric := strings.TrimPrefix(pm.Name(), "windows_exchange_ldap_")
   175  			mx["exchange_ldap_"+name+"_"+metric] += int64(pm.Value)
   176  		}
   177  	}
   178  
   179  	for _, pm := range pms.FindByNames(
   180  		metricExchangeLDAPReadTimeSec,
   181  		metricExchangeLDAPSearchTmeSec,
   182  		metricExchangeLDAPWriteTimeSec,
   183  	) {
   184  		if name := pm.Labels.Get("name"); name != "" {
   185  			seen[name] = true
   186  			metric := strings.TrimPrefix(pm.Name(), "windows_exchange_ldap_")
   187  			mx["exchange_ldap_"+name+"_"+metric] += int64(pm.Value * precision)
   188  		}
   189  	}
   190  
   191  	for name := range seen {
   192  		if !w.cache.exchangeLDAP[name] {
   193  			w.cache.exchangeLDAP[name] = true
   194  			w.addExchangeLDAPCharts(name)
   195  		}
   196  	}
   197  	for name := range w.cache.exchangeLDAP {
   198  		if !seen[name] {
   199  			delete(w.cache.exchangeLDAP, name)
   200  			w.removeExchangeLDAPCharts(name)
   201  		}
   202  	}
   203  }
   204  
   205  func (w *Windows) collectExchangeAddHTTPProxyMetric(mx map[string]int64, pms prometheus.Series) {
   206  	seen := make(map[string]bool)
   207  
   208  	for _, pm := range pms.FindByNames(
   209  		metricExchangeHTTPProxyAvgAuthLatency,
   210  		metricExchangeHTTPProxyOutstandingProxyRequests,
   211  		metricExchangeHTTPProxyRequestsTotal,
   212  	) {
   213  		if name := pm.Labels.Get("name"); name != "" {
   214  			seen[name] = true
   215  			metric := strings.TrimPrefix(pm.Name(), "windows_exchange_http_proxy_")
   216  			mx["exchange_http_proxy_"+name+"_"+metric] += int64(pm.Value)
   217  		}
   218  	}
   219  
   220  	for _, pm := range pms.FindByNames(
   221  		metricExchangeHTTPProxyAvgCASProcessingLatencySec,
   222  		metricExchangeHTTPProxyMailboxProxyFailureRate,
   223  		metricExchangeHTTPProxyMailboxServerLocatorAvgLatencySec,
   224  	) {
   225  		if name := pm.Labels.Get("name"); name != "" {
   226  			seen[name] = true
   227  			metric := strings.TrimPrefix(pm.Name(), "windows_exchange_http_proxy_")
   228  			mx["exchange_http_proxy_"+name+"_"+metric] += int64(pm.Value * precision)
   229  		}
   230  	}
   231  
   232  	for name := range seen {
   233  		if !w.cache.exchangeHTTPProxy[name] {
   234  			w.cache.exchangeHTTPProxy[name] = true
   235  			w.addExchangeHTTPProxyCharts(name)
   236  		}
   237  	}
   238  	for name := range w.cache.exchangeHTTPProxy {
   239  		if !seen[name] {
   240  			delete(w.cache.exchangeHTTPProxy, name)
   241  			w.removeExchangeHTTPProxyCharts(name)
   242  		}
   243  	}
   244  }