{"id":20038003,"url":"https://github.com/perfectlysoft/perfect-sysinfo","last_synced_at":"2025-05-05T06:31:58.600Z","repository":{"id":63920184,"uuid":"90308296","full_name":"PerfectlySoft/Perfect-SysInfo","owner":"PerfectlySoft","description":"This project provides a Swift library to monitor system performance in essential metrics.","archived":false,"fork":false,"pushed_at":"2018-02-09T17:37:14.000Z","size":35,"stargazers_count":23,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-15T08:01:47.002Z","etag":null,"topics":["cpu-monitoring","memory-monitor","network-traffic","perfect","performance-metrics","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PerfectlySoft.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":"2017-05-04T20:49:55.000Z","updated_at":"2023-08-18T03:13:23.000Z","dependencies_parsed_at":"2022-11-29T10:45:11.813Z","dependency_job_id":null,"html_url":"https://github.com/PerfectlySoft/Perfect-SysInfo","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SysInfo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SysInfo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SysInfo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PerfectlySoft%2FPerfect-SysInfo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PerfectlySoft","download_url":"https://codeload.github.com/PerfectlySoft/Perfect-SysInfo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224429246,"owners_count":17309674,"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":["cpu-monitoring","memory-monitor","network-traffic","perfect","performance-metrics","swift"],"created_at":"2024-11-13T10:24:37.195Z","updated_at":"2024-11-13T10:24:37.901Z","avatar_url":"https://github.com/PerfectlySoft.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Perfect SysInfo [简体中文](README.zh_CN.md)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"http://perfect.org/get-involved.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.org/assets/github/perfect_github_2_0_0.jpg\" alt=\"Get Involved with Perfect!\" width=\"854\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/PerfectlySoft/Perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_1_Star.jpg\" alt=\"Star Perfect On Github\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://stackoverflow.com/questions/tagged/perfect\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/perfect_gh_button_2_SO.jpg\" alt=\"Stack Overflow\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"https://twitter.com/perfectlysoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_3_twit.jpg\" alt=\"Follow Perfect on Twitter\" /\u003e\n    \u003c/a\u003e  \n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://www.perfect.org/github/Perfect_GH_button_4_slack.jpg\" alt=\"Join the Perfect Slack\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Swift-4.0-orange.svg?style=flat\" alt=\"Swift 4.0\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://developer.apple.com/swift/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Platforms-OS%20X%20%7C%20Linux%20-lightgray.svg?style=flat\" alt=\"Platforms OS X | Linux\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.org/licensing.html\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/License-Apache-lightgrey.svg?style=flat\" alt=\"License Apache\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://twitter.com/PerfectlySoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/Twitter-@PerfectlySoft-blue.svg?style=flat\" alt=\"PerfectlySoft Twitter\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"http://perfect.ly\" target=\"_blank\"\u003e\n        \u003cimg src=\"http://perfect.ly/badge.svg\" alt=\"Slack Status\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nThis project provides a Swift library to monitor system performance.\n\nThis package builds with Swift Package Manager and is part of the [Perfect](https://github.com/PerfectlySoft/Perfect) project but can also be used as an independent module.\n\nEnsure you have installed and activated the latest Swift 4.0 tool chain.\n\n## Quick Start\n\nAdd Perfect SysInfo library to your Package.swift:\n\n``` swift\n\n.package(url: \"https://github.com/PerfectlySoft/Perfect-SysInfo.git\", from: \"3.0.0\")\n\n/// target section\n.target(\n  // name: \"your app's name\",\n  dependencies: [\"PerfectSysInfo\"]),\n```\n\nAdd library header to your source code:\n\n``` swift\n\nimport PerfectSysInfo\n\n```\n\nNow SysInfo class is available to call.\n\n### CPU Usage\n\nCall static variable `SysInfo.CPU` will return a dictionary `[String: [String: Int]]` of all CPU usage, for example:\n\n``` swift\n\nprint(SysInfo.CPU)\n\n//here is a typical return of single CPU (from Linux): \n\n[\n  \"cpu0\":\n    [\"nice\": 1201, \"system\": 3598, \"user\": 8432, \"idle\": 8657606],\n  \"cpu\":\n    [\"nice\": 1201, \"system\": 3598, \"user\": 8432, \"idle\": 8657606]\n]\n\n// and the following is another example with 8 cores (from Mac):\n[\n  \"cpu3\":\n    [\"user\": 18095, \"idle\": 9708265, \"nice\": 0, \"system\": 16177],\n  \"cpu5\":\n    [\"user\": 18032, \"idle\": 9708329, \"nice\": 0, \"system\": 16079],\n  \"cpu7\":\n    [\"user\": 18186, \"idle\": 9707892, \"nice\": 0, \"system\": 16285],\n  \"cpu\":\n    [\"user\": 344301, \"idle\": 9201762, \"nice\": 0, \"system\": 196763],\n  \"cpu0\":\n    [\"user\": 730263, \"idle\": 8387000, \"nice\": 0, \"system\": 626684],\n  \"cpu2\":\n    [\"user\": 648287, \"idle\": 8799969, \"nice\": 0, \"system\": 294749],\n  \"cpu1\":\n    [\"user\": 17708, \"idle\": 9708996, \"nice\": 0, \"system\": 15950],\n  \"cpu4\":\n    [\"user\": 647701, \"idle\": 8800643, \"nice\": 0, \"system\": 294544],\n  \"cpu6\": [\"user\": 656136, \"idle\": 8793002, \"nice\": 0, \"system\": 293640]\n]\n\n```\n\nThe record is a structure of `N+1` entries, where `N` is the number of CPU and `1` is the summary, so the each record will be tagged with \"cpu0\" ... \"cpuN-1\" and the tag \"cpu\" represents the average of overall. Each entries will contain `idle`, `user`, `system` and `nice` to represent the cpu usage time. In a common sense, `idle` shall be as large as possible to indicate the CPU is not busy.\n\n### Memory Usage\n\nCall static property `SysInfo.Memory` will return a dictionary `[String: Int]` with memory metrics in ** MB **:\n\n``` swift\n\nprint(SysInfo.Memory)\n\n```\n\n** Note ** Since system information is subject to operating system type, so please use directive `#if os(Linux) #else #endif` determine OS type before reading system metrics; The definition of each counter is out of the scope of this document, please see OS manual for detail.\n\nTypical Linux memory looks like this ( 1G total memory with about 599MB available):\n\n``` swift\n[\n  \"Inactive\": 283, \"MemTotal\": 992, \"CmaFree\": 0,\n  \"VmallocTotal\": 33554431, \"CmaTotal\": 0, \"Mapped\": 74,\n  \"SUnreclaim\": 14, \"Writeback\": 0, \"Active(anon)\": 98,\n  \"Shmem\": 26, \"PageTables\": 7, \"VmallocUsed\": 0,\n  \"MemFree\": 98, \"Inactive(file)\": 179, \"SwapCached\": 0,\n  \"HugePages_Total\": 0, \"Inactive(anon)\": 104, \"HugePages_Rsvd\": 0,\n  \"Buffers\": 21, \"SReclaimable\": 39, \"Cached\": 613,\n  \"Mlocked\": 3, \"SwapTotal\": 1021, \"NFS_Unstable\": 0,\n  \"CommitLimit\": 1518, \"Hugepagesize\": 2, \"SwapFree\": 1016,\n  \"WritebackTmp\": 0, \"Committed_AS\": 1410, \"AnonHugePages\": 130,\n  \"DirectMap2M\": 966, \"Unevictable\": 3, \"HugePages_Surp\": 0,\n  \"Dirty\": 3, \"HugePages_Free\": 0, \"MemAvailable\": 599,\n  \"Active(file)\": 426, \"Slab\": 54, \"Active\": 525,\n  \"KernelStack\": 2, \"VmallocChunk\": 0, \"AnonPages\": 177,\n  \"Bounce\": 0, \"HardwareCorrupted\": 0, \"DirectMap4k\": 57\n]\n```\n\nAnd here is a typical mac OS X memory summary, which indicates that there is about 4.5GB free memory:\n\n``` swift\n[\n  \"hits\": 0, \"faults\": 3154324, \"cow\": 31476,\n  \"wired\": 3576, \"reactivations\": 366, \"zero_filled\": 2296248,\n  \"pageins\": 13983, \"lookups\": 1021, \"pageouts\": 0,\n  \"active\": 6967, \"free\": 4455, \"inactive\": 1008\n]\n\n```\n\n### Network Traffic\n\nCall static property `SysInfo.Net` will return total traffic summary from all interfaces as a dictionary `[String: [String: Int]]` where the key represents the network interface name, and the value is a detailed dictionary with two key-value pairs - `i` stands for receiving and `o` for transmitting, both in KB:\n\n``` swift\n\nif let net = SysInfo.Net {\n  print(net)\n}\n\n```\n\nIf success, it will print something like these mac  / linux outputs:\n\n``` swift\n// typical mac os x network summary, where the only physical network\n// adapter \"en0\" has 1MB incoming data totally.\n\n[\n\t\"p2p0\": [\"o\": 0, \"i\": 0], \n\t\"stf0\": [\"o\": 0, \"i\": 0], \n\t\"vboxnet0\": [\"o\": 0, \"i\": 1], \n\t\"gif0\": [\"o\": 0, \"i\": 0], \n\t\"lo0\": [\"o\": 0, \"i\": 887], \n\t\"bridge0\": [\"o\": 0, \"i\": 0], \n\t\"utun0\": [\"o\": 0, \"i\": 0], \n\t\"awdl0\": [\"o\": 0, \"i\": 318], \n\t\"en1\": [\"o\": 0, \"i\": 0], \n\t\"en0\": [\"o\": 0, \"i\": 1063], \n\t\"en2\": [\"o\": 0, \"i\": 0]\n]\n\n// typical linux network summary, where the only physical network\n// adapter \"enp0s3\" has received 0.6MB data and sent out 506KB in the same time.\n\n[\n\t\"virbr0\": [\"o\": 0, \"i\": 0], \n\t\"enp0s8\": [\"o\": 506, \"i\": 614], \n\t\"virbr0-nic\": [\"o\": 0, \"i\": 0], \n\t\"lo\": [\"o\": 1804, \"i\": 1804], \n\t\"enp0s3\": [\"o\": 158, \"i\": 7594]\n]\n```\n\n### Disk IO\n\nCall static method `SysInfo.Disk` may inspect disk i/o activity statistics in real time. It will return a `[String:[String: UInt64]]` dictionary with metrics as sample below. For more information of these counters, please refer to the operating system manual.\n\n#### Linux Release Notes\n\n``` swift\nprint(SysInfo.Disk)\n\n// here is a sample output from Linux:\n[\n  \"sda\":\n    [\n      \"io_ms\": 7516, \"reads_merged\": 17, \"reads_completed\": 14993,\n      \"writing_ms\": 9772, \"io_in_progress\": 0, \"writes_completed\": 4921,\n      \"sectors_read\": 1292762, \"reading_ms\": 11952, \"writes_merged\": 5738,\n      \"sectors_written\": 969480, \"weighte_io_ms\": 21636\n    ],\n  \"sda2\":\n    [\n      \"io_ms\": 0, \"reads_merged\": 0, \"reads_completed\": 4,\n      \"writing_ms\": 0, \"io_in_progress\": 0, \"writes_completed\": 0,\n      \"sectors_read\": 8, \"reading_ms\": 0, \"writes_merged\": 0,\n      \"sectors_written\": 0, \"weighte_io_ms\": 0\n    ],\n  \"sda1\":\n    [\n      \"io_ms\": 7252, \"reads_merged\": 7, \"reads_completed\": 14817,\n      \"writing_ms\": 9520, \"io_in_progress\": 0, \"writes_completed\": 3971,\n      \"sectors_read\": 1281954, \"reading_ms\": 11908, \"writes_merged\": 5426,\n      \"sectors_written\": 966696, \"weighte_io_ms\": 21340\n    ]\n]\n\n```\n\n#### Mac OS X Release Notes\n\nPlease note that if using `SysInfo.Disk` in a loop, then an `autoreleasepool{ }` is strongly recommend to avoid unnecessary memory caching on such objects:\n\n``` swift\n\nautoreleasepool(invoking: {\n  let io = SysInfo.Disk\n  print(io)\n})\n\n// here is the sample output from macOS:\n[\n  \"disk0\":\n    [\n      \"operations_read\": 501077, \"latency_time_read\": 0,\n      \"bytes_written\": 21265645056, \"bytes_read\": 25022815232,\n      \"operations_written\": 360598, \"latency_time_written\": 0\n    ]\n]\n```\n\n## Further Information\nFor more information on the Perfect project, please visit [perfect.org](http://perfect.org).\n\n\n## Now WeChat Subscription is Available (Chinese)\n\u003cp align=center\u003e\u003cimg src=\"https://raw.githubusercontent.com/PerfectExamples/Perfect-Cloudinary-ImageUploader-Demo/master/qr.png\"\u003e\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-sysinfo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fperfectlysoft%2Fperfect-sysinfo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fperfectlysoft%2Fperfect-sysinfo/lists"}