{"id":13509831,"url":"https://github.com/gihnius/monconn","last_synced_at":"2025-03-30T14:31:49.056Z","repository":{"id":146433735,"uuid":"152878665","full_name":"gihnius/monconn","owner":"gihnius","description":"A TCP connection monitoring tool written in Go.","archived":false,"fork":false,"pushed_at":"2018-11-08T11:39:01.000Z","size":91,"stargazers_count":75,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-01T10:35:01.231Z","etag":null,"topics":["connection","go","monitor","service","tcp","traffic"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gihnius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-10-13T14:12:42.000Z","updated_at":"2024-08-04T20:40:54.000Z","dependencies_parsed_at":"2024-01-13T19:24:42.236Z","dependency_job_id":"95bd07dd-0945-4fed-b0f2-6f33b6098a06","html_url":"https://github.com/gihnius/monconn","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gihnius%2Fmonconn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gihnius%2Fmonconn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gihnius%2Fmonconn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gihnius%2Fmonconn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gihnius","download_url":"https://codeload.github.com/gihnius/monconn/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246332231,"owners_count":20760444,"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":["connection","go","monitor","service","tcp","traffic"],"created_at":"2024-08-01T02:01:13.933Z","updated_at":"2025-03-30T14:31:47.194Z","avatar_url":"https://github.com/gihnius.png","language":"Go","funding_links":[],"categories":["Go","go"],"sub_categories":[],"readme":"# monconn\n\nA TCP connection monitoring tool written in Go.\n\n## About\n\nThis is a tool(a library and a command line) for monitoring and debugging network services.\n\n~~I built this for the purpose of facilitating debugging and monitoring the network connections of IoT devices. At this stage, it is just an experimental tool.~~\n\n~~Note: For each tcp connection, an additional goroutine is used for monitoring, and uses a MonConn struct to store the monitored info, which takes up a bit more memory. For 5000 long connections, it takes up about 80~100MB of memory.~~\n\n~~So it's not recommended to use it in high performance production environment.~~\n\n**features**\n\n- reject remote ip by managing an ip blacklist\n- limit ip connections\n- record upload/download traffics of all connections\n- check idle tcp connection\n- show connecting ip connections count\n- show read and write bytes(hex array) on a connection\n- gracefull stop a tcp listener\n\n## Usage\n\n### Install\n\nlibrary:\n\n`go get -u -v github.com/gihnius/monconn`\n\ncommand line:\n\n`go get -u -v github.com/gihnius/monconn/cli/monconn`\n\nthen run: `monconn -h`\n\n### Configuration\n\n#### for library\n\n``` go\nimport \"github.com/gihnius/monconn\"\n\n// --------------- global setup\nmonconn.Debug = true // enable debug log\nmonconn.DebugFunc = func(format string, v ...interface{}) {\n    // custom log function\n}\n\n// set net.Conn buffer size, default 4k\nmonconn.ReadBufSize = 4 \u003c\u003c 10\nmonconn.WriteBufSize = 4 \u003c\u003c 10\n\n// set how many concurrency clients(ip) can connect to a service\n// default 64\nmonconn.MaxIPLimit = 1000\n\n// --------------- service setup\n// set net.Conn read write timeout\nservice.ReadTimeout = 600\nservice.WriteTimeout = 600\n// close wait timeout\nservice.WaitTimeout = 60\n// max idle check in seconds\nservice.MaxIdle = 900\n// connections count to a service, default 0, no limit\nservice.ConnLimit = 0 // ConnLimit changes need to restart service\n// ips count to service, default 0, no limit\nservice.IPLimit = 0\n// set tcp connection keepalive, default true\nservice.KeepAlive = true\n// Print read write bytes in hex format, default false\nservice.PrintBytes = false\n\n```\n\n#### for command line\n\nplease checkout `monconn/cli/monconn/config.yaml`.\n\nsimple usage as a port forwarder:\n\n``` shell\n# use as ssh and web frontend to monitor traffics\n$ monconn -p :22=127.0.0.1:2222 -p 0.0.0.0:80=127.0.0.1:8080\n# here 2222 and 8080 are the real ssh and web services\n\n```\n\nmore configurable options:\n\n``` yaml\n# monconn config.yaml\nservice_1: # service name\n  # service listen on\n  listen_ip: \"127.0.0.1\"\n  # monconn listen on 80\n  listen_port: 80\n  # forward requests to this backend\n  backend_ip: \"127.0.0.1\"\n  # the real web listen on 8080\n  backend_port: 8080\n  # service config\n  read_timeout: 600 # 10 minutes\n  write_timeout: 600 # 10 minutes\n  wait_timeout: 60 # 1 minute\n  max_idle: 900 # 15 minutes\n  conn_limit: 0 # zero means no limit\n  ip_limit: 0 # zero means no limit\n  keepalive: true\n  print_bytes: true\n  ip_blacklist:\n    - 1.1.1.1\n    - 2.2.2.2\n\n```\n\n### Example\n\n``` go\n// create service by given a sid: \"127.0.0.1:1234\"\n// a service is binding to a tcp listener, so normally\n// use a listen address as sid to identify a service\n// you can also choose a uniqe string as sid.\nservice := monconn.NewService(\"127.0.0.1:1234\")\n// configure service like above\n// service.ReadTimeout = ...\n// listen a tcp port\n// start the service monitor on ln\nservice.Listen(\"tcp\", \"127.0.0.1:1234\")\n\n// accept connection and monitor the connection\nconn, err := service.AcquireConn()\nif err != nil {\n    // handle err\n} else {\n    go HandleConn(conn)\n}\n\n// when everything done, usually before program exit,\n// call service.Stop() to stop the listener as well as service\nservice.Close()\n// or call Shutdown() to Stop all services if there are multiple started.\nmonconn.Shutdown()\n\n// or pls checkout the example code in examples/\n\n// checkout the API to see how to grab the monitored infomation.\n\n// ... that's all\n\n```\n\n## API\n\n### monconn package api\n\n- NewService(sid) to create a service\n- GetService(sid) get service by sid\n- DelService(sid) delete a service\n- Shutdown() Stop all services\n\n### Service instance method\n\n- RejectIP(ip) add ip to blacklist\n- ReleaseIP(ip) remove ip from blacklist\n- Listen() start monitor the listener\n- AcquireConn() return monitored new connection\n- Close() stop service\n- WrapMonConn()\n- EliminateBytes(r, w) see godoc\n- ReadWriteBytes() return how many bytes read or write in a service\n- IPs() service's connecting ip\n- Uptime() service's uptime, in seconds\n- Sid() service's sid getter\n- AccessAt() latest client connect time\n- BootAt() service start from time\n- ConnCount() how many realtime connections\n- IPCount() realtime ips\n- Stats() json format stats\n- Log()\n\n### MonConn instance method\n\n- Idle() tell if client read idle\n- Stats()\n- Log()\n\nsee [godoc](https://godoc.org/github.com/gihnius/monconn)\n\n## TODO\n\n- a session wrapper\n- improve logger\n- Implement ReadFrom and WriteTo methods\n\n## Status\n\nIn development (alpha).\n\n## License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgihnius%2Fmonconn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgihnius%2Fmonconn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgihnius%2Fmonconn/lists"}