Monitorex.Exports (monitorex v0.6.0)

Copy Markdown

Export utilities for Monitorex — generates CSV and JSON from page data.

Used by the dashboard export buttons to download current view as a file.

Summary

Functions

Builds a filename for an exported page. Format: monitorex{page}{timestamp}.{ext}

Sanitizes a filename for safe filesystem use. Replaces non-alphanumeric characters (except . - _) with underscores.

Generates CSV string from a list of maps (rows) and column definitions.

Generates pretty-printed JSON from a list of maps or structs.

Functions

filename(page_name, ext)

@spec filename(String.t(), String.t()) :: String.t()

Builds a filename for an exported page. Format: monitorex{page}{timestamp}.{ext}

sanitize_filename(name)

@spec sanitize_filename(String.t()) :: String.t()

Sanitizes a filename for safe filesystem use. Replaces non-alphanumeric characters (except . - _) with underscores.

to_csv(data, fields)

@spec to_csv([map()], [atom()]) :: String.t()

Generates CSV string from a list of maps (rows) and column definitions.

Columns define both order and which keys to include. Handles commas, quotes, and newlines in cell values.

to_json(data, fields \\ [])

@spec to_json([map()], [atom()]) :: String.t()

Generates pretty-printed JSON from a list of maps or structs.

When fields is provided, only those keys are included (same as CSV export). Structs are converted to plain maps before encoding.