├── .gitignore ├── README.md ├── Cargo.toml ├── src └── main.rs └── Cargo.lock /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## memoryChecker-rs-mac 2 | 3 | An application to raise alert if memory usage exceeds particular threshold (for Mac OS) - written in Rust 4 | 5 | ### Goals 6 | 7 | 1. Check and raise a warning -> if memory consumption is greater than a set threshold. 8 | 2. Share the program details that is taking most of the memory. 9 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memory_checker" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | sysinfo = {version = "0.29.10", default-features = false} 10 | # notify-rust = "*" 11 | mac-notification-sys = "0.6" 12 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use mac_notification_sys::*; 2 | use sysinfo::{System, SystemExt}; 3 | 4 | fn main() { 5 | // use notify_rust::Notification; 6 | let mut sys = System::new_all(); 7 | sys.refresh_all(); 8 | let threshold = 0.50; 9 | 10 | loop { 11 | sys.refresh_all(); 12 | let total_memory: f64 = sys.total_memory() as f64; 13 | let used_memory: f64 = sys.used_memory() as f64; 14 | let used_memory_percentage = used_memory / total_memory; 15 | 16 | if used_memory_percentage > threshold { 17 | println!( 18 | "Current used memory percentage: {:?}", 19 | used_memory_percentage 20 | ); 21 | send_notification( 22 | "Exceeding Memory", 23 | Some("WARNING"), 24 | &format!( 25 | "Looks like memory has exceeded than the given threshold: {}", 26 | threshold 27 | ), 28 | Some(Notification::new().sound("Blow")), 29 | ) 30 | .unwrap(); 31 | } 32 | 33 | std::thread::sleep(System::MINIMUM_CPU_UPDATE_INTERVAL); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "bitflags" 7 | version = "1.3.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 10 | 11 | [[package]] 12 | name = "block" 13 | version = "0.1.6" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" 16 | 17 | [[package]] 18 | name = "cc" 19 | version = "1.0.83" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" 22 | dependencies = [ 23 | "libc", 24 | ] 25 | 26 | [[package]] 27 | name = "cfg-if" 28 | version = "1.0.0" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 31 | 32 | [[package]] 33 | name = "core-foundation-sys" 34 | version = "0.8.4" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 37 | 38 | [[package]] 39 | name = "deranged" 40 | version = "0.3.8" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "f2696e8a945f658fd14dc3b87242e6b80cd0f36ff04ea560fa39082368847946" 43 | 44 | [[package]] 45 | name = "dirs-next" 46 | version = "2.0.0" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" 49 | dependencies = [ 50 | "cfg-if", 51 | "dirs-sys-next", 52 | ] 53 | 54 | [[package]] 55 | name = "dirs-sys-next" 56 | version = "0.1.2" 57 | source = "registry+https://github.com/rust-lang/crates.io-index" 58 | checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" 59 | dependencies = [ 60 | "libc", 61 | "redox_users", 62 | "winapi", 63 | ] 64 | 65 | [[package]] 66 | name = "getrandom" 67 | version = "0.2.10" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" 70 | dependencies = [ 71 | "cfg-if", 72 | "libc", 73 | "wasi", 74 | ] 75 | 76 | [[package]] 77 | name = "libc" 78 | version = "0.2.148" 79 | source = "registry+https://github.com/rust-lang/crates.io-index" 80 | checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" 81 | 82 | [[package]] 83 | name = "mac-notification-sys" 84 | version = "0.6.1" 85 | source = "registry+https://github.com/rust-lang/crates.io-index" 86 | checksum = "51fca4d74ff9dbaac16a01b924bc3693fa2bba0862c2c633abc73f9a8ea21f64" 87 | dependencies = [ 88 | "cc", 89 | "dirs-next", 90 | "objc-foundation", 91 | "objc_id", 92 | "time", 93 | ] 94 | 95 | [[package]] 96 | name = "malloc_buf" 97 | version = "0.0.6" 98 | source = "registry+https://github.com/rust-lang/crates.io-index" 99 | checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" 100 | dependencies = [ 101 | "libc", 102 | ] 103 | 104 | [[package]] 105 | name = "memory_checker" 106 | version = "0.1.0" 107 | dependencies = [ 108 | "mac-notification-sys", 109 | "sysinfo", 110 | ] 111 | 112 | [[package]] 113 | name = "ntapi" 114 | version = "0.4.1" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "e8a3895c6391c39d7fe7ebc444a87eb2991b2a0bc718fdabd071eec617fc68e4" 117 | dependencies = [ 118 | "winapi", 119 | ] 120 | 121 | [[package]] 122 | name = "objc" 123 | version = "0.2.7" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" 126 | dependencies = [ 127 | "malloc_buf", 128 | ] 129 | 130 | [[package]] 131 | name = "objc-foundation" 132 | version = "0.1.1" 133 | source = "registry+https://github.com/rust-lang/crates.io-index" 134 | checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" 135 | dependencies = [ 136 | "block", 137 | "objc", 138 | "objc_id", 139 | ] 140 | 141 | [[package]] 142 | name = "objc_id" 143 | version = "0.1.1" 144 | source = "registry+https://github.com/rust-lang/crates.io-index" 145 | checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" 146 | dependencies = [ 147 | "objc", 148 | ] 149 | 150 | [[package]] 151 | name = "once_cell" 152 | version = "1.18.0" 153 | source = "registry+https://github.com/rust-lang/crates.io-index" 154 | checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" 155 | 156 | [[package]] 157 | name = "proc-macro2" 158 | version = "1.0.67" 159 | source = "registry+https://github.com/rust-lang/crates.io-index" 160 | checksum = "3d433d9f1a3e8c1263d9456598b16fec66f4acc9a74dacffd35c7bb09b3a1328" 161 | dependencies = [ 162 | "unicode-ident", 163 | ] 164 | 165 | [[package]] 166 | name = "quote" 167 | version = "1.0.33" 168 | source = "registry+https://github.com/rust-lang/crates.io-index" 169 | checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" 170 | dependencies = [ 171 | "proc-macro2", 172 | ] 173 | 174 | [[package]] 175 | name = "redox_syscall" 176 | version = "0.2.16" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" 179 | dependencies = [ 180 | "bitflags", 181 | ] 182 | 183 | [[package]] 184 | name = "redox_users" 185 | version = "0.4.3" 186 | source = "registry+https://github.com/rust-lang/crates.io-index" 187 | checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" 188 | dependencies = [ 189 | "getrandom", 190 | "redox_syscall", 191 | "thiserror", 192 | ] 193 | 194 | [[package]] 195 | name = "serde" 196 | version = "1.0.188" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" 199 | dependencies = [ 200 | "serde_derive", 201 | ] 202 | 203 | [[package]] 204 | name = "serde_derive" 205 | version = "1.0.188" 206 | source = "registry+https://github.com/rust-lang/crates.io-index" 207 | checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" 208 | dependencies = [ 209 | "proc-macro2", 210 | "quote", 211 | "syn", 212 | ] 213 | 214 | [[package]] 215 | name = "syn" 216 | version = "2.0.37" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "7303ef2c05cd654186cb250d29049a24840ca25d2747c25c0381c8d9e2f582e8" 219 | dependencies = [ 220 | "proc-macro2", 221 | "quote", 222 | "unicode-ident", 223 | ] 224 | 225 | [[package]] 226 | name = "sysinfo" 227 | version = "0.29.10" 228 | source = "registry+https://github.com/rust-lang/crates.io-index" 229 | checksum = "0a18d114d420ada3a891e6bc8e96a2023402203296a47cdd65083377dad18ba5" 230 | dependencies = [ 231 | "cfg-if", 232 | "core-foundation-sys", 233 | "libc", 234 | "ntapi", 235 | "once_cell", 236 | "winapi", 237 | ] 238 | 239 | [[package]] 240 | name = "thiserror" 241 | version = "1.0.49" 242 | source = "registry+https://github.com/rust-lang/crates.io-index" 243 | checksum = "1177e8c6d7ede7afde3585fd2513e611227efd6481bd78d2e82ba1ce16557ed4" 244 | dependencies = [ 245 | "thiserror-impl", 246 | ] 247 | 248 | [[package]] 249 | name = "thiserror-impl" 250 | version = "1.0.49" 251 | source = "registry+https://github.com/rust-lang/crates.io-index" 252 | checksum = "10712f02019e9288794769fba95cd6847df9874d49d871d062172f9dd41bc4cc" 253 | dependencies = [ 254 | "proc-macro2", 255 | "quote", 256 | "syn", 257 | ] 258 | 259 | [[package]] 260 | name = "time" 261 | version = "0.3.29" 262 | source = "registry+https://github.com/rust-lang/crates.io-index" 263 | checksum = "426f806f4089c493dcac0d24c29c01e2c38baf8e30f1b716ee37e83d200b18fe" 264 | dependencies = [ 265 | "deranged", 266 | "serde", 267 | "time-core", 268 | ] 269 | 270 | [[package]] 271 | name = "time-core" 272 | version = "0.1.2" 273 | source = "registry+https://github.com/rust-lang/crates.io-index" 274 | checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" 275 | 276 | [[package]] 277 | name = "unicode-ident" 278 | version = "1.0.12" 279 | source = "registry+https://github.com/rust-lang/crates.io-index" 280 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 281 | 282 | [[package]] 283 | name = "wasi" 284 | version = "0.11.0+wasi-snapshot-preview1" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 287 | 288 | [[package]] 289 | name = "winapi" 290 | version = "0.3.9" 291 | source = "registry+https://github.com/rust-lang/crates.io-index" 292 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 293 | dependencies = [ 294 | "winapi-i686-pc-windows-gnu", 295 | "winapi-x86_64-pc-windows-gnu", 296 | ] 297 | 298 | [[package]] 299 | name = "winapi-i686-pc-windows-gnu" 300 | version = "0.4.0" 301 | source = "registry+https://github.com/rust-lang/crates.io-index" 302 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 303 | 304 | [[package]] 305 | name = "winapi-x86_64-pc-windows-gnu" 306 | version = "0.4.0" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 309 | --------------------------------------------------------------------------------