diff --git a/API.md b/API.md index 2067610..2707d04 100644 --- a/API.md +++ b/API.md @@ -2,6 +2,86 @@ KasmVNC has an API to make changes or get data via simple HTTPS API calls. All API calls require owner credentials. +### Bottleneck stats +Returns CPU and Network bottleneck statistics. These metrics attempt to identify where performance issues may be occurring. The network and CPU stats each have two numbers. The first number is the current snapshot in time value and the second is averaged over time. Values range from 0 to 10 with 10 representing no constraints. When the frame rate drops, the bottleneck stats should help identify if the bottleneck is server side CPU or the network. The following is an example of what is returned + +/api/get_bottleneck_stats + +Example Returned JSON +```json +{ + "myusername": { + "71.61.88.0_1627638421.160028::websocket": [ 8.2, 9.6, 10.0, 9.4 ], + "71.61.88.0_1627638469.484285::websocket": [ 8.2, 9.6, 2.6, 8.5 ] + } +} +``` + +Because KasmVNC supports multiple users and each user can have multiple connections, the returned JSON contains a dict for each user, which contains an entry for each connection. Each connection has an array with the following contents in order: + +CPU, CPU Average, Network, Network Average + +In the above example, the second connection for shows that the network is not able to keep up with the frames being sent from the server. It also indicates some CPU constraints, meaning that the CPU is mostly keeping up with the changes to the screen but not at 100%. + +### Frame Stats +The bottleneck stats are a quick way to determine whether the network or the server-side CPU is causing a bottleneck, however, it does not provide enough fidelity to make coding decisions. The frame stats API call returns timings for all major processes with respect to processing a single frame. + +/api/get_frame_stats + + client - Which client connection to return frame stats for + auto - Return frame stats for the first connection for the owner + all - Return frame stats for ALL client connections + none - Return no client side statistics + 71.61.88.0_1627638421.160028::websocket - Example of providing a specific connection + +Example: /api/get_frame_stats?client=auto + +Example Returned JSON +```json +{ + "frame" : { + "resx": 1680, + "resy": 971, + "changed": 60, + "server_time": 45 + }, + "server_side" : [ + { "process_name": "Analysis", "time": 2 }, + { "process_name": "Screenshot", "time": 3 }, + { "process_name": "Encoding_total", "time": 25, "videoscaling": 17 }, + { "process_name": "TightJPEGEncoder", "time": 3, "count": 1, "area": 786432 }, + { "process_name": "TightWEBPEncoder", "time": 0, "count": 0, "area": 0 } + ], + "client_side" : [ + { + "client": "71.61.88.0_1627638469.484285::websocket", + "client_time": 1, + "ping": 54, + "processes" : [ + { "process_name": "scanRenderQ", "time": 0 } + ] + } + ] +} +``` + +| Field | Description | +|-----------------------------|-----------------------------------------------------------| +| frame.resx | Width of frame | +| frame.resy | Height of frame | +| frame.changed | Percent of the frame that had changes | +| frame.server_time | Wall clock time total to process the frame | +| server_side.[].process_name | Name of the process | +| server_side.[].time. | CPU time elapsed total for the process | +| server_side.[].count. | Total times the process executed | +| server_side.[].area. | For encoding processes, the total area of rects processed | +| server_side.[].videoscaling | For encoding_total entry, scaling time in video mode. | +| client_side.client_time. | Total time for client to process frame | +| client_side.ping. | Round trip time to client, divide by two | + +Since encoding in jpeg and webp is multi-threaded, the time specified in the process entries for JPEG and WEBP encoding is CPU time not wall clock time. The "Encoding_total" process logs the wall clock time for all encoding and also includes videoscaling time which only applies when in "video mode". Video mode scales image down in size, encodes, sends to client, and the client scales it back up. Video mode keeps aspect ratio. Video mode kicks in when screen change reaches a threshold for a period of time defined. + + ### Get Screenshot Get a screenshot of the current session. You can pass a height and width that do not match the current aspect ratio, it will return the requested width with the height adjusted to keep the aspect ratio.