Observability
Observability API client for kdb Insights Enterprise.
Use ObservabilityService to stream logs, query Kubernetes events, and list running workload pods in a deployed kdb Insights Enterprise namespace.
Example
Fetch and filter logs:
from kxi.observability import ObservabilityService
obs = ObservabilityService(host="https://<host>")
# Fetch the last 100 log lines for a namespace
logs = obs.get_logs(namespace="my-namespace", tailLines=100)
for log in logs:
print(log.level, log.message)
Example
Stream logs continuously and inspect workload health:
# Stream logs until Ctrl+C
obs.watch_logs(namespace="my-namespace", pretty=True)
# Query Kubernetes events for a specific workload
events = obs.get_events(namespace="my-namespace", workload="assembly1")
for event in events:
print(event.reason, event.message)
# List all running pods
pods = obs.get_pods(namespace="my-namespace")
for pod in pods:
print(pod.pod, pod.phase, pod.containers)
Classes:
- ObservabilityLogLevel – Log severity levels used to filter or classify log messages.
- ObservabilityLogMsg – Structured log message returned by the Observability API.
- ObservabilityService – REST client for the kdb Insights Enterprise Observability API.
- WorkloadEvent – Kubernetes event associated with a workload pod.
- WorkloadPod – Pod information for a running workload.
Functions:
- drop_nones – Drop None values from a dict.
- get_remote_logger_func – Get a pretty remote logger.
- parse_time_stamp – Parse time stamp.
ObservabilityLogLevel¶
Log severity levels used to filter or classify log messages.
Pass as the level parameter to
ObservabilityService.get_logs.
Attributes:
- TRACE – Most verbose level, below DEBUG.
- DEBUG – Detailed diagnostic information.
- INFO – Standard informational messages.
- WARN – Warning conditions that don't cause failures.
- WARNING – Alias for
WARN. - ERROR – Error conditions that may cause partial failure.
- FATAL – Critical failure — process cannot continue.
ObservabilityLogMsg¶
Bases: BaseModel
Structured log message returned by the Observability API.
All fields are optional. Unrecognised API fields are preserved via extra="allow".
Attributes:
- level (
ObservabilityLogLevel | None) – Severity level. - message (
str | None) – Log message text. - time (
str | None) – ISO 8601 timestamp. - pod (
str | None) – Pod name that emitted the log. - container (
str | None) – Container name within the pod. - component (
str | None) – Logical component (e.g. pipeline name). - service (
str | None) – Service identifier. - host (
str | None) – Host or node name. - corr (
str | None) – Correlation ID for request tracing. - instance (
str | None) – Instance identifier. - source (
str | None) – Source of the log entry. - status (
int | None) – HTTP status code, when applicable. - method (
str | None) – HTTP method, when applicable. - uri (
str | None) – Request URI, when applicable. - user (
str | None) – Authenticated user, when applicable.
ObservabilityService¶
Bases: ApiClient
REST client for the kdb Insights Enterprise Observability API.
Provides access to logs, Kubernetes events, and workload pod information.
Connects to the /observe service path on the kdb Insights host.
Example
from kxi.observability import ObservabilityService
obs = ObservabilityService(host="https://<host>")
logs = obs.get_logs(namespace="my-namespace", tailLines=50)
pods = obs.get_pods(namespace="my-namespace")
See Connection Parameters for shared constructor arguments.
Functions:
- a_get_logs – Asynchronously yield log messages as they arrive.
- async_watch_logs – Asynchronously stream logs until the task is cancelled.
- get_events – Fetch Kubernetes events for a namespace.
- get_logs – Fetch logs from a namespace.
- get_pods – Fetch the list of running pods in a namespace.
- watch_logs – Stream logs continuously until interrupted with Ctrl+C.
a_get_logs¶
a_get_logs(**params)
Asynchronously yield log messages as they arrive.
When follow=False, fetches current logs once and returns.
When follow=True (default), streams logs continuously.
Parameters:
- *params* – Filtering parameters forwarded to the log API (see get_logs).
Yields:
AsyncGenerator[ObservabilityLogMsg, None]– ObservabilityLogMsg objects.
async_watch_logs¶
async_watch_logs(**params)
Asynchronously stream logs until the task is cancelled.
Parameters:
- *params* – Filtering parameters forwarded to the log API (see get_logs).
get_events¶
get_events(**params)
Fetch Kubernetes events for a namespace.
Parameters:
- namespace – Target Kubernetes namespace.
- pod – Exact pod name to retrieve events for.
- package – Filter pods associated with a specific package.
- workload – Limit results to components related to this workload.
- label – Comma-separated key-value label selectors.
- pretty – Render response with indentation.
- *params* – Additional keyword arguments passed to the events API.
Returns:
list[WorkloadEvent]– List of WorkloadEvent objects.
get_logs¶
get_logs(**params)
Fetch logs from a namespace.
Parameters:
- namespace – Target Kubernetes namespace.
- pod – Filter by pod name.
- container – Filter by container name.
- workload – Limit results to components related to this workload.
- label – Comma-separated key-value label selectors.
- component – Regex applied to the workload name.
- level – Minimum log level to return (see ObservabilityLogLevel).
- logComponent – Filter by the log message
componentfield. - search – Case-insensitive substring search on the message field.
- corr – Filter by correlation ID.
- sinceSeconds – Return logs from this many seconds ago.
- sinceTime – RFC 3339 timestamp from which to return logs.
- tailLines – Number of lines from the end of the log to return per container.
- aggregate – Aggregate all log messages by log level.
- byPod – Group results by pod name and log level (requires
aggregate). - pretty – Pretty-print the response JSON.
- *params* – Additional keyword arguments passed to the log API.
Returns:
list[ObservabilityLogMsg]– List of ObservabilityLogMsg objects.
get_pods¶
get_pods(**params)
Fetch the list of running pods in a namespace.
Parameters:
- namespace – Target Kubernetes namespace.
- *params* – Additional keyword arguments passed to the workloads API.
Returns:
list[WorkloadPod]– List of WorkloadPod objects.
watch_logs¶
watch_logs(**params)
Stream logs continuously until interrupted with Ctrl+C.
Blocks the calling thread. Pass follow=False to fetch current logs once and exit.
Parameters:
- *params* – Filtering parameters forwarded to the log API (see get_logs).
WorkloadEvent¶
Bases: BaseModel
Kubernetes event associated with a workload pod.
Attributes:
- count (
int | None) – Number of times the event has occurred. - first_time (
str | None) – Timestamp of the first occurrence. - last_time (
str | None) – Timestamp of the most recent occurrence. - message (
str | None) – Human-readable event description. - name (
str | None) – Event object name. - namespace (
str | None) – Kubernetes namespace. - pod (
str | None) – Name of the related pod. - reason (
str | None) – Short machine-readable reason (e.g."OOMKilling"). - type (
str | None) – Event type —"Normal"or"Warning". - workload (
str | None) – Name of the related workload.
WorkloadPod¶
Bases: BaseModel
Pod information for a running workload.
Attributes:
- containers (
list[str]) – Names of containers running in the pod. - package (
str | None) – Package deployed into this pod. - phase (
str | None) – Kubernetes pod phase (e.g."Running","Pending"). - pod (
str | None) – Pod name. - workload (
str | None) – Workload name this pod belongs to.
drop_nones¶
drop_nones(d)
Drop None values from a dict.
get_remote_logger_func¶
get_remote_logger_func(name=DEFAULT_OBS_LOG_NAME, pretty=False)
Get a pretty remote logger.
parse_time_stamp¶
parse_time_stamp(time)
Parse time stamp.