pExtension
- class dynatrace_extension.Extension(*args, **kwargs)[source]¶
Base class for Python extensions.
- logger¶
Embedded logger object for the extension.
- schedule_decorators: ClassVar = []¶
- property is_helper: bool¶
Internal property used by the EEC.
- property task_id: str¶
Internal property used by the EEC.
- property monitoring_config_id: str¶
Internal property used by the EEC.
Represents a unique identifier of the monitoring configuration. that is assigned to this particular extension instance.
- run()[source]¶
Launch the extension instance.
Calling this method starts the main loop of the extension.
This method must be invoked once to start the extension,
if –fastcheck is set, the extension will run in fastcheck mode, otherwise the main loop is started, which periodically runs:
The scheduled callbacks
The heartbeat method
The metrics publisher method
- on_shutdown()[source]¶
Callback method to be invoked when the extension is shutting down.
Called when extension exits after it has received shutdown signal from EEC This is executed before metrics are flushed to EEC
- schedule(callback: Callable, interval: timedelta | int, args: tuple | None = None, activation_type: ActivationType | None = None) None [source]¶
Schedule a method to be executed periodically.
The callback method will be periodically invoked in a separate thread. The callback method is always immediately scheduled for execution.
- Parameters:
callback – The callback method to be invoked
interval – The time interval between invocations, can be a timedelta object, or an int representing the number of seconds
args – Arguments to the callback, if any
activation_type – Optional activation type when this callback should run, can be ‘ActivationType.LOCAL’ or ‘ActivationType.REMOTE’
- query()[source]¶
Callback to be executed every minute by default.
Optional method that can be implemented by subclasses. The query method is always scheduled to run every minute.
- initialize()[source]¶
Callback to be executed when the extension starts.
Called once after the extension starts and the processes arguments are parsed. Sometimes there are tasks the user needs to do that must happen before runtime, but after the activation config has been received, example: Setting the schedule frequency based on the user input on the monitoring configuration, this can be done on this method
- fastcheck() Status [source]¶
Callback executed when extension is launched.
Called if the extension is run in the fastcheck mode. Only invoked for remote extensions. This method is not called if fastcheck callback was already registered with Extension.register_fastcheck().
- Returns:
Status with optional message whether the fastcheck succeed or failed.
- register_fastcheck(fast_check_callback: Callable[[ActivationConfig, str], Status])[source]¶
Registers fastcheck callback that is executed in the fastcheck mode.
Extension.fastcheck() is not called if fastcheck callback is registered with this method
- Parameters:
fast_check_callback – callable called with ActivationConfig and
message (extension_config arguments. Must return the Status with optional)
failed. (whether the fastcheck succeed or)
- report_metric(key: str, value: float | str | int | SummaryStat, dimensions: Dict[str, str] | None = None, techrule: str | None = None, timestamp: datetime | None = None, metric_type: MetricType = MetricType.GAUGE) None [source]¶
Report a metric.
Metric is sent to EEC using an HTTP request and MINT protocol. EEC then sends the metrics to the tenant.
By default, it reports a gauge metric.
- Parameters:
key – The metric key, must follow the MINT specification
value – The metric value, can be a simple value or a SummaryStat
dimensions – A dictionary of dimensions
techrule – The technology rule string set by self.techrule setter.
timestamp – The timestamp of the metric, defaults to the current time
metric_type – The type of the metric, defaults to MetricType.GAUGE
- report_mint_lines(lines: List[str]) None [source]¶
Report mint lines using the MINT protocol
Examples
Metric lines must comply with the MINT format.
>>> self.report_mint_lines(["my_metric 1", "my_other_metric 2"])
- Parameters:
lines – A list of mint lines
- report_event(title: str, description: str, properties: dict | None = None, timestamp: datetime | None = None, severity: Severity | str = Severity.INFO) None [source]¶
Report an event using log ingest.
- Parameters:
title – The title of the event
description – The description of the event
properties – A dictionary of extra event properties
timestamp – The timestamp of the event, defaults to the current time
severity – The severity of the event, defaults to Severity.INFO
- report_dt_event(event_type: DtEventType, title: str, start_time: int | None = None, end_time: int | None = None, timeout: int | None = None, entity_selector: str | None = None, properties: dict[str, str] | None = None) None [source]¶
Reports an event using the v2 event ingest API.
Unlike
report_event
, this directly raises an event or even a problem based on the specifiedevent_type
.Note
For reference see: https://www.dynatrace.com/support/help/dynatrace-api/environment-api/events-v2/post-event
- Parameters:
event_type – The event type chosen from type Enum (required)
title – The title of the event (required)
start_time – The start time of event in UTC ms, if not set, current timestamp (optional)
end_time – The end time of event in UTC ms, if not set, current timestamp + timeout (optional)
timeout – The timeout of event in minutes, if not set, 15 (optional)
entity_selector – The entity selector, if not set, the event is associated with environment entity (optional)
properties – A map of event properties (optional)
- report_dt_event_dict(event: dict)[source]¶
Report an event using event ingest API with provided dictionary.
Note
For reference see: https://www.dynatrace.com/support/help/dynatrace-api/environment-api/events-v2/post-event
Format of the event dictionary:
{ "type": "object", "required": ["eventType", "title"], "properties": { "eventType": { "type": "string", "enum": [ "CUSTOM_INFO", "CUSTOM_ANNOTATION", "CUSTOM_CONFIGURATION", "CUSTOM_DEPLOYMENT", "MARKED_FOR_TERMINATION", "ERROR_EVENT", "AVAILABILITY_EVENT", "PERFORMANCE_EVENT", "RESOURCE_CONTENTION_EVENT", "CUSTOM_ALERT" ] }, "title": { "type": "string", "minLength": 1 }, "startTime": {"type": "integer"}, "endTime": {"type": "integer"}, "timeout": {"type": "integer"}, "entitySelector": {"type": "string"}, "properties": { "type": "object", "patternProperties": { "^.*$": {"type": "string"} } } } }
- report_log_event(log_event: dict)[source]¶
Report a custom log event using log ingest.
Note
See reference: https://www.dynatrace.com/support/help/shortlink/log-monitoring-log-data-ingestion
- Parameters:
log_event – The log event dictionary.
- report_log_events(log_events: List[dict])[source]¶
Report a list of custom log events using log ingest.
- Parameters:
log_events – The list of log events
- report_log_lines(log_lines: List[str | bytes])[source]¶
Report a list of log lines using log ingest
- Parameters:
log_lines – The list of log lines
- property enabled_feature_sets: dict[str, list[str]]¶
Map of enabled feautre sets and corresponding metrics.
- Returns:
Dictionary containing enabled feature sets with corresponding metrics defined in
extension.yaml
.
- property enabled_feature_sets_names: list[str]¶
Names of enabled feature sets.
- Returns:
List containing names of enabled feature sets.
- property enabled_feature_sets_metrics: list[str]¶
Enabled metrics.
- Returns:
List of all metric keys from enabled feature sets
- property techrule: str¶
Internal property used by the EEC.