Skip to content

Commit

Permalink
Support new implementation of Windows performance counters on Python 3 (
Browse files Browse the repository at this point in the history
#10850)

* Support new implementation of Windows performance counters on Python 3

* address
  • Loading branch information
ofek authored and cswatt committed Jan 5, 2022
1 parent f9d9a8e commit 741db1f
Show file tree
Hide file tree
Showing 11 changed files with 436 additions and 157 deletions.
11 changes: 3 additions & 8 deletions active_directory/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,13 @@ files:
options:
- template: init_config
options:
- template: init_config/perf_counters
- template: init_config/default
- template: instances
options:
- template: instances/perf_counters
- template: instances/pdh_legacy
overrides:
host.required: true
additional_metrics.value.example:
- [NTDS, none, DS % Writes from LDAP, active_directory.ds.writes_from_ldap, gauge]
counter_data_types.value.example:
- <METRIC_NAME>,<DATA_TYPE>
- active_directory.dra.inbound.bytes.total,int
- active_directory.ldap.bind_time,float
hidden: true
- template: instances/default
- template: logs
example:
Expand Down
123 changes: 11 additions & 112 deletions active_directory/datadog_checks/active_directory/active_directory.py
Original file line number Diff line number Diff line change
@@ -1,123 +1,22 @@
# (C) Datadog, Inc. 2013-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
from six import PY3

from datadog_checks.base.checks.win import PDHBaseCheck

DEFAULT_COUNTERS = [
# counterset, instance of counter, counter name, metric name
# This set is from the Microsoft recommended counters to monitor active directory:
# https://technet.microsoft.com/en-us/library/cc961942.aspx
[
"NTDS",
None,
"DRA Inbound Bytes Compressed (Between Sites, After Compression)/sec",
"active_directory.dra.inbound.bytes.after_compression",
"gauge",
],
[
"NTDS",
None,
"DRA Inbound Bytes Compressed (Between Sites, Before Compression)/sec",
"active_directory.dra.inbound.bytes.before_compression",
"gauge",
],
[
"NTDS",
None,
"DRA Inbound Bytes Not Compressed (Within Site)/sec",
"active_directory.dra.inbound.bytes.not_compressed",
"gauge",
],
["NTDS", None, "DRA Inbound Bytes Total/sec", "active_directory.dra.inbound.bytes.total", "gauge"],
[
"NTDS",
None,
"DRA Inbound Full Sync Objects Remaining",
"active_directory.dra.inbound.objects.remaining",
"gauge",
],
["NTDS", None, "DRA Inbound Objects/sec", "active_directory.dra.inbound.objects.persec", "gauge"],
["NTDS", None, "DRA Inbound Objects Applied/sec", "active_directory.dra.inbound.objects.applied_persec", "gauge"],
["NTDS", None, "DRA Inbound Objects Filtered/sec", "active_directory.dra.inbound.objects.filtered_persec", "gauge"],
[
"NTDS",
None,
"DRA Inbound Object Updates Remaining in Packet",
"active_directory.dra.inbound.objects.remaining_in_packet",
"gauge",
],
[
"NTDS",
None,
"DRA Inbound Properties Applied/sec",
"active_directory.dra.inbound.properties.applied_persec",
"gauge",
],
[
"NTDS",
None,
"DRA Inbound Properties Filtered/sec",
"active_directory.dra.inbound.properties.filtered_persec",
"gauge",
],
["NTDS", None, "DRA Inbound Properties Total/sec", "active_directory.dra.inbound.properties.total_persec", "gauge"],
["NTDS", None, "DRA Inbound Values (DNs only)/sec", "active_directory.dra.inbound.values.dns_persec", "gauge"],
["NTDS", None, "DRA Inbound Values Total/sec", "active_directory.dra.inbound.values.total_persec", "gauge"],
[
"NTDS",
None,
"DRA Outbound Bytes Compressed (Between Sites, After Compression)/sec",
"active_directory.dra.outbound.bytes.after_compression",
"gauge",
],
[
"NTDS",
None,
"DRA Outbound Bytes Compressed (Between Sites, Before Compression)/sec",
"active_directory.dra.outbound.bytes.before_compression",
"gauge",
],
[
"NTDS",
None,
"DRA Outbound Bytes Not Compressed (Within Site)/sec",
"active_directory.dra.outbound.bytes.not_compressed",
"gauge",
],
["NTDS", None, "DRA Outbound Bytes Total/sec", "active_directory.dra.outbound.bytes.total", "gauge"],
[
"NTDS",
None,
"DRA Outbound Objects Filtered/sec",
"active_directory.dra.outbound.objects.filtered_persec",
"gauge",
],
["NTDS", None, "DRA Outbound Objects/sec", "active_directory.dra.outbound.objects.persec", "gauge"],
["NTDS", None, "DRA Outbound Properties/sec", "active_directory.dra.outbound.properties.persec", "gauge"],
["NTDS", None, "DRA Outbound Values (DNs only)/sec", "active_directory.dra.outbound.values.dns_persec", "gauge"],
["NTDS", None, "DRA Outbound Values Total/sec", "active_directory.dra.outbound.values.total_persec", "gauge"],
# ["NTDS", None, "DRA Remaining Replication Updates", "active_directory.dra.replication.remaining_updates", "gauge"], # noqa: E501
[
"NTDS",
None,
"DRA Pending Replication Synchronizations",
"active_directory.dra.replication.pending_synchronizations",
"gauge",
],
["NTDS", None, "DRA Sync Requests Made", "active_directory.dra.sync_requests_made", "gauge"],
# ["NTDS", None, "DS Security Descriptor Suboperations/sec", "active_directory.ds.security_descriptor.subops_persec", "gauge"], # noqa: E501
# ["NTDS", None, "DS Security Descriptor Propagation Events", "active_directory.ds.security_descriptor.propagation_events", "gauge"], # noqa: E501
["NTDS", None, "DS Threads in Use", "active_directory.ds.threads_in_use", "gauge"],
["NTDS", None, "LDAP Client Sessions", "active_directory.ldap.client_sessions", "gauge"],
["NTDS", None, "LDAP Bind Time", "active_directory.ldap.bind_time", "gauge"],
["NTDS", None, "LDAP Successful Binds/sec", "active_directory.ldap.successful_binds_persec", "gauge"],
["NTDS", None, "LDAP Searches/sec", "active_directory.ldap.searches_persec", "gauge"],
# ["NTDS", None, "Kerberos Authentications/sec", "active_directory.kerberos.auths_persec", "gauge"],
# ["NTDS", None, "NTLM Authentications/sec", "active_directory.ntlm.auths_persec", "gauge"],
]
from .metrics import DEFAULT_COUNTERS


class ActiveDirectoryCheck(PDHBaseCheck):
def __new__(cls, name, init_config, instances):
if PY3:
from .check import ActiveDirectoryCheckV2

return ActiveDirectoryCheckV2(name, init_config, instances)
else:
return super(ActiveDirectoryCheck, cls).__new__(cls)

def __init__(self, name, init_config, instances=None):
super(ActiveDirectoryCheck, self).__init__(
name, init_config, instances=instances, counter_list=DEFAULT_COUNTERS
Expand Down
13 changes: 13 additions & 0 deletions active_directory/datadog_checks/active_directory/check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# (C) Datadog, Inc. 2021-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from datadog_checks.base.checks.windows.perf_counters.base import PerfCountersBaseCheckWithLegacySupport

from .metrics import METRICS_CONFIG


class ActiveDirectoryCheckV2(PerfCountersBaseCheckWithLegacySupport):
__NAMESPACE__ = 'active_directory'

def get_default_config(self):
return {'metrics': METRICS_CONFIG}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ def shared_service(field, value):
return get_default_field_value(field, value)


def shared_use_localized_counters(field, value):
return False


def instance_additional_metrics(field, value):
return get_default_field_value(field, value)

Expand All @@ -24,14 +28,42 @@ def instance_empty_default_hostname(field, value):
return False


def instance_enable_health_service_check(field, value):
return True


def instance_extra_metrics(field, value):
return get_default_field_value(field, value)


def instance_host(field, value):
return '.'


def instance_metrics(field, value):
return get_default_field_value(field, value)


def instance_min_collection_interval(field, value):
return 15


def instance_namespace(field, value):
return get_default_field_value(field, value)


def instance_password(field, value):
return get_default_field_value(field, value)


def instance_server(field, value):
return get_default_field_value(field, value)


def instance_server_tag(field, value):
return get_default_field_value(field, value)


def instance_service(field, value):
return get_default_field_value(field, value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,84 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
from __future__ import annotations

from typing import Optional, Sequence
from typing import Literal, Mapping, Optional, Sequence, Union

from pydantic import BaseModel, root_validator, validator
from pydantic import BaseModel, Extra, Field, root_validator, validator

from datadog_checks.base.utils.functions import identity
from datadog_checks.base.utils.models import validation

from . import defaults, validators


class Counter(BaseModel):
class Config:
extra = Extra.allow
allow_mutation = False

aggregate: Optional[Union[bool, Literal['only']]]
average: Optional[bool]
metric_name: Optional[str]
name: Optional[str]
type: Optional[str]


class InstanceCounts(BaseModel):
class Config:
allow_mutation = False

monitored: Optional[str]
total: Optional[str]
unique: Optional[str]


class ExtraMetrics(BaseModel):
class Config:
allow_mutation = False

counters: Sequence[Mapping[str, Union[str, Counter]]]
exclude: Optional[Sequence[str]]
include: Optional[Sequence[str]]
instance_counts: Optional[InstanceCounts]
name: str
tag_name: Optional[str]
use_localized_counters: Optional[bool]


class Counter1(BaseModel):
class Config:
extra = Extra.allow
allow_mutation = False

aggregate: Optional[Union[bool, Literal['only']]]
average: Optional[bool]
metric_name: Optional[str]
name: Optional[str]
type: Optional[str]


class InstanceCounts1(BaseModel):
class Config:
allow_mutation = False

monitored: Optional[str]
total: Optional[str]
unique: Optional[str]


class Metrics(BaseModel):
class Config:
allow_mutation = False

counters: Sequence[Mapping[str, Union[str, Counter1]]]
exclude: Optional[Sequence[str]]
include: Optional[Sequence[str]]
instance_counts: Optional[InstanceCounts1]
name: str
tag_name: Optional[str]
use_localized_counters: Optional[bool]


class InstanceConfig(BaseModel):
class Config:
allow_mutation = False
Expand All @@ -21,9 +89,15 @@ class Config:
counter_data_types: Optional[Sequence[str]]
disable_generic_tags: Optional[bool]
empty_default_hostname: Optional[bool]
host: str
enable_health_service_check: Optional[bool]
extra_metrics: Optional[Mapping[str, ExtraMetrics]]
host: Optional[str]
metrics: Optional[Mapping[str, Metrics]]
min_collection_interval: Optional[float]
namespace: Optional[str] = Field(None, regex='\\w*')
password: Optional[str]
server: Optional[str]
server_tag: Optional[str]
service: Optional[str]
tags: Optional[Sequence[str]]
username: Optional[str]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Config:
allow_mutation = False

service: Optional[str]
use_localized_counters: Optional[bool]

@root_validator(pre=True)
def _initial_validation(cls, values):
Expand Down
Loading

0 comments on commit 741db1f

Please sign in to comment.