-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support new implementation of Windows performance counters on Python 3 #10546
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ files: | |
options: | ||
- template: init_config | ||
options: | ||
- template: init_config/perf_counters | ||
- template: init_config/default | ||
- template: instances | ||
options: | ||
|
@@ -39,30 +40,7 @@ files: | |
compact_example: false | ||
items: | ||
type: string | ||
- name: is_2008 | ||
required: false | ||
display_priority: 1 | ||
description: | | ||
Because of a typo in IIS6/7 (typically on W2K8) where perfmon reports TotalBytesTransferred as | ||
TotalBytesTransfered, you may have to enable this to grab the IIS metrics in that environment. | ||
value: | ||
example: false | ||
type: boolean | ||
- template: instances/pdh_legacy | ||
overrides: | ||
host.required: true | ||
host.display_priority: 2 | ||
username.display_priority: 2 | ||
password.display_priority: 2 | ||
host.description: | | ||
By default, this check runs against a single instance - the current | ||
machine that the Agent is running on. It checks the PDH (Performance | ||
Data Helper) performance counters for IIS on that machine. | ||
|
||
"." means the current host, any other value makes the Agent attempt to connect to a remote host. | ||
Note: Remote access requires additional permissions. | ||
additional_metrics.value.example: | ||
- ['Web Service', none, 'CGI Requests/sec', iis.httpd_request_method.cgi, gauge] | ||
Comment on lines
-64
to
-65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not working, I made a card to fix config spec nested overrides |
||
- template: instances/perf_counters | ||
- template: instances/default | ||
- template: logs | ||
example: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# (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 datadog_checks.base.checks.windows.perf_counters.counter import PerfObject | ||
from datadog_checks.base.constants import ServiceCheck | ||
|
||
from .metrics import METRICS_CONFIG | ||
|
||
|
||
class IISCheckV2(PerfCountersBaseCheckWithLegacySupport): | ||
__NAMESPACE__ = 'iis' | ||
|
||
def get_default_config(self): | ||
metrics_config = {} | ||
for object_name, config in METRICS_CONFIG.items(): | ||
new_config = config.copy() | ||
|
||
include = [] | ||
if object_name == 'APP_POOL_WAS': | ||
new_config['tag_name'] = 'app_pool' | ||
include.extend(self.instance.get('app_pools', [])) | ||
elif object_name == 'Web Service': | ||
new_config['tag_name'] = 'site' | ||
include.extend(self.instance.get('sites', [])) | ||
|
||
if include: | ||
new_config['include'] = [f'^{instance}$' for instance in include] | ||
|
||
metrics_config[object_name] = new_config | ||
|
||
return {'server_tag': 'iis_host', 'metrics': metrics_config} | ||
|
||
def get_perf_object(self, connection, object_name, object_config, use_localized_counters, tags): | ||
if object_name == 'APP_POOL_WAS': | ||
return CompatibilityPerfObject( | ||
self, | ||
connection, | ||
object_name, | ||
object_config, | ||
use_localized_counters, | ||
tags, | ||
'Current Application Pool Uptime', | ||
'app_pool', | ||
self.instance.get('app_pools', []), | ||
) | ||
elif object_name == 'Web Service': | ||
return CompatibilityPerfObject( | ||
self, | ||
connection, | ||
object_name, | ||
object_config, | ||
use_localized_counters, | ||
tags, | ||
'Service Uptime', | ||
'site', | ||
self.instance.get('sites', []), | ||
) | ||
else: | ||
return super().get_perf_object(connection, object_name, object_config, use_localized_counters, tags) | ||
|
||
|
||
class CompatibilityPerfObject(PerfObject): | ||
def __init__( | ||
self, | ||
check, | ||
connection, | ||
object_name, | ||
object_config, | ||
use_localized_counters, | ||
tags, | ||
uptime_counter, | ||
instance_type, | ||
instances_included, | ||
): | ||
super().__init__(check, connection, object_name, object_config, use_localized_counters, tags) | ||
|
||
self.uptime_counter = uptime_counter | ||
self.instance_type = instance_type | ||
self.instance_service_check_name = f'{self.instance_type}_up' | ||
self.instances_included = set(instances_included) | ||
|
||
# Resets during refreshes | ||
self.instances_unseen = set() | ||
|
||
def refresh(self): | ||
self.instances_unseen.clear() | ||
self.instances_unseen.update(self.instances_included) | ||
|
||
for instance in sorted(self.instances_unseen): | ||
self.logger.debug('Expecting %ss: %s', self.instance_type, instance) | ||
|
||
super().refresh() | ||
|
||
for instance in sorted(self.instances_unseen): | ||
tags = [f'{self.instance_type}:{instance}'] | ||
tags.extend(self.tags) | ||
self.logger.warning('Did not get any data for expected %s: %s', self.instance_type, instance) | ||
self.check.service_check(self.instance_service_check_name, ServiceCheck.CRITICAL, tags=tags) | ||
|
||
def _instance_excluded(self, instance): | ||
self.instances_unseen.discard(instance) | ||
return super()._instance_excluded(instance) | ||
|
||
def get_custom_transformers(self): | ||
return {self.uptime_counter: self.__get_uptime_transformer} | ||
|
||
def __get_uptime_transformer(self, check, metric_name, modifiers): | ||
gauge_method = check.gauge | ||
service_check_method = check.service_check | ||
|
||
def submit_uptime(value, tags=None): | ||
gauge_method(metric_name, value, tags=tags) | ||
service_check_method( | ||
self.instance_service_check_name, ServiceCheck.CRITICAL if value == 0 else ServiceCheck.OK, tags=tags | ||
) | ||
|
||
del check | ||
del modifiers | ||
return submit_uptime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't do anything