TableParser (table_parser v0.1.1) View Source
Documentation for TableParser
.
Link to this section Summary
Functions
iex(1)> header = "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND" iex(2)> TableParser.get_columns_count(header) 11
iex(1)> header = "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND" iex(2)> TableParser.get_keys_from_header(header) [:user, :pid, :"%cpu", :"%mem", :vsz, :rss, :tty, :stat, :start, :time, :command]
iex(1)> line = "root 1 0.0 0.0 184856 7180 ? Ss Dec16 0:29 /sbin/init" iex(2)> TableParser.line_to_list(line) ["root", "1", "0.0", "0.0", "184856", "7180", "?", "Ss", "Dec16", "0:29", "/sbin/init"] iex(3)> line = "kuku 3844311 0.0 0.0 3896 1100 ? Ss 17:41 0:00 /usr/bin/xsel --nodetach -i -b" iex(4)> TableParser.line_to_list(line, 11) ["kuku", "3844311", "0.0", "0.0", "3896", "1100", "?", "Ss", "17:41", "0:00", "/usr/bin/xsel --nodetach -i -b"]
Function gets a table separated by spaces and returns a list of maps with headers and values from the rows iex(1)> ps_output = """ ...(1)> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ...(1)> root 1 0.0 0.0 184856 7180 ? Ss Dec16 0:29 /sbin/init ...(1)> """ iex(2)> TableParser.parse_table(ps_output) [ %{
Link to this section Functions
iex(1)> header = "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND" iex(2)> TableParser.get_columns_count(header) 11
iex(1)> header = "USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND" iex(2)> TableParser.get_keys_from_header(header) [:user, :pid, :"%cpu", :"%mem", :vsz, :rss, :tty, :stat, :start, :time, :command]
iex(1)> line = "root 1 0.0 0.0 184856 7180 ? Ss Dec16 0:29 /sbin/init" iex(2)> TableParser.line_to_list(line) ["root", "1", "0.0", "0.0", "184856", "7180", "?", "Ss", "Dec16", "0:29", "/sbin/init"] iex(3)> line = "kuku 3844311 0.0 0.0 3896 1100 ? Ss 17:41 0:00 /usr/bin/xsel --nodetach -i -b" iex(4)> TableParser.line_to_list(line, 11) ["kuku", "3844311", "0.0", "0.0", "3896", "1100", "?", "Ss", "17:41", "0:00", "/usr/bin/xsel --nodetach -i -b"]
Function gets a table separated by spaces and returns a list of maps with headers and values from the rows iex(1)> ps_output = """ ...(1)> USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND ...(1)> root 1 0.0 0.0 184856 7180 ? Ss Dec16 0:29 /sbin/init ...(1)> """ iex(2)> TableParser.parse_table(ps_output) [ %{
"%cpu": "0.0",
"%mem": "0.0",
command: "/sbin/init",
pid: "1",
rss: "7180",
start: "Dec16",
stat: "Ss",
time: "0:29",
tty: "?",
user: "root",
vsz: "184856"
} ]