Setting up monitoring and fetching data

In the following examples, client is an AgentManagementClient created as described in The main AgentManagementClient class.

Enabling monitoring for one agent

Call agent.setup_monitoring() to create monitoring resources and enable the features supported by one agent. You need agent administration rights and access to the project and connection used for these resources.

agent = client.get_agent("production", "support-agent")
result = agent.setup_monitoring(
    project_key="AGENTMONITORING",
    connection_name="filesystem_managed",
    partitioning="DAY",
    run_first_fetch=True,
    include_in_uptime_tests=True,
)
print(result["configuredAgentIds"])
print(result["warnings"])

The project and connection must already exist. Omit these parameters to use the configured defaults. Inspect warnings even when the request succeeds: an agent may not have been fully configured.

Initial data fetches and uptime tests run in the background. Use the operation history described in Asynchronous operations to follow them.

Enabling monitoring for several agents

Call platform.setup_monitoring() to configure monitoring for several agents in one request. Pass agent IDs, AgentListItem entries, or Agent handles, all from the same platform.

from dataikuapi import AgentFilter

platform = client.get_platform("production")
agents = platform.list_agents(
    agent_filter=AgentFilter().with_agent_ids("support-agent", "sales-agent")
)
if agents:
    result = platform.setup_monitoring(
        agents,
        project_key="AGENTMONITORING",
        connection_name="filesystem_managed",
    )
    print(result["warnings"])

Provide at least one agent, and do not repeat an agent ID. Use Setting up monitoring across platforms to apply this pattern across platforms.

See Asynchronous operations to track the initial fetches and tests started for the selected agents.

Fetching execution logs

For an agent that supports log fetching and has its monitoring resources configured:

agent = client.get_agent("production", "support-agent")
result = agent.start_fetch_logs().wait_for_result()
print(result)

See Asynchronous operations to follow collection progress and read the operation logs.

OpenTelemetry receiver agents receive traces sent to Agent Management. They do not support fetching logs from a remote platform. The summary returned by agent.get_status().get_light() includes capabilities["logFetch"].

To investigate collection failures, open the agent’s Activity > Logs page. These diagnostic logs are separate from the execution logs collected into monitoring datasets. See Accessing logs.

Fetching platform operational metrics

Some providers expose operational metrics separately from execution logs. Use this operation when capabilities["operationalMetricsFetch"] is true.

result = agent.start_fetch_platform_operational_metrics().wait_for_result()
print(result)

The fetch returns an operation handle. See Asynchronous operations to monitor it and inspect failures.

Scheduling data collection

Periodic fetches are configured on the platform. Per-agent settings select whether scheduled log and operational metric fetches are enabled.

platform = client.get_platform("production")
settings = platform.get_settings()
settings.raw["periodicFetchEnabled"] = True
settings.raw["periodicFetchScheduleMode"] = "MINUTES"
settings.raw["periodicFetchFrequencyMinutes"] = 60
settings.save()

settings = agent.get_settings()
settings.get_raw()["configuration"]["scheduledLogFetchEnabled"] = True
settings.save()

For operation status and failures, see Asynchronous operations. For retrieving collected values, see Retrieving metrics.

Reference documentation

Classes

dataikuapi.agentmanagement.agent.AgentFilter()

Agent filter accepted by search, metric retrieval and bulk action methods.

Functions

get_agent(platform_id, agent_id)

Returns a handle to an agent.

get_light()

Gets the 'light' (summary) status of this agent.

get_platform(platform_id)

Returns a handle to an Agent Management platform.

get_raw()

Returns the raw settings of this agent.

get_settings()

Returns the settings of this agent.

get_settings()

Returns the settings of this platform.

get_status()

Returns status information about this agent.

list_agents([as_type, agent_filter])

Lists agents on this platform.

save()

Saves the settings of this agent, checking fetchedRevision read by get_settings.

save()

Saves the settings of this platform, using fetchedRevision to detect concurrent changes.

setup_monitoring([run_first_fetch, ...])

Enables monitoring for this agent and provisions its monitoring resources.

setup_monitoring(agents[, run_first_fetch, ...])

Enables monitoring for one or several agents on this platform in one pass.

start_fetch_logs()

Starts fetching execution logs for the agent.

start_fetch_platform_operational_metrics()

Starts fetching platform operational metrics for the agent.

wait_for_result()

Waits for this operation to complete successfully and returns its result.

with_agent_ids(*agent_ids)