{"id":21942083,"url":"https://github.com/richardzcode/metrics","last_synced_at":"2025-03-22T15:25:18.785Z","repository":{"id":3543806,"uuid":"4603982","full_name":"richardzcode/metrics","owner":"richardzcode","description":"Capture Java application metrics","archived":false,"fork":false,"pushed_at":"2017-12-15T18:08:03.000Z","size":1180,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-13T22:05:46.648Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","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/richardzcode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-06-09T01:01:15.000Z","updated_at":"2017-12-15T18:08:04.000Z","dependencies_parsed_at":"2022-09-06T04:40:23.915Z","dependency_job_id":null,"html_url":"https://github.com/richardzcode/metrics","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/richardzcode%2Fmetrics","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardzcode%2Fmetrics/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardzcode%2Fmetrics/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/richardzcode%2Fmetrics/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/richardzcode","download_url":"https://codeload.github.com/richardzcode/metrics/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244976078,"owners_count":20541406,"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-11-29T03:16:25.568Z","updated_at":"2025-03-22T15:25:18.765Z","avatar_url":"https://github.com/richardzcode.png","language":"Java","readme":"metrics\n=======\n\nCapture Java application metrics\n\nInspired by [Metrics](http://metrics.codahale.com/) written by Coda Hale. But don't want to get too complicated. I want something lightweight but just enough.\n\nMinimum overhead on data collecting. Use thread to emit event when time unit reached.\n\nDepend on listener implementation, data can be send to database, in-memory, another service, or wherever useful.\n\n## Version\n0.1.2\n\n## Classes\n\n### Tracker\nStart point. Singleton class. Default time unit is 1 minute.\n    Tracker.count(key);\n    Tracker.incr(key); Tracker.decr();\n    Tracker.gauge(key, value);\n    Tracker.log(key, log);\n\n    Tracker.peek(); // Emit onTimeUnit with current data.\n\n### Aspect\n\nBase class\n\nIf aspect is set to accumulative then values do not reset on each time unit. Default is non-accumulative.\n\n#### Counter\nCount: Counts number per time unit.\n\nIncr/Decr: Keep counts over time. Does not reset number if the counter is used with incr/decr.\n\n#### Gauger\nCollect dataset per time unit. Calculates count/total/main/mean/90 percentile/95 percentile/99 percentile/max when emitting event.\n\n#### Logger\nKeep special logs per one time unit.\n\n### Listener\nImplements IListener interface. The method onTimeUnit will be triggered on every time unit with collected data in JSON string.\n\nApplication should implement IListener and add to Tracker to deal with data.\n\n    public interface IListener {\n        public void onTimeUnit(String data);\n    }\n\n#### ConsoleListener\nListen to data and writes data to console.\n\n#### HttpListener\nListen to data and POST to another service.\n\n## Usage\n\n### Initialize\n    import com.rz.metrics.Tracker;\n    import com.rz.metrics.listeners.ConsoleListener;\n    \n    Tracker.setTimeUnit(1000L); // 1 second\n    Tracker.addListener(new ConsoleListener());\n\n### Tracking\n#### Count\n    Tracker.count(\"traffic:url1\");\n\nIf first time calling a counter, which creates the counter, is by incr/decr then the counter is set to accumulative automatically.\n\n    Tracker.incr(\"onlineUser\"); // Login\n    Tracker.decr(\"onlineUser\"); // Logout or expire\n\n#### Gauge\n    long latency = nnn;\n    Tracker.gauge(\"latency:url1\", latency);\n\n#### Log\n    Tracker.log(\"malicious\", \"IP xxx.xxx.xxx.xxx\");\n\n### Listening\n    /**\n     * @param data\n     *         {\n     *             aspect: \"counter\"|\"gauger\"|\"logger\"\n     *             , key: \"...\"\n     *             , ts: \"nnn\" // Timestamp\n     *             , timeUnit: \"60000\"\n     *             , data: {...}\n     *         }\n     */\n    public void onTimeUnit(String data) {\n        // Do whatever.\n    }\n\n## Run example\n    java -jar metrics-0.1.0.jar\n\n### Node.js client\n    cd nodeClient\n    node app.js\n\nOpen browser, goto http://localhost:3001/index.html\n![nodeClient](https://github.com/richardzcode/metrics/raw/master/screenshots/nodeClient.png)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardzcode%2Fmetrics","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frichardzcode%2Fmetrics","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frichardzcode%2Fmetrics/lists"}