### Get Comprehensive Process Information with recon:info/1 Source: https://context7.com/ferd/recon/llms.txt Safely retrieves detailed process information, excluding sensitive fields. Supports various input types for process identification and allows fetching specific categories or attributes. ```erlang %% Get info for a registered process 1> recon:info(whereis(init)). [{meta,[{registered_name,init}, {dictionary,[{'$ancestors',[]}]}, {group_leader,<0.0.0>}, {status,waiting}]}, {signals,[{links,[<0.3.0>,<0.5.0>,<0.7.0>]}, {monitors,[]}, {monitored_by,[]}, {trap_exit,true}]}, {location,[{initial_call,{otp_ring0,start,2}}, {current_stacktrace,[{init,loop,1,[]}]}]}, {memory_used,[{memory,5424}, {message_queue_len,0}, {heap_size,610}, {total_heap_size,752}, {garbage_collection,[...]}]}, {work,[{reductions,3402}]}] %% Using pid as string 2> recon:info("<0.1.0>"). %% Using pid as tuple 3> recon:info({0,1,0}). %% Get specific category only 4> recon:info(init, memory_used). {memory_used,[{memory,5424}, {message_queue_len,0}, {heap_size,610}, {total_heap_size,752}, {garbage_collection,[...]}]} %% Get specific attributes 5> recon:info(init, [memory, status]). [{memory,5424},{status,waiting}] %% Get binary memory (special attribute) 6> recon:info(SomePid, binary_memory). {binary_memory,1048576} ``` -------------------------------- ### Get Module Source Code Source: https://context7.com/ferd/recon/llms.txt Retrieves the source code of a module. ```APIDOC ## recon:source/1 - Get Module Source Code Retrieves the source code of a module compiled with debug_info. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang 1> io:format("~s~n", [recon:source(lists)]). ``` ### Response #### Success Response (200) Returns the source code of the module as a string. #### Response Example ```erlang -module(lists). -export([append/2, ...]). ... ``` ``` -------------------------------- ### recon:info/1 - Get Comprehensive Process Information Source: https://context7.com/ferd/recon/llms.txt Returns detailed process information grouped by category (meta, signals, location, memory_used, work), safely excluding potentially dangerous fields like the full mailbox. Supports querying specific categories or attributes. ```APIDOC ## recon:info/1 - Get Comprehensive Process Information ### Description Returns detailed process information grouped by category (meta, signals, location, memory_used, work), safely excluding potentially dangerous fields like the full mailbox. ### Method `erlang:apply` (internal, but used via `recon:info`) ### Endpoint N/A (Erlang function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Get info for a registered process 1> recon:info(whereis(init)). %% Using pid as string 2> recon:info("<0.1.0>"). %% Using pid as tuple 3> recon:info({0,1,0}). %% Get specific category only 4> recon:info(init, memory_used). %% Get specific attributes 5> recon:info(init, [memory, status]). %% Get binary memory (special attribute) 6> recon:info(SomePid, binary_memory). ``` ### Response #### Success Response (200) - **meta** (list) - Process metadata including registered name, dictionary, group leader, and status. - **signals** (list) - Information about process links, monitors, and trap_exit status. - **location** (list) - Details about the process's initial call and current stacktrace. - **memory_used** (list) - Memory usage statistics including memory, message queue length, heap size, total heap size, and garbage collection info. - **work** (list) - Information about process reductions. #### Response Example ```erlang [{meta,[{registered_name,init}, {dictionary,[{'$ancestors',[]}]}, {group_leader,<0.0.0>}, {status,waiting}]}, {signals,[{links,[<0.3.0>,<0.5.0>,<0.7.0>]}, {monitors,[]}, {monitored_by,[]}, {trap_exit,true}]}, {location,[{initial_call,{otp_ring0,start,2}}, {current_stacktrace,[{init,loop,1,[]}]}]}, {memory_used,[{memory,5424}, {message_queue_len,0}, {heap_size,610}, {total_heap_size,752}, {garbage_collection,[...]}]}, {work,[{reductions,3402}]}] ``` ``` -------------------------------- ### Get Detailed Port Information Source: https://context7.com/ferd/recon/llms.txt Returns comprehensive port information, including inet-specific details for network ports. Use to diagnose issues with specific network connections. ```erlang %% Get info for a TCP port 1> recon:port_info(hd(recon:tcp())). [{meta,[{id,1234}, {name,"tcp_inet"}, {os_pid,undefined}]}, {signals,[{connected,<0.89.0>}, {links,[<0.89.0>]}, {monitors,[]}]}, {io,[{input,45678}, {output,12345}]}, {memory_used,[{memory,1234}, {queue_size,0}]}, {type,[{statistics,[{recv_cnt,100}, {recv_max,1500}, {recv_avg,256}, {recv_oct,25600}, {recv_dvi,0}, {send_cnt,50}, {send_max,1400}, {send_avg,280}, {send_oct,14000}, {send_pend,0}]}, {peername,{{192,168,1,100},54321}}, {sockname,{{0,0,0,0},8080}}, {options,[{active,true}, {nodelay,true}, {packet,raw}]}]} %% Get info using port index 2> recon:port_info(1234). %% Get info using port string 3> recon:port_info("#Port<0.1234>"). ``` -------------------------------- ### Get Module Source Code with recon:source/1 Source: https://context7.com/ferd/recon/llms.txt Retrieves the source code of a module, provided it was compiled with debug_info. The output includes module definition, exports, and other directives. ```erlang 1> io:format("~s~n", [recon:source(lists)]). -module(lists). -export([append/2, ...]). ... ``` -------------------------------- ### Get Scheduler CPU Usage Source: https://context7.com/ferd/recon/llms.txt Returns per-scheduler CPU utilization as a ratio (0.0 to 1.0). Provides more accurate CPU usage than OS-reported metrics. Values close to 1.0 indicate saturation. ```erlang %% Measure scheduler usage over 1 second 1> recon:scheduler_usage(1000). [{1,0.12345}, {2,0.09876}, {3,0.05432}, {4,0.02345}, {5,0.01234}, {6,0.00987}, {7,0.00543}, {8,0.00234}] %% Interpretation: scheduler 1 was busy 12.3% of the time %% Values close to 1.0 indicate scheduler saturation ``` -------------------------------- ### Get OTP Process State Source: https://context7.com/ferd/recon/llms.txt Safely retrieves the internal state of an OTP process (gen_server, gen_statem, etc.). Use with caution as it bypasses normal message passing. ```erlang %% Get state of a gen_server 1> recon:get_state(my_server). {state,connected,#{clients => [], buffer => <<>>}} %% Get state with timeout 2> recon:get_state(my_server, 10000). %% Get state using pid 3> recon:get_state("<0.123.0>"). ``` -------------------------------- ### Get Allocator Memory Usage with recon_alloc:memory/1,2 Source: https://context7.com/ferd/recon/llms.txt Reports memory usage from Erlang's memory allocators. Can retrieve currently used, allocated, unused memory, usage ratio, allocation by type, and max values. ```erlang %% Get currently used memory 1> recon_alloc:memory(used). 45678901 ``` ```erlang %% Get allocated (reserved) memory 2> recon_alloc:memory(allocated). 67890123 ``` ```erlang %% Get unused but allocated memory 3> recon_alloc:memory(unused). 22211222 ``` ```erlang %% Get usage ratio (0.0 to 1.0) 4> recon_alloc:memory(usage). 0.67 ``` ```erlang %% Get allocation by allocator type 5> recon_alloc:memory(allocated_types). [{binary_alloc,12345678}, {driver_alloc,234567}, {eheap_alloc,34567890}, {ets_alloc,4567890}, {fix_alloc,567890}, {ll_alloc,6789012}, {sl_alloc,789012}, {std_alloc,89012}, {temp_alloc,9012}] ``` ```erlang %% Get max values (peak usage) 6> recon_alloc:memory(used, max). 56789012 ``` -------------------------------- ### recon:proc_window/3 - Find Top Processes Over Time Window Source: https://context7.com/ferd/recon/llms.txt Returns top N processes based on attribute changes over a sliding time window, useful for finding processes that are actively consuming resources. ```APIDOC ## recon:proc_window/3 - Find Top Processes Over Time Window ### Description Returns top N processes based on attribute changes over a sliding time window, useful for finding processes that are actively consuming resources. ### Method `erlang:apply` (internal, but used via `recon:proc_window`) ### Endpoint N/A (Erlang function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Find top 5 processes by reductions over 1 second 1> recon:proc_window(reductions, 5, 1000). %% Find processes growing memory fastest over 5 seconds 2> recon:proc_window(memory, 10, 5000). %% Find processes with growing message queues over 2 seconds 3> recon:proc_window(message_queue_len, 5, 2000). ``` ### Response #### Success Response (200) - **pid** (pid) - The process identifier. - **attribute_change** (integer) - The change in the resource attribute over the time window. - **process_info** (list) - A list containing the process name, current function, and initial call. #### Response Example ```erlang [{<0.89.0>,145623,[worker_pool, {current_function,{gen_server,loop,7}}, {initial_call,{proc_lib,init_p,5}}]}, {<0.90.0>,98234,[{current_function,{ets,select,2}}, {initial_call,{proc_lib,init_p,5}}]}] ``` ``` -------------------------------- ### Snapshot Memory State with recon_alloc:snapshot/0 and Friends Source: https://context7.com/ferd/recon/llms.txt Allows taking, managing, and saving/loading snapshots of allocator state for offline analysis. Functions include `snapshot/0`, `snapshot_save/2`, `snapshot_load/1`, and `snapshot_clear/0`. ```erlang %% Take a snapshot 1> recon_alloc:snapshot(). undefined % returns previous snapshot (none) ``` ```erlang %% Use memory functions on snapshot 2> recon_alloc:memory(used). 45678901 ``` ```erlang %% Save snapshot to file 3> recon_alloc:snapshot_save("/tmp/alloc_snapshot.terms"). ok ``` ```erlang %% On another machine or later: 4> recon_alloc:snapshot_load("/tmp/alloc_snapshot.terms"). 5> recon_alloc:memory(used). 45678901 ``` ```erlang %% Clear snapshot 6> recon_alloc:snapshot_clear(). ``` -------------------------------- ### Set Up Safe Function Tracing with recon_trace:calls Source: https://context7.com/ferd/recon/llms.txt Sets up rate-limited tracing for function calls with automatic safety guards. Use to trace all calls, specific arities, or with return values. Supports rate limiting and match specifications. ```erlang 1> recon_trace:calls({queue, new, '_'}, 10). 1 13:14:34.086078 <0.44.0> queue:new() ``` ```erlang 2> recon_trace:calls({queue, in, 2}, 10). 1 13:14:55.365157 <0.44.0> queue:in(a, {[],[]}) ``` ```erlang 3> recon_trace:calls({queue, in, fun(_) -> return_trace() end}, 10). 1 13:15:27.655132 <0.44.0> queue:in(a, {[],[]}) 13:15:27.655467 <0.44.0> queue:in/2 --> {[a],[]} ``` ```erlang 4> recon_trace:calls({queue, '_', '_'}, {10, 100}). 32 ``` ```erlang 5> recon_trace:calls( {queue, '_', fun([A,_]) when is_list(A) -> return_trace() end}, {10, 100}). ``` ```erlang 6> recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, whereis(myproc)}]). ``` ```erlang 7> recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, new}]). ``` ```erlang 8> recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, [whereis(proc1), whereis(proc2), new]}]). ``` ```erlang 9> recon_trace:calls({mymod, internal_fun, '_'}, 10, [{scope, local}]). ``` ```erlang 10> recon_trace:calls({mymod, myfun, '_'}, 10, [{args, arity}]). ``` ```erlang 11> {ok, Dev} = file:open("/tmp/traces.log", [write]). 12> recon_trace:calls({mymod, myfun, '_'}, 100, [{io_server, Dev}]). ``` -------------------------------- ### recon_trace:calls/2,3 - Set Up Safe Function Tracing Source: https://context7.com/ferd/recon/llms.txt Sets up rate-limited tracing for function calls with automatic safety guards. This function allows tracing specific function calls, with options for rate limiting, filtering by process, and controlling output format. ```APIDOC ## recon_trace:calls/2,3 - Set Up Safe Function Tracing ### Description Sets up rate-limited tracing for function calls with automatic safety guards. ### Method N/A (Erlang function) ### Endpoint N/A (Erlang function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```erlang %% Trace all calls to queue:new, max 10 traces recon_trace:calls({queue, new, '_'}, 10). %% Trace specific arity recon_trace:calls({queue, in, 2}, 10). %% Trace with return values recon_trace:calls({queue, in, fun(_) -> return_trace() end}, 10). %% Rate-limited tracing: 10 messages per 100ms recon_trace:calls({queue, '_', '_'}, {10, 100}). %% Trace with match specification recon_trace:calls({queue, '_', fun([A,_]) when is_list(A) -> return_trace() end}, {10, 100}). %% Trace specific process only recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, whereis(myproc)}]). %% Trace new processes only recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, new}]). %% Trace multiple specific processes recon_trace:calls({mymod, myfun, '_'}, 10, [{pid, [whereis(proc1), whereis(proc2), new]}]). %% Trace local calls (not just fully qualified) recon_trace:calls({mymod, internal_fun, '_'}, 10, [{scope, local}]). %% Show arity instead of arguments recon_trace:calls({mymod, myfun, '_'}, 10, [{args, arity}]). %% Write traces to file {ok, Dev} = file:open("/tmp/traces.log", [write]). recon_trace:calls({mymod, myfun, '_'}, 100, [{io_server, Dev}]). ``` ### Response #### Success Response (200) Returns an integer indicating the number of traces set up or a confirmation message. #### Response Example ```erlang 1 32 ok ``` ``` -------------------------------- ### Print Live Node Statistics Source: https://context7.com/ferd/recon/llms.txt Prints node statistics N times with a given interval, showing both absolute values and incremental changes. Use for real-time monitoring. ```erlang %% Print stats 5 times, every 1 second 1> recon:node_stats_print(5, 1000). {[{process_count,89}, {run_queue,0}, {memory_total,23456789}, {memory_procs,12345678}, {memory_atoms,345678}, {memory_bin,567890}, {memory_ets,234567}], [{bytes_in,1234}, {bytes_out,567}, {gc_count,12}, {gc_words_reclaimed,45678}, {reductions,123456}, {scheduler_usage,[{1,0.05},{2,0.03},{3,0.02},{4,0.01}]}]} %% ... repeats 4 more times ``` -------------------------------- ### OTP Integration Source: https://context7.com/ferd/recon/llms.txt Function for safely retrieving the state of OTP processes. ```APIDOC ## recon:get_state/1 - Get OTP Process State ### Description Safely retrieves the internal state of an OTP process (gen_server, gen_statem, etc.). ### Method `erlang` ### Endpoint `recon:get_state(Process, Timeout)` ### Parameters #### Path Parameters - **Process** (pid | atom | string) - Required - The process identifier (PID), registered name, or name of the process. - **Timeout** (integer) - Optional - The maximum time in milliseconds to wait for a response. ### Request Example ```erlang recon:get_state(my_server). recon:get_state(my_server, 10000). recon:get_state("<0.123.0>"). ``` ### Response #### Success Response (200) - **Process state**: The internal state of the OTP process. #### Response Example ```erlang {state,connected,#{clients => [], buffer => <<>>}} ``` ``` -------------------------------- ### recon_rec:import/1 - Import Record Definitions for Trace Output Source: https://context7.com/ferd/recon/llms.txt Imports record definitions so traces display records with field names. This enhances the readability of trace output by showing record fields instead of just the record structure. ```APIDOC ## recon_rec:import/1 - Import Record Definitions for Trace Output ### Description Imports record definitions so traces display records with field names. ### Method N/A (Erlang function) ### Endpoint N/A (Erlang function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```erlang %% Import records from a module recon_rec:import(my_records). %% Import from multiple modules recon_rec:import([my_records, other_module]). %% List imported records recon_rec:list(). %% Limit output to specific fields recon_rec:limit(my_state, 5, [id, status]). %% Clear all imports recon_rec:clear(). ``` ### Response #### Success Response (200) Returns a list of imported records or a confirmation message. `recon_rec:list()` returns a formatted string listing imported records. #### Response Example ```erlang [{imported,my_records,my_state,5}, {imported,my_records,my_config,3}] Module: #Name(Size){} Limits ========== my_records: #my_state(5){id,name,data,status,timestamp} none my_records: #my_config(3){host,port,timeout} none ``` ``` -------------------------------- ### Memory Allocator Analysis (recon_alloc) Source: https://context7.com/ferd/recon/llms.txt Functions for analyzing Erlang's memory allocator usage and fragmentation. ```APIDOC ## recon_alloc:memory/1,2 - Get Allocator Memory Usage Reports memory usage from Erlang's memory allocators. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Get currently used memory 1> recon_alloc:memory(used). 45678901 %% Get allocated (reserved) memory 2> recon_alloc:memory(allocated). 67890123 %% Get unused but allocated memory 3> recon_alloc:memory(unused). 22211222 %% Get usage ratio (0.0 to 1.0) 4> recon_alloc:memory(usage). 0.67 %% Get allocation by allocator type 5> recon_alloc:memory(allocated_types). [{binary_alloc,12345678}, {driver_alloc,234567}, {eheap_alloc,34567890}, {ets_alloc,4567890}, {fix_alloc,567890}, {ll_alloc,6789012}, {sl_alloc,789012}, {std_alloc,89012}, {temp_alloc,9012}] %% Get max values (peak usage) 6> recon_alloc:memory(used, max). 56789012 ``` ### Response #### Success Response (200) Returns memory usage information based on the provided argument (e.g., `used`, `allocated`, `usage`, `allocated_types`). The return type varies based on the argument. ``` ```APIDOC ## recon_alloc:fragmentation/1 - Analyze Memory Fragmentation Returns fragmentation data for all allocators, sorted by severity. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang 1> recon_alloc:fragmentation(current). [{{binary_alloc,3}, [{sbcs_usage,1.0}, {mbcs_usage,0.78}, {sbcs_block_size,0}, {sbcs_carriers_size,0}, {mbcs_block_size,234567}, {mbcs_carriers_size,300000}]}, {{eheap_alloc,1}, [{sbcs_usage,0.95}, {mbcs_usage,0.82}, ...]}] %% Check max fragmentation (peak) 2> recon_alloc:fragmentation(max). ``` ### Response #### Success Response (200) Returns fragmentation data, typically a list of tuples containing allocator type, severity, and detailed fragmentation metrics. ``` ```APIDOC ## recon_alloc:cache_hit_rates/0 - Check Allocator Cache Efficiency Returns cache hit rates for the mseg_alloc allocator. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang 1> recon_alloc:cache_hit_rates(). [{{instance,0},[{hit_rate,0.95},{hits,9500},{calls,10000}]}, {{instance,1},[{hit_rate,0.92},{hits,4600},{calls,5000}]}] %% Low hit rates (< 0.80) may indicate need to tune +MMmcs flag ``` ### Response #### Success Response (200) Returns a list of cache hit rate statistics for each allocator instance. ``` ```APIDOC ## recon_alloc:sbcs_to_mbcs/1 - Check Single vs Multiblock Carrier Ratio Returns the ratio of single block carriers to multiblock carriers. High ratios indicate potential performance issues. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang 1> recon_alloc:sbcs_to_mbcs(current). [{{binary_alloc,0},0.0}, {{eheap_alloc,1},0.001}, {{ets_alloc,2},0.05}] %% High ratios suggest need to tune sbct (single block carrier threshold) ``` ### Response #### Success Response (200) Returns the ratio of single block carriers to multiblock carriers for specified allocators. ``` ```APIDOC ## recon_alloc:snapshot/0 and Friends - Snapshot Memory State Take and manage snapshots of allocator state for offline analysis. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Take a snapshot 1> recon_alloc:snapshot(). undefined % returns previous snapshot (none) %% Use memory functions on snapshot 2> recon_alloc:memory(used). 45678901 %% Save snapshot to file 3> recon_alloc:snapshot_save("/tmp/alloc_snapshot.terms"). ok %% On another machine or later: 4> recon_alloc:snapshot_load("/tmp/alloc_snapshot.terms"). 5> recon_alloc:memory(used). 45678901 %% Clear snapshot 6> recon_alloc:snapshot_clear(). ``` ### Response #### Success Response (200) Functions like `snapshot`, `snapshot_save`, `snapshot_load`, and `snapshot_clear` return `ok` or previous snapshot data upon success. ``` ```APIDOC ## recon_alloc:set_unit/1 - Change Display Units Changes the unit for all memory values returned. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang 1> recon_alloc:memory(used). 45678901 % bytes 2> recon_alloc:set_unit(megabyte). 3> recon_alloc:memory(used). 43.56 % megabytes 4> recon_alloc:set_unit(kilobyte). 5> recon_alloc:memory(used). 44608.30 % kilobytes ``` ### Response #### Success Response (200) Indicates the unit has been successfully changed. Subsequent memory calls will use the new unit. ``` -------------------------------- ### Find Top Processes Over Time Window with recon:proc_window/3 Source: https://context7.com/ferd/recon/llms.txt Identifies top N processes based on attribute changes within a specified time window. This helps in detecting processes actively consuming resources over time. ```erlang %% Find top 5 processes by reductions over 1 second 1> recon:proc_window(reductions, 5, 1000). [{<0.89.0>,145623,[worker_pool, {current_function,{gen_server,loop,7}}, {initial_call,{proc_lib,init_p,5}}]}, {<0.90.0>,98234,[{current_function,{ets,select,2}}, {initial_call,{proc_lib,init_p,5}}]}] %% Find processes growing memory fastest over 5 seconds 2> recon:proc_window(memory, 10, 5000). %% Find processes with growing message queues over 2 seconds 3> recon:proc_window(message_queue_len, 5, 2000). ``` -------------------------------- ### Collect Node Statistics as List Source: https://context7.com/ferd/recon/llms.txt Collects node statistics and returns them as a list for programmatic analysis. Useful for historical data collection and batch processing. ```erlang %% Collect 10 samples, 500ms apart 1> Stats = recon:node_stats_list(10, 500). [{[{process_count,89},{run_queue,0},...], [{bytes_in,1234},{bytes_out,567},...]} | ...] %% Analyze collected data 2> [proplists:get_value(bytes_in, Incr) || {_Abs, Incr} <- Stats]. ``` ```erlang [1234, 2345, 1890, 3456, ...] ``` -------------------------------- ### Configure Map Display with recon_map:limit Source: https://context7.com/ferd/recon/llms.txt Configures how maps are displayed in trace output, allowing labeling and limiting maps matching a pattern or using a function for matching. Can list, remove, or clear patterns. ```erlang 1> recon_map:limit(user_state, #{type => user}, [id, name]). ok ``` ```erlang 2> recon_map:limit(large_map, fun(M) -> map_size(M) > 10 end, all). ok ``` ```erlang 3> recon_map:list(). map definitions and limits: large_map: #Fun<...> -> all user_state: [{type,user}] -> [id,name] ``` ```erlang 4> recon_map:remove(large_map). true ``` ```erlang 5> recon_map:clear(). ok ``` -------------------------------- ### RPC Utilities Source: https://context7.com/ferd/recon/llms.txt Utilities for executing functions on remote nodes. ```APIDOC ## recon:rpc/1,2,3 - Execute Fun on Remote Nodes Executes a fun on one or more nodes, supporting shell-defined anonymous functions. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Run on all connected nodes including self 1> recon:rpc(fun() -> node() end). {[node1@host, node2@host, node3@host], []} %% Run on specific nodes 2> recon:rpc([node1@host, node2@host], fun() -> erlang:memory(total) end). {[12345678, 23456789], []} %% Run with timeout 3> recon:rpc(nodes(), fun() -> expensive_operation() end, 30000). ``` ### Response #### Success Response (200) Returns a tuple where the first element is a list of results from each node, and the second element is a list of errors. ``` ```APIDOC ## recon:named_rpc/1,2,3 - Execute Fun with Node Names in Results Like rpc but wraps results with the originating node name. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Get memory from all nodes with node names 1> recon:named_rpc(fun() -> erlang:memory(total) end). {[{node1@host, 12345678}, {node2@host, 23456789}, {node3@host, 34567890}], []} %% Easier to identify which node has issues 2> recon:named_rpc(nodes(), fun() -> recon:proc_count(memory, 1) end). ``` ### Response #### Success Response (200) Returns a tuple where the first element is a list of {node_name, result} tuples, and the second element is a list of errors. ``` -------------------------------- ### Import Record Definitions with recon_rec:import Source: https://context7.com/ferd/recon/llms.txt Imports record definitions from a module to display records with field names in trace output. Can import from multiple modules or list imported records. ```erlang 1> recon_rec:import(my_records). [{imported,my_records,my_state,5}, {imported,my_records,my_config,3}] ``` ```erlang 2> recon_rec:import([my_records, other_module]). ``` ```erlang 3> recon_rec:list(). Module: #Name(Size){} Limits ========== my_records: #my_state(5){id,name,data,status,timestamp} none my_records: #my_config(3){host,port,timeout} none ``` ```erlang 4> recon_rec:limit(my_state, 5, [id, status]). ``` ```erlang 5> recon_rec:clear(). ``` -------------------------------- ### Load Module Remotely with recon:remote_load/1,2 Source: https://context7.com/ferd/recon/llms.txt Use to load a local module onto remote connected nodes without requiring the beam file on disk. Can target all nodes or specific nodes. ```erlang %% Load module to all connected nodes 1> recon:remote_load(my_module). {[ok,ok,ok],[]} ``` ```erlang %% Load module to specific nodes 2> recon:remote_load([node1@host, node2@host], my_module). {[ok,ok],[]} ``` ```erlang %% Load multiple modules 3> recon:remote_load(nodes(), [module1, module2, module3]). [[{ok,ok,ok}],[{ok,ok,ok}],[{ok,ok,ok}]] ``` -------------------------------- ### Remote Module Loading Source: https://context7.com/ferd/recon/llms.txt Functions for loading modules onto remote nodes. ```APIDOC ## recon:remote_load/1,2 - Load Module Remotely Loads a local module onto remote connected nodes without requiring the beam file on disk. ### Method `erlang` (function call) ### Endpoint N/A (Local function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```erlang %% Load module to all connected nodes 1> recon:remote_load(my_module). {[ok,ok,ok],[]} %% Load module to specific nodes 2> recon:remote_load([node1@host, node2@host], my_module). {[ok,ok],[]} %% Load multiple modules 3> recon:remote_load(nodes(), [module1, module2, module3]). [[{ok,ok,ok}],[{ok,ok,ok}],[{ok,ok,ok}]] ``` ### Response #### Success Response (200) Returns a tuple where the first element is a list of results for each node, and the second element is a list of errors. #### Response Example `{[ok,ok,ok],[]}` ``` -------------------------------- ### Analyze Memory Fragmentation with recon_alloc:fragmentation/1 Source: https://context7.com/ferd/recon/llms.txt Returns fragmentation data for all allocators, sorted by severity. Can analyze current fragmentation or peak fragmentation using the `max` option. ```erlang 1> recon_alloc:fragmentation(current). [{{binary_alloc,3}, [{sbcs_usage,1.0}, {mbcs_usage,0.78}, {sbcs_block_size,0}, {sbcs_carriers_size,0}, {mbcs_block_size,234567}, {mbcs_carriers_size,300000}]}, {{eheap_alloc,1}, [{sbcs_usage,0.95}, {mbcs_usage,0.82}, ...]}] ``` ```erlang %% Check max fragmentation (peak) 2> recon_alloc:fragmentation(max). ``` -------------------------------- ### Node Statistics Source: https://context7.com/ferd/recon/llms.txt Functions for printing and collecting node statistics, and measuring scheduler CPU usage. ```APIDOC ## recon:node_stats_print/2 - Print Live Node Statistics ### Description Prints node statistics N times with a given interval, showing both absolute values and incremental changes. ### Method `erlang` ### Endpoint `recon:node_stats_print(Count, Interval)` ### Parameters #### Path Parameters - **Count** (integer) - Required - Number of times to print statistics. - **Interval** (integer) - Required - Interval in milliseconds between prints. ### Request Example ```erlang recon:node_stats_print(5, 1000). ``` ### Response #### Success Response (200) - **List of statistics**: A list containing two lists: absolute statistics and incremental statistics. #### Response Example ```erlang [{[{process_count,89},{run_queue,0},{memory_total,23456789},{memory_procs,12345678},{memory_atoms,345678},{memory_bin,567890},{memory_ets,234567}], [{bytes_in,1234},{bytes_out,567},{gc_count,12},{gc_words_reclaimed,45678},{reductions,123456},{scheduler_usage,[{1,0.05},{2,0.03},{3,0.02},{4,0.01}]}]} ``` ## recon:node_stats_list/2 - Collect Node Statistics as List ### Description Collects node statistics and returns them as a list for programmatic analysis. ### Method `erlang` ### Endpoint `recon:node_stats_list(Count, Interval)` ### Parameters #### Path Parameters - **Count** (integer) - Required - Number of samples to collect. - **Interval** (integer) - Required - Interval in milliseconds between samples. ### Request Example ```erlang recon:node_stats_list(10, 500). ``` ### Response #### Success Response (200) - **List of statistics**: A list of collected statistics, where each element is a pair of absolute and incremental statistics. #### Response Example ```erlang [{[{process_count,89},{run_queue,0},...], [{bytes_in,1234},{bytes_out,567},...]} | ...] ``` ## recon:scheduler_usage/1 - Get Scheduler CPU Usage ### Description Returns per-scheduler CPU utilization as a ratio (0.0 to 1.0), more accurate than OS-reported CPU usage. ### Method `erlang` ### Endpoint `recon:scheduler_usage(Interval)` ### Parameters #### Path Parameters - **Interval** (integer) - Required - Measurement interval in milliseconds. ### Request Example ```erlang recon:scheduler_usage(1000). ``` ### Response #### Success Response (200) - **List of tuples**: Each tuple contains a scheduler ID and its CPU utilization ratio. #### Response Example ```erlang [{1,0.12345},{2,0.09876},{3,0.05432},{4,0.02345},{5,0.01234},{6,0.00987},{7,0.00543},{8,0.00234}] ``` ``` -------------------------------- ### Find Top N Processes by Attribute with recon:proc_count/2 Source: https://context7.com/ferd/recon/llms.txt Identifies the top N processes based on specified attributes like memory usage or reductions. Useful for pinpointing resource-intensive processes. ```erlang %% Find top 5 processes by memory usage 1> recon:proc_count(memory, 5). [{<0.123.0>,2048576,[some_worker, {current_function,{gen_server,loop,7}}, {initial_call,{proc_lib,init_p,5}}]}, {<0.45.0>,1024000,[code_server, {current_function,{code_server,loop,1}}, {initial_call,{erlang,apply,2}}]}, {<0.67.0>,512000,[{current_function,{ets,lookup,2}}, {initial_call,{proc_lib,init_p,5}}]}] %% Find top 10 processes by reductions (CPU usage) 2> recon:proc_count(reductions, 10). %% Find processes with largest message queues 3> recon:proc_count(message_queue_len, 5). %% Find processes using most binary memory 4> recon:proc_count(binary_memory, 5). ``` -------------------------------- ### List Network Ports Source: https://context7.com/ferd/recon/llms.txt Returns lists of all TCP, UDP, or SCTP ports open on the node. Use to inspect network activity. ```erlang %% List all TCP sockets 1> recon:tcp(). [#Port<0.1234>,#Port<0.1235>,#Port<0.1236>] %% List all UDP sockets 2> recon:udp(). [#Port<0.5678>] %% List all SCTP sockets 3> recon:sctp(). [] ``` -------------------------------- ### recon_map:limit/3 - Configure Map Display in Traces Source: https://context7.com/ferd/recon/llms.txt Configures how maps are displayed in trace output. This allows for custom labeling and limiting of map fields shown in traces. ```APIDOC ## recon_map:limit/3 - Configure Map Display in Traces ### Description Configures how maps are displayed in trace output. ### Method N/A (Erlang function) ### Endpoint N/A (Erlang function) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example ```erlang %% Label and limit maps matching a pattern recon_map:limit(user_state, #{type => user}, [id, name]). %% Use a function for matching recon_map:limit(large_map, fun(M) -> map_size(M) > 10 end, all). %% List configured patterns recon_map:list(). %% Remove a pattern recon_map:remove(large_map). %% Clear all patterns recon_map:clear(). ``` ### Response #### Success Response (200) Returns `ok` upon successful configuration or removal of map display settings. `recon_map:list()` returns a string listing configured patterns. #### Response Example ```erlang ok map definitions and limits: large_map: #Fun<...> -> all user_state: [{type,user}] -> [id,name] ``` ``` -------------------------------- ### Add Recon as a Dependency with rebar3 Source: https://github.com/ferd/recon/blob/master/src_doc/overview.md To include Recon in your project using rebar3, add it to the dependencies list in your rebar.config file. ```erlang {deps, [recon]}. ``` -------------------------------- ### Find Top N Network Ports by Attribute Source: https://context7.com/ferd/recon/llms.txt Returns the top N Inet ports by traffic statistics (e.g., bytes received, bytes sent). Useful for identifying high-traffic network connections. ```erlang %% Find top 5 ports by bytes received 1> recon:inet_count(recv_oct, 5). [{#Port<0.1234>,567890,[{recv_oct,567890}]}, {#Port<0.1235>,345678,[{recv_oct,345678}]} ] %% Find top 5 ports by bytes sent 2> recon:inet_count(send_oct, 5). %% Find top 5 ports by total octets (both directions) 3> recon:inet_count(oct, 5). %% Find top 5 ports by packet count 4> recon:inet_count(cnt, 5). ``` -------------------------------- ### Include Recon in Erlang Releases Source: https://github.com/ferd/recon/blob/master/src_doc/overview.md When using Erlang releases, ensure Recon is added to the list of applications bundled within your release configuration. ```erlang {relx, [ {release, {myrel, "0.1.0"}, [myapp, recon, % <-- here sasl] }, ... ]}." ``` -------------------------------- ### Execute Fun on Remote Nodes with recon:rpc/1,2,3 Source: https://context7.com/ferd/recon/llms.txt Executes a function on one or more remote nodes. Supports shell-defined anonymous functions and can include a timeout for the execution. ```erlang %% Run on all connected nodes including self 1> recon:rpc(fun() -> node() end). {[node1@host, node2@host, node3@host], []} ``` ```erlang %% Run on specific nodes 2> recon:rpc([node1@host, node2@host], fun() -> erlang:memory(total) end). {[12345678, 23456789], []} ``` ```erlang %% Run with timeout 3> recon:rpc(nodes(), fun() -> expensive_operation() end, 30000). ```