{"id":13413525,"url":"https://github.com/go-playground/stats","last_synced_at":"2025-05-05T17:31:50.235Z","repository":{"id":57486059,"uuid":"42474825","full_name":"go-playground/stats","owner":"go-playground","description":":chart_with_upwards_trend: Monitors Go MemStats + System stats such as Memory, Swap and CPU and sends via UDP anywhere you want for logging etc...","archived":false,"fork":false,"pushed_at":"2016-09-07T12:51:16.000Z","size":172,"stargazers_count":170,"open_issues_count":1,"forks_count":19,"subscribers_count":7,"default_branch":"v1","last_synced_at":"2024-10-24T20:31:03.669Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","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/go-playground.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-09-14T20:20:20.000Z","updated_at":"2024-06-18T11:38:19.000Z","dependencies_parsed_at":"2022-09-13T08:10:26.587Z","dependency_job_id":null,"html_url":"https://github.com/go-playground/stats","commit_stats":null,"previous_names":["joeybloggs/stats"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-playground%2Fstats","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-playground%2Fstats/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-playground%2Fstats/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/go-playground%2Fstats/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/go-playground","download_url":"https://codeload.github.com/go-playground/stats/tar.gz/refs/heads/v1","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252542260,"owners_count":21764934,"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-07-30T20:01:42.392Z","updated_at":"2025-05-05T17:31:49.799Z","avatar_url":"https://github.com/go-playground.png","language":"Go","readme":"Package stats\n=============\n\n![Project status](https://img.shields.io/badge/version-1.0.2-green.svg)\n[![Build Status](https://semaphoreci.com/api/v1/projects/b5c5d4f1-ec31-441f-a6d2-88f4e73105df/563578/badge.svg)](https://semaphoreci.com/joeybloggs/stats)\n[![GoDoc](https://godoc.org/gopkg.in/go-playground/stats.v1?status.svg)](https://godoc.org/gopkg.in/go-playground/stats.v1)\n\nPackage stats allows for gathering of statistics regarding your Go application and system it is running on and\nsent them via UDP to a server where you can do whatever you wish to the stats; display, store in database or\nsend off to a logging service.\n\n###### We currently gather the following Go related information:\n\n* # of Garbabage collects\n* Last Garbage Collection\n* Last Garbage Collection Pause Duration\n* Memory Allocated\n* Memory Heap Allocated\n* Memory Heap System Allocated\n* Go version\n* Number of goroutines\n* HTTP request logging; when implemented via middleware\n\n###### And the following System Information:\n\n* Host Information; hostname, OS....\n* CPU Information; type, model, # of cores...\n* Total CPU Timings\n* Per Core CPU Timings\n* Memory + Swap Information\n\nInstallation\n------------\n\nUse go get.\n\n\tgo get gopkg.in/go-playground/stats.v1\n\nor to update\n\n\tgo get -u gopkg.in/go-playground/stats.v1\n\nThen import the validator package into your own code.\n\n\timport \"gopkg.in/go-playground/stats.v1\"\n\n#### Example\nServer\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"gopkg.in/go-playground/stats.v1\"\n)\n\nfunc main() {\n\n\tconfig := \u0026stats.ServerConfig{\n\t\tDomain: \"\",\n\t\tPort:   3008,\n\t\tDebug:  false,\n\t}\n\n\tserver, err := stats.NewServer(config)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfor stat := range server.Run() {\n\n\t\t// calculate CPU times\n\t\t// totalCPUTimes := stat.CalculateTotalCPUTimes()\n\t\t// perCoreCPUTimes := stat.CalculateCPUTimes()\n\n\t\t// Do whatever you want with the data\n\t\t// * Save to database\n\t\t// * Stream elsewhere\n\t\t// * Print to console\n\t\t//\n\n\t\tfmt.Println(stat)\n\t}\n}\n```\n\nClient\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net/http\"\n\t\"runtime\"\n\n\t\"gopkg.in/go-playground/stats.v1\"\n)\n\nvar statsClient *stats.ClientStats\n\nfunc main() {\n\n\tserverConfig := \u0026stats.ServerConfig{\n\t\tDomain: \"remoteserver\",\n\t\tPort:   3008,\n\t\tDebug:  false,\n\t}\n\n\tclientConfig := \u0026stats.ClientConfig{\n\t\tDomain:           \"\",\n\t\tPort:             3009,\n\t\tPollInterval:     1000,\n\t\tDebug:            false,\n\t\tLogHostInfo:      true,\n\t\tLogCPUInfo:       true,\n\t\tLogTotalCPUTimes: true,\n\t\tLogPerCPUTimes:   true,\n\t\tLogMemory:        true,\n\t\tLogGoMemory:      true,\n\t}\n\n\tclient, err := stats.NewClient(clientConfig, serverConfig)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tgo client.Run()\n\n\t// if you want to capture HTTP requests in a middleware you'll have\n\t// to have access to the client.\n\t// see below for middleware example\n\tstatsClient = client\n}\n\n// LoggingRecoveryHandler ...\n//\n//\n// Middleware example for capturing HTTP Request info\n// NOTE: this is standard go middlware, but could be adapted to other types/styles easily\n//\nfunc LoggingRecoveryHandler(next http.Handler) http.Handler {\n\n\tfn := func(w http.ResponseWriter, r *http.Request) {\n\n\t\t// log incoming request\n\t\tlogReq := statsClient.NewHTTPRequest(w, r)\n\n\t\tdefer func() {\n\t\t\tif err := recover(); err != nil {\n\t\t\t\ttrace := make([]byte, 1\u003c\u003c16)\n\t\t\t\tn := runtime.Stack(trace, true)\n\n\t\t\t\t// log failure\n\t\t\t\tlogReq.Failure(fmt.Sprintf(\"%s\\n%s\", err, trace[:n]))\n\n\t\t\t\thttp.Error(w, \"Friendly error message\", 500)\n\t\t\t\treturn\n\t\t\t}\n\t\t}()\n\n\t\tnext.ServeHTTP(logReq.Writer(), r)\n\n\t\t// log completion\n\t\tlogReq.Complete()\n\t}\n\n\treturn http.HandlerFunc(fn)\n}\n```\n\nLicense\n------\n- [MIT License](https://github.com/go-playground/stats/blob/v1/LICENSE), Copyright (c) 2015 Dean Karn\n- [BSD License](https://github.com/go-playground/stats/tree/v1/vendor/github.com/shirou/gopsutil/LICENSE)\n\t- Copyright (c) 2014, WAKAYAMA Shirou\n\t- Copyright (c) 2009 The Go Authors. All rights reserved.\n- [BSD License](https://github.com/go-playground/stats/tree/v1/vendor/github.com/shirou/w32/LICENSE), Copyright (c) 2010-2012 The w32 Authors. All rights reserved.","funding_links":[],"categories":["Microsoft Office","Miscellaneous","Go","其他杂项","Uncategorized","\u003cspan id=\"其他-miscellaneous\"\u003e其他 Miscellaneous\u003c/span\u003e","杂项","其他"],"sub_categories":["Uncategorized","Strings","暂未分类","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","未分类的","交流","暂未分类这些库被放在这里是因为其他类别似乎都不适合。"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-playground%2Fstats","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgo-playground%2Fstats","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgo-playground%2Fstats/lists"}