{"id":13643508,"url":"https://github.com/git-hulk/tcpkit","last_synced_at":"2025-04-05T20:04:18.690Z","repository":{"id":45143406,"uuid":"46619168","full_name":"git-hulk/tcpkit","owner":"git-hulk","description":"the tcpkit was designed to make network packets programable with Lua script","archived":false,"fork":false,"pushed_at":"2021-02-22T09:00:56.000Z","size":2568,"stargazers_count":464,"open_issues_count":2,"forks_count":60,"subscribers_count":25,"default_branch":"master","last_synced_at":"2025-03-29T19:01:46.396Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/git-hulk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-21T14:44:15.000Z","updated_at":"2025-03-05T10:26:10.000Z","dependencies_parsed_at":"2022-07-13T16:50:28.280Z","dependency_job_id":null,"html_url":"https://github.com/git-hulk/tcpkit","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Ftcpkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Ftcpkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Ftcpkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/git-hulk%2Ftcpkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/git-hulk","download_url":"https://codeload.github.com/git-hulk/tcpkit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393566,"owners_count":20931812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:01:48.582Z","updated_at":"2025-04-05T20:04:18.656Z","avatar_url":"https://github.com/git-hulk.png","language":"C","funding_links":[],"categories":["C","C (286)"],"sub_categories":[],"readme":"# tcpkit [![Build Status](https://travis-ci.com/git-hulk/tcpkit.svg?branch=master)](https://travis-ci.com/git-hulk/tcpkit)\n\nThe tcpkit was designed to analyze network packets with lua script, can also be used to observe the request latency\nof the service with simple protocol, like `redis`/`memcached`.\n\n## Install\n\n```\n$ git clone https://github.com/git-hulk/tcpkit.git tcpkit\n$ cd tcpkit\n$ sudo make \u0026\u0026 make install\n```\n\n## Usage\n\n```shell\nthe tcpkit was designed to make network packets programable with LUA by @git-hulk\n   -h, Print the tcpkit version strings, print a usage message, and exit\n   -i interface, Listen on network card interface\n   -r file, Read packets from file (which was created with the -w option or by other tools that write pcap)\n   -A Print each packet (minus its link level header) in ASCII.  Handy for capturing web pages\n   -B buffer_size, Set the operating system capture buffer size to buffer_size, in units of KiB (1024 bytes)\n   -s snaplen, Snarf snaplen bytes of data from each packet rather than the default of 1500 bytes\n   -S file, Push packets to lua state if the script was specified\n   -t threshold, Print the request lantecy which slower than the threshold, in units of Millisecond\n   -w file, Write the raw packets to file\n   -p protocol, Parse the packet if the protocol was specified (supports: redis, memcached, http, raw)\n   -P stats port, Listen port to fetch the latency stats, default is 33333\n\n\nFor example:\n\n   `tcpkit -i eth0 tcp port 6379 -p redis` was used to monitor the redis reqeust latency\n\n   `tcpkit -i eth0 tcp port 6379 -p redis -w 6379.pcap` would also dump the packets to `6379.pcap`\n\n   `tcpkit -i eth0 tcp port 6379 -p redis -t 10` would only print the request latency slower than 10ms\n```\n\n## How To Observe The Latency Of Redis/Memcached \n\n\n```shell\n$ tcpkit -i eth0 tcp port 6379 -p redis\n```  \n\ntcpkit would listen on NIC `eth0` and caputure the tcp port `6379`, then parse network packets with Redis protocol. \nThe output was like below:\n\n```\n2020-03-08 19:23:06.253384 127.0.0.1:51137 =\u003e 127.0.0.1:6379 | 0.615 ms | COMMAND\n2020-03-08 19:23:06.258761 127.0.0.1:51137 =\u003e 127.0.0.1:6379 | 0.059 ms | get a\n```\n\nUse the option `-t` would only show the request which the request latency was slower than threshold(in units of millisecond).\n\n\n## How to Use Lua Script\n\n```\n$ tcpkit -i eth0 tcp port 6379 -p redis -S scripts/example.lua\n```\n\nthe callback function `function process(packet)` in `scripts/example.lua` would be triggered if new packets reached.\n\n### Predefine Scripts\n\n1. [exmaple.lua](https://github.com/git-hulk/tcpkit/blob/master/scripts/example.lua) - example for user defined script\n2. [dns.lua](https://github.com/git-hulk/tcpkit/blob/master/scripts/dns.lua) - print the dns latency\n3. [tcp-connnect.lua](https://github.com/git-hulk/tcpkit/blob/master/scripts/tcp-connect.lua) - print connection with syn packet retransmit\n\n## Request Latency\n\nthe stats port listen on `33333` by default, use the `-P` to change the listen port.\n\n```json\n➜  ~ telnet 127.0.0.1 33333\nTrying 127.0.0.1...\nConnected to localhost.\nEscape character is '^]'.\n\n{\n\t\"127.0.0.1:6379\":\t{\n\t\t\"requests\":\t1700,\n\t\t\"request_bytes\":\t184100,\n\t\t\"responses\":\t1700,\n\t\t\"response_bytes\":\t1413764,\n\t\t\"latency\":\t[{\n\t\t\t\t\"\u003c0.1ms\":\t326\n\t\t\t}, {\n\t\t\t\t\"0.1ms~0.2ms\":\t371\n\t\t\t}, {\n\t\t\t\t\"0.2~0.5ms\":\t589\n\t\t\t}, {\n\t\t\t\t\"0.5ms~1ms\":\t291\n\t\t\t}, {\n\t\t\t\t\"1ms~5ms\":\t123\n\t\t\t}]\n\t}\n}\n```\n\n## License\n\ntcpkit is under the MIT license. See the LICENSE file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-hulk%2Ftcpkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgit-hulk%2Ftcpkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgit-hulk%2Ftcpkit/lists"}