src/libnetdata/facets/README.md
The facets engine provides a unified interface for querying, searching, and analyzing log data from multiple sources including systemd journal (Linux) and Windows Event logs.
The logs query system uses a two-phase approach:
When called with info=true, the system returns metadata about available log sources and accepted parameters.
{
"_request": {
// Echo of the request parameters
},
"versions": {
"sources": 1748491820000467 // Version timestamp for source list
},
"v": 3, // API version
"accepted_params": [
// List of all parameters the API accepts
],
"required_params": [
// Array of required parameter definitions
],
"show_ids": false,
"has_history": true,
"pagination": {
"enabled": true,
"key": "anchor",
"column": "timestamp",
"units": "timestamp_usec"
},
"status": 200,
"type": "table",
"help": "..."
}
Sources are hierarchical and represent different views of journal data:
all - All available logsall-local-logs - All local logsall-local-namespaces - Namespace-specific logsall-local-system-logs - System logs onlyall-local-user-logs - User logs onlynamespace-* - Specific namespace logsremote-* - Remote logs (if available)Each source includes:
Sources are Windows Event channels organized by provider:
All - All event channelsAll-Admin - Administrative channelsAll-Classic - Classic event logs (Application, Security, System)All-Operational - Operational channelsMicrosoft-Windows-*/Operational)Netdata/Health, Netdata/Daemon)Each source includes:
default_selected flag (indicates if selected by default)Windows Events Performance Optimization:
__logs_sources - Multiselect field for choosing log sources to queryafter - Start timestamp (Unix seconds)before - End timestamp (Unix seconds)anchor - Pagination anchor (timestamp in microseconds)direction - "backward" (newest first) or "forward"last - Number of entries to return (default: 200)query - Full-text search queryfacets - Array of field names to analyze and return facet countshistogram - Field name for generating time-based histogram (default: _PRIORITY for Linux, Level for Windows)data_only - Return only log data without facet analysisdelta - Return incremental updatestail - Follow mode for real-time updatessampling - Sample rate for large datasets (default: 1000000)slice - Time slicing for analysisif_modified_since - Conditional requestsWhen parameters are not specified:
source_type: 1 (platform default)direction: "backward" (newest entries first)last: 200 entriessampling: 1000000The system is designed to work without user intervention:
Source Auto-Selection:
default_selected: true should be pre-selectedImmediate Data Fetch:
info call, clients should immediately fetch dataThe query response includes:
data_only=true)data_only=true)Get available sources:
GET /api/v1/logs?info=true
Parse response and auto-select sources:
default_selected: true (Windows)Query logs:
POST /api/v1/logs
{
"__logs_sources": ["Application", "System"],
"after": 1748527000,
"before": 1748528000,
"query": "error",
"last": 100
}
data_only=true)The fastest query mode that seeks directly to the anchor point (or time boundary) and returns the next last entries in the specified direction:
delta=true is specifieddata_only=false) - DefaultScans the entire time window to calculate complete facet counts and histogram data:
last entries as data_only modetail=true)Combined with data_only=true and delta=true for efficient log following:
if_modified_since, returns HTTP 304 if no changestail -f or journalctl -fsampling)Controls when statistical sampling begins:
unsampled and estimatedslice)Database-level filtering optimization (Linux only):
slice=false (default):
slice=true (when backend supports it):
Windows Events note: Does not support slicing; Netdata maintains internal cache of possible facet values.
For long-running queries:
Log databases often contain out-of-order entries:
data_only=true queriesversions.sources)tail=truehas_history=true (like logs) are currently excluded from MCP's table processing{"type": "table", "data": [...], "columns": {...}}Regular Table Functions (e.g., processes, network connections):
{
"status": 200,
"type": "table",
"has_history": false,
"columns": { /* column definitions */ },
"data": [ /* simple arrays of values */ ],
"charts": { /* optional chart configs */ }
}
Logs Functions (e.g., systemd-journal, Windows events):
{
"status": 200,
"type": "table",
"has_history": true,
"_request": { /* complete request parameters */ },
"columns": { /* column definitions with facet support */ },
"data": [
/* arrays starting with timestamp, rowOptions, then values */
],
"facets": { /* available filters with counts */ },
"histogram": { /* time-series visualization */ },
"pagination": { /* anchor-based navigation */ },
"_journal_files": { /* source metadata */ },
"_sampling": { /* sampling statistics */ },
"items": 12345,
"last_modified": 1234567890,
/* many more metadata fields */
}
Key differences:
The same systemd-journal can contain completely different datasets with different schemas:
Standard System Logs - Traditional journal fields:
_HOSTNAME, _UID, _GID, _PID, _COMM, _EXEMESSAGE, PRIORITY, SYSLOG_FACILITY, SYSLOG_IDENTIFIER_SYSTEMD_UNIT, _SYSTEMD_CGROUP, _SYSTEMD_SLICE_BOOT_ID, _MACHINE_ID, _RUNTIME_SCOPENetdata Agent Events - Custom application data with AE_ prefix:
AE_AGENT_ID, AE_AGENT_VERSION, AE_AGENT_STATUSAE_HW_BOARD_NAME, AE_HW_CHASSIS_TYPE, AE_HW_SYS_VENDORAE_HOST_CLOUD_PROVIDER, AE_HOST_CONTAINER, AE_AGENT_KUBERNETESAE_AGENT_CRASHES, AE_FATAL_FAULT_ADDRESS, AE_FATAL_THREADAE_AGENT_UPTIME, AE_AGENT_TIMINGS_INIT, AE_AGENT_TIMINGS_EXITOther Structured Data - Any application can log structured data:
ND_ALERT_NAME, ND_ALERT_STATUS, ND_ALERT_CLASSThis variability means:
Linux (systemd-journal):
Windows (Event logs):