Back to Netdata

Query agent Functions via Netdata Cloud

docs/netdata-ai/skills/query-netdata-cloud/query-functions.md

2.11.013.8 KB
Original Source

Query agent Functions via Netdata Cloud

This guide is part of the query-netdata-cloud skill. Read the SKILL.md prerequisites first.

This file documents the generic Function transport: the URL, the standard response envelope, the info discovery query, the four Function families and where each family's data lives in the response.

For three of the four families there is a dedicated guide:

The table-snapshot family (full dataset in each response) is covered here.

For querying agents directly (without going through Cloud) -- which includes the transparent Cloud-token to agent-bearer mint flow -- see the sibling skill query-netdata-agents.


Mandatory Requirements (READ FIRST)

  1. Provide actionable instructions. Every recommendation ends in a runnable curl command.
  2. Never request credentials. Use YOUR_API_TOKEN and YOUR_NODE_UUID placeholders.
  3. Always start with {"info":true} when you don't already know the parameter set of the target Function. The info response is authoritative -- this skill's tables can be stale relative to the running agent.
  4. Function names are case-sensitive (e.g. systemd-journal, topology:snmp, flows:netflow).

Function classes

The canonical Functions v3 protocol (<repo>/src/plugins.d/FUNCTION_UI_REFERENCE.md) formally defines two Function classes, distinguished by the has_history flag in the info response:

Classhas_historyFrontend behaviorExamples
Simple TablefalseBackend returns the whole current dataset; frontend filters/sorts/searches in-memoryprocesses, network-connections, network-interfaces, block-devices, mount-points, containers-vms, systemd-services, netdata-streaming, netdata-api-calls, netdata-metrics-cardinality, <db>:top-queries, <db>:running-queries, <db>:deadlock-info, <db>:error-info
Log ExplorertrueBackend filters / facets / histograms before sending; supports infinite scroll, anchor pagination, delta and PLAY modessystemd-journal, windows-events, macos-logs, otel-logs

Two additional type values are used by purpose-built Functions that build on the same envelope but emit non-tabular data:

typeResponse shapeExamplesGuide
topologydata.actors/data.links graph plus compact-schema sections (data.evidence, data.tables, data.overlays)topology:network-connections, topology:streaming, topology:snmpquery-topology.md
flowsdata.flows[] plus data.facets / data.columns / data.stats over a time windowflows:netflow (covers NetFlow / sFlow / IPFIX)query-flows.md

For full protocol semantics (facet pills, histograms, charts configuration, anchor/delta/PLAY modes, error handling, edge cases), the authoritative source is <repo>/src/plugins.d/FUNCTION_UI_REFERENCE.md. This skill summarizes the surface that matters for a Cloud-side curl client; the reference covers everything else.


Standard response envelope

Every Function -- regardless of family -- wraps its output in this envelope. Verified live against the agent's systemd-journal, topology:snmp, and flows:netflow Functions, and against the agent emit code at src/web/api/functions/function-metrics-cardinality.c:26-39,92 plus per-collector wrappers.

KeyTypeRequiredNotes
statusintyesHTTP-style status (200, 400, ...)
vintyesFunction schema version (currently 3 or 4 depending on Function)
typestringyesFamily discriminator: table, logs, topology, flows (some Functions emit a custom string -- treat unknown values as table-like)
helpstringtypicalHuman-readable description
accepted_paramsarray<string>typicalParameter names accepted in the body
required_paramsarray<object>typicalPer-parameter widget descriptors -- see "info=true discovery" below
has_historybooltypicalWhether the Function honors after / before
update_everyinttypicalSuggested refresh interval in seconds
dataarray OR objectconditionalFamily-specific result. Absent on info=true calls and on errors. Array for logs and table families; object (with actors/links or flows/columns/stats) for topology and flows
columnsobjectlogs / tableColumn-metadata, keyed by column name. Each entry has index (position inside each row of data), name, type, visible, sort, summary, filter, ...
facetsarraylogs / flowsPer-field value distribution and option counts
histogramobjectlogs (when requested)Bucketed counts over time
paginationobjectlogsanchor, direction, last, etc.
presentationobjecttopology / flowsVisualization metadata for the Cloud UI
expires / last_modified / partial / messagescalaroptionalCaching, freshness, partial-result diagnostics
versionsobjectoptionalSource/version hashes for client cache invalidation

status >= 400 responses follow the same envelope but include an errorMessage / errorMsgKey instead of data.


info=true discovery

The single most important call to make before constructing a real query: pass {"info": true} and read accepted_params plus required_params. The agent itself is the authoritative source -- if a parameter exists there, the Function accepts it; if it doesn't, no other doc matters.

bash
TOKEN="YOUR_API_TOKEN"
NODE="YOUR_NODE_UUID"
FN="systemd-journal"

read -r -d '' PAYLOAD <<'EOF'
{ "info": true }
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v2/nodes/$NODE/function?function=$FN" \
  -d "$PAYLOAD"

required_params widget schema

Each entry of required_params is a UI-widget descriptor that tells a client what to render and what values are valid. Verified against the emit code in src/collectors/network-viewer.plugin/network-viewer.c:1601-1731 and across the topology / logs / flows Functions.

FieldTypeRequiredPurpose
idstringyesParameter id (the body key)
namestringyesDisplay label
helpstringtypicalTooltip / help text
typestringyesWidget kind -- see table below
options[]arrayfor select/multiselect/autocompleteEach option: { "id": "<value>", "name": "<label>", "defaultSelected": <bool>? }
unique_viewbooloptionalSingle-select enforces single-value semantics
multiselectbooloptionalMulti-value semantics
patternstringoptionalRegex/glob input for text/pattern widgets
default_valuescalaroptionalPre-filled value

Widget type values seen in source:

typeMeaning
selectSingle-choice dropdown
multiselectMulti-choice; each option may have defaultSelected:true
autocompleteText input backed by an autocomplete query (the Function itself answers via mode:"autocomplete" or similar)
textFree-form text
checkboxBoolean toggle
rangeNumeric range / slider (newer Functions)
patternPattern / regex input (newer Functions)

The widget array is the contract between the agent and any UI or script. To programmatically construct a valid body for a Function, walk required_params and emit the body shape it implies. There is no central widget builder API in source -- each collector emits the array directly via buffer_json_* calls -- so the agent's own info=true response is the only authoritative place to read the schema for a specific node version.


Endpoints

List Functions on the nodes in a room

POST /api/v3/spaces/{spaceID}/rooms/{roomID}/functions

bash
TOKEN="YOUR_API_TOKEN"
SPACE="YOUR_SPACE_ID"
ROOM="YOUR_ROOM_ID"

read -r -d '' PAYLOAD <<'EOF'
{
  "scope":     { "nodes": [] },
  "selectors": { "nodes": ["*"] }
}
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v3/spaces/$SPACE/rooms/$ROOM/functions" \
  -d "$PAYLOAD"

Response top-level: functions[] (each entry: name, version, help, ni[], tags, access[], priority), nodes[] (each { ni, mg, nd, nm, st }), agents[], versions. Match functions[].ni to nodes[].ni to find which nodes expose a given Function.

Invoke a Function on a node

POST /api/v2/nodes/{nodeId}/function?function={functionName}

bash
TOKEN="YOUR_API_TOKEN"
NODE="YOUR_NODE_UUID"
FN="processes"

read -r -d '' PAYLOAD <<'EOF'
{
  "last":    50,
  "timeout": 30000
}
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v2/nodes/$NODE/function?function=$FN" \
  -d "$PAYLOAD"

Optional headers:

HeaderPurpose
X-Transaction-Id: <uuid>Correlation id propagated to the agent. Optional.

Frequently registered Functions

Function availability is per-node. The listing endpoint above is the only authoritative source. Below are common Functions on a stock Linux Netdata install (verified live):

FunctionFamilyWhat it returns
processestableLive process list with CPU / memory / I/O / page faults / PPID
network-connectionstableActive sockets/connections (proto, state, addresses, ports, perf metrics)
network-interfacestablePer-interface traffic, packet counts, drops, link status
block-devicestablePer-block-device read/write throughput, ops, latency, utilization
mount-pointstableFilesystem mount points with space and inode usage
containers-vmstableActive containers and cgroups with resource usage
systemd-servicestablesystemd service cgroups with process counts and resource use
netdata-streamingtableParent-child streaming/replication status, data-flow metrics, ML status
netdata-api-callstableActive and recent Netdata API requests with timings
netdata-metrics-cardinalitytableCardinality stats (instances, time-series per context/node)
systemd-journallogssystemd journal entries -- see query-logs.md
windows-eventslogsWindows event log channels (Windows nodes only)
macos-logslogsmacOS unified log entries (macOS nodes only)
otel-logslogsOpenTelemetry log entries (when the OTEL log receiver is enabled)
topology:snmptopologyLLDP/CDP/FDB/STP-derived L2 topology -- see query-topology.md
flows:netflowflowsNetFlow / sFlow / IPFIX records -- see query-flows.md

Database collectors register a per-collector family of Functions when active: <collector>:top-queries, <collector>:running-queries, <collector>:deadlock-info, <collector>:error-info -- e.g. postgres:top-queries, mysql:top-queries, mssql:deadlock-info. The listing endpoint reports them when the collector is enabled.


Examples (table-snapshot Functions)

For logs / topology / flows examples, see the per-family guides linked at the top.

Example 1: top processes by CPU

bash
TOKEN="YOUR_API_TOKEN"
NODE="YOUR_NODE_UUID"

read -r -d '' PAYLOAD <<'EOF'
{
  "last":    50,
  "timeout": 30000
}
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v2/nodes/$NODE/function?function=processes" \
  -d "$PAYLOAD" \
  | jq '.data | length, (.[0:3])'

Example 2: discover a Function's parameter widget set

bash
read -r -d '' PAYLOAD <<'EOF'
{ "info": true }
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v2/nodes/$NODE/function?function=network-connections" \
  -d "$PAYLOAD" \
  | jq '.required_params | map({id, type, name, options: (.options | length // 0)})'

Example 3: list the Functions on a single node

bash
read -r -d '' PAYLOAD <<'EOF'
{
  "scope":     { "nodes": ["YOUR_NODE_UUID"] },
  "selectors": { "nodes": ["*"] }
}
EOF

curl -sS -X POST \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $TOKEN" \
  "https://app.netdata.cloud/api/v3/spaces/$SPACE/rooms/$ROOM/functions" \
  -d "$PAYLOAD" \
  | jq -r '.functions[] | "\(.name)\t\(.tags // "")\t\(.help)"'

Limits and gotchas

  • Cloud default timeout is 120 s for Function calls; pass "timeout": <ms> in the body for slower Functions but Cloud may impose its own ceiling.
  • Response is NOT streamed. The Cloud proxy collects the full agent response and returns it in one body. For potentially huge results (logs, flows), narrow the time window or use the Function's pagination (last, anchor) rather than relying on streaming.
  • Node must be reachable. A stale node returns HTTP 400 with errorMsgKey: "ErrInstanceNotReachable". Verify with the discovery endpoints in SKILL.md.
  • Permission: the cloud token must include PermissionFunctionExec on the target space. scope:all works; scope:grafana-plugin does NOT.
  • Function name is case-sensitive -- wrong casing returns 400.
  • info=true does NOT bypass auth. ACL is enforced on every call regardless of body.
  • The agent's own info=true response is authoritative for parameters. Tables in this skill can drift relative to the running version. When in doubt, ask the agent.