├── .gitignore ├── screenshot.png ├── package.json ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── SECURITY.md ├── LICENSE.md ├── MMM-Pinfo.css ├── CODE_OF_CONDUCT.md ├── node_helper.js ├── README.md └── MMM-Pinfo.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SalekurPolas/MMM-Pinfo/HEAD/screenshot.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mmm-pinfo", 3 | "version": "1.0.1", 4 | "description": "An informational module for MagicMirror².", 5 | "main": "MMM-Pinfo.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/SalekurPolas/MMM-Pinfo.git" 9 | }, 10 | "keywords": [ 11 | "magicmirror", 12 | "module", 13 | "raspberrypi", 14 | "node" 15 | ], 16 | "author": "Salekur Rahaman", 17 | "license": "MIT", 18 | "bugs": { 19 | "url": "https://github.com/SalekurPolas/MMM-Pinfo/issues" 20 | }, 21 | "homepage": "https://github.com/SalekurPolas/MMM-Pinfo#readme", 22 | "dependencies": { 23 | "systeminformation": "^5.27.1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | Use this section to tell people about which versions of your project are 6 | currently being supported with security updates. 7 | 8 | | Version | Supported | 9 | | ------- | ------------------ | 10 | | 5.1.x | :white_check_mark: | 11 | | 5.0.x | :x: | 12 | | 4.0.x | :white_check_mark: | 13 | | < 4.0 | :x: | 14 | 15 | ## Reporting a Vulnerability 16 | 17 | Use this section to tell people how to report a vulnerability. 18 | 19 | Tell them where to go, how often they can expect to get an update on a 20 | reported vulnerability, what to expect if the vulnerability is accepted or 21 | declined, etc. 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright © 2021 Salekur Rahaman 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MMM-Pinfo.css: -------------------------------------------------------------------------------- 1 | .Pinfo { 2 | display: flex; 3 | flex-direction: column; 4 | justify-content: flex-start; 5 | font-size: initial; 6 | line-height: 1em; 7 | color: #eee; 8 | } 9 | 10 | .Pinfo .item { 11 | display: flex; 12 | flex-direction: row; 13 | justify-content: center; 14 | height: 1.2em; 15 | } 16 | 17 | .Pinfo .item .label { 18 | order: 1; 19 | text-align: start; 20 | padding-right: 15px; 21 | color: #bdf; 22 | overflow: hidden; 23 | text-overflow: ellipsis; 24 | white-space: nowrap; 25 | } 26 | 27 | .Pinfo .item .container { 28 | order: 2; 29 | height: 100%; 30 | margin-top: 0px; 31 | } 32 | 33 | .Pinfo .item .container .value { 34 | /* overflow: hidden; */ 35 | text-overflow: ellipsis; 36 | white-space: nowrap; 37 | text-align: center; 38 | } 39 | 40 | .Pinfo .total { 41 | text-align: right; 42 | background-color: #333; 43 | position: relative; 44 | width: 100%; 45 | } 46 | 47 | .Pinfo .bar { 48 | text-align: left; 49 | position: absolute; 50 | top: 0; 51 | background-color: #369; 52 | overflow: visible; 53 | height: 100%; 54 | } 55 | 56 | .Pinfo .bar.step0 { 57 | background-color: #33c; 58 | } 59 | 60 | .Pinfo .bar.step10 { 61 | background-color: #43b; 62 | } 63 | 64 | .Pinfo .bar.step20 { 65 | background-color: #53a; 66 | } 67 | 68 | .Pinfo .bar.step30 { 69 | background-color: #639; 70 | } 71 | 72 | .Pinfo .bar.step40 { 73 | background-color: #738; 74 | } 75 | 76 | .Pinfo .bar.step50 { 77 | background-color: #837; 78 | } 79 | 80 | .Pinfo .bar.step60 { 81 | background-color: #936; 82 | } 83 | 84 | .Pinfo .bar.step70 { 85 | background-color: #a35; 86 | } 87 | 88 | .Pinfo .bar.step80 { 89 | background-color: #b34; 90 | } 91 | 92 | .Pinfo .bar.step90 { 93 | background-color: #c33; 94 | } 95 | 96 | .Pinfo .bar.step100 { 97 | background-color: #d32; 98 | } 99 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /node_helper.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | const fs = require('fs'); 4 | const os = require('os'); 5 | const si = require('systeminformation'); 6 | const NodeHelper = require('node_helper'); 7 | var log = (...args) => {} 8 | 9 | module.exports = NodeHelper.create({ 10 | start: function() { 11 | this.config = {}; 12 | this.timer = null; 13 | 14 | this.status = { 15 | DEVICE: { 16 | model: 'unknown', 17 | serial: 'unknown' 18 | }, 19 | OS: 'unknown', 20 | NETWORK: { 21 | type: 'unknown', 22 | ipv4: 'unknown', 23 | ipv6: 'unknown', 24 | mac: 'unknown' 25 | }, 26 | MEMORY: { 27 | total: 0, 28 | used: 0, 29 | percent: 0 30 | }, 31 | STORAGE: { 32 | total: 0, 33 | used: 0, 34 | percent: 0 35 | }, 36 | CPU: { 37 | type: 'unknown', 38 | usage: 0, 39 | temp: 0 40 | }, 41 | UPTIME: 'unknown' 42 | } 43 | 44 | this.network = os.networkInterfaces(); 45 | this.DeviceInfo = fs.readFileSync('/proc/cpuinfo', 'utf8').split("\n"); 46 | }, 47 | 48 | socketNotificationReceived: function(notification, payload) { 49 | if (notification === "CONFIG") { 50 | this.config = payload; 51 | if(this.config.debug) { 52 | log = (...args) => { 53 | console.log("[" + this.name + "]", ...args); 54 | } 55 | } 56 | 57 | this.collectStaticInfo(); 58 | } 59 | }, 60 | 61 | collectStaticInfo: async function() { 62 | await this.getDeviceInfo(); 63 | await this.getOSInfo(); 64 | this.scheduler(); 65 | }, 66 | 67 | scheduler: async function() { 68 | clearTimeout(this.timer); 69 | 70 | await this.collectDynamicInfo(resolve => { 71 | this.sendSocketNotification('STATUS', this.status); 72 | }); 73 | 74 | this.timer = setTimeout(() => { 75 | this.scheduler(); 76 | }, this.config.refresh); 77 | }, 78 | 79 | collectDynamicInfo: async function(resolve) { 80 | await this.getNetworkInfo(); 81 | await this.getMemoryInfo(); 82 | await this.getStorageInfo(); 83 | await this.getCPUInfo(); 84 | await this.getUptime(); 85 | resolve(); 86 | }, 87 | 88 | getUptime: function() { 89 | this.status['UPTIME'] = this.convertTime(si.time().uptime) 90 | }, 91 | 92 | getDeviceInfo: function() { 93 | return new Promise((resolve) => { 94 | var ModelInfo = this.DeviceInfo[this.DeviceInfo.length - 2].split(":"); 95 | if (!ModelInfo[1]) { 96 | resolve(); 97 | return; 98 | } 99 | var model = ModelInfo[1].slice(1).split(' '); 100 | delete model[model.length-1]; 101 | delete model[model.length-2]; 102 | this.status['DEVICE'].model = model.toString().replace(new RegExp(',', 'g'), ' '); 103 | 104 | var SerialInfo = this.DeviceInfo[this.DeviceInfo.length - 3].split(":"); 105 | this.status['DEVICE'].serial = SerialInfo[1].slice(1); 106 | resolve(); 107 | }) 108 | }, 109 | 110 | getOSInfo: function() { 111 | return new Promise((resolve) => { 112 | si.osInfo().then(data => { 113 | this.status['OS'] = data.distro.split(' ')[0] + " " + data.release + " (" + data.codename + ")"; 114 | resolve(); 115 | }).catch(error => { 116 | log(error); 117 | }); 118 | }) 119 | }, 120 | 121 | getNetworkInfo: function() { 122 | return new Promise((resolve) => { 123 | si.networkInterfaceDefault().then(defaultInt => { 124 | si.networkInterfaces().then(data => { 125 | data.forEach(net => { 126 | if((net.iface != "lo") && (net.iface === defaultInt)) { 127 | this.status['NETWORK'].type = net.iface; 128 | this.status['NETWORK'].ipv4 = net.ip4; 129 | this.status['NETWORK'].ipv6 = net.ip6; 130 | this.status['NETWORK'].mac = net.mac; 131 | } resolve(); 132 | }); 133 | }).catch(error => { 134 | log(error); 135 | }); 136 | }).catch(error => { 137 | log(error); 138 | }); 139 | }) 140 | }, 141 | 142 | getMemoryInfo: function() { 143 | return new Promise((resolve) => { 144 | si.mem().then(data => { 145 | this.status['MEMORY'].total = this.convert(data.total, 0); 146 | this.status['MEMORY'].used = this.convert(data.used-data.buffcache, 2); 147 | this.status['MEMORY'].percent = ((data.used-data.buffcache) / data.total * 100).toFixed(0); 148 | resolve(); 149 | }).catch(error => { 150 | log(error); 151 | }); 152 | }); 153 | }, 154 | 155 | getStorageInfo: function() { 156 | return new Promise((resolve) => { 157 | si.fsSize().then(data => { 158 | data.forEach(partition => { 159 | if(partition.mount === '/') { 160 | this.status['STORAGE'].total = this.convert(partition.size, 2); 161 | this.status['STORAGE'].used = this.convert(partition.used, 2); 162 | this.status['STORAGE'].percent = partition.use; 163 | resolve(); 164 | } 165 | }) 166 | }).catch(error => { 167 | log(error); 168 | }); 169 | }); 170 | }, 171 | 172 | getCPUInfo: function() { 173 | return new Promise((resolve) => { 174 | var CPUInfo = this.DeviceInfo[this.DeviceInfo.length - 14].split(":"); 175 | try { 176 | var type = CPUInfo[1].slice(1).split(' '); 177 | delete type[type.length-1]; 178 | delete type[type.length-2]; 179 | delete type[type.length-3]; 180 | this.status['CPU'].type = type.toString().replace(new RegExp(',', 'g'), ' '); 181 | } 182 | catch { 183 | this.status['CPU'].type = 'Not available' 184 | } 185 | 186 | si.currentLoad().then(data => { 187 | this.status['CPU'].usage = data.currentLoad.toFixed(0); 188 | }).catch(error => { 189 | log(error); 190 | }); 191 | 192 | si.cpuTemperature().then(data => { 193 | this.status['CPU'].temp = data.main.toFixed(1); 194 | }).catch(error => { 195 | log(error); 196 | }); 197 | resolve(); 198 | }) 199 | }, 200 | 201 | convert: function(octet, FixTo) { 202 | octet = Math.abs(parseInt(octet, 10)); 203 | var def = [ 204 | [1, 'B'], 205 | [1024, 'KB'], 206 | [1024*1024, 'MB'], 207 | [1024*1024*1024, 'GB'], 208 | [1024*1024*1024*1024, 'TB']]; 209 | 210 | for(var i = 0; i < def.length; i++){ 211 | if(octet < def[i][0]) return (octet / def[i-1][0]).toFixed(FixTo) + def[i - 1][1]; 212 | } 213 | }, 214 | 215 | convertTime: function(seconds) { 216 | if (seconds > 60*60*24) { 217 | var humanTime = Math.round(seconds/(60*60*24), 0) + ' days' 218 | } 219 | else if (seconds > 60*60) { 220 | humanTime = Math.round(seconds/(60*60), 0) + ' hours' 221 | } 222 | else if (seconds > 60) { 223 | humanTime = Math.round(seconds/60, 0) + ' minutes' 224 | } 225 | else { 226 | humanTime = Math.round(seconds, 0) + ' seconds' 227 | } 228 | return humanTime 229 | }, 230 | 231 | }); 232 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MMM-Pinfo 2 | 3 | A [MagicMirror²](https://magicmirror.builders/) module that can display device information. This module is mainly inspired by [MMM-Tools](https://github.com/bugsounet/MMM-Tools). To develop this module I used Node.js. Also, MagicMirror users can set warnings for abnormal information. MagicMirror will send a notification if any information exceeds the standard value. 4 | 5 | ## Screenshot 6 | 7 | ![Screenshot](screenshot.png) 8 | 9 | ## Dependencies 10 | 11 | - [systeminformation](https://www.npmjs.com/package/systeminformation) 12 | 13 | ## Installation 14 | 15 | Get the module directly from GitHub and install to MagicMirror using the following commands. 16 | 17 | ```sh 18 | cd ~/MagicMirror/modules/ 19 | git clone https://github.com/SalekurPolas/MMM-Pinfo 20 | cd MMM-Pinfo 21 | npm install 22 | ``` 23 | 24 | ### Manual Installation 25 | 26 | Although dependencies will automatically install during installation on MagicMirror, you can manually install them by the following steps. 27 | 28 | 1. systeminformation 29 | 30 | ```sh 31 | cd ~/MagicMirror/MMM-Pinfo 32 | npm install systeminformation 33 | ``` 34 | 35 | ## Updating 36 | 37 | ```sh 38 | cd ~/MagicMirror/modules/MMM-Pinfo 39 | git pull 40 | npm install 41 | ``` 42 | 43 | ## Usage 44 | 45 | `MMM-Pinfo` module can display the following information 46 | 47 | | Name | Description 48 | | --------------- | -------- 49 | | Model | Display model name and number of the device 50 | | Serial | Display the unique serial number of the device 51 | | Network type | Display connected network types like WLAN, LAN, etc 52 | | IPv4 | Display IPv4 of the corresponding network 53 | | IPv6 | Display IPv6 of the corresponding network 54 | | MAC | Display MAC address of the corresponding network 55 | | RAM | Display total size, usage, and percentage usage of the RAM 56 | | Storage | Display total size, usage, and percentage usage of the Storage 57 | | CPU type | Display CPU type of the device 58 | | CPU usage | Display the percentage of usage 59 | | CPU temp | Display current temperature of the CPU 60 | | System uptime | Display the uptime of the system 61 | 62 | ### Module Usage 63 | 64 | To setup `MMM-Pinfo` module in MagicMirror², add the following section to the `config.js` file in the `MagicMirror/config` directory. 65 | 66 | ```js 67 | { 68 | module: 'MMM-Pinfo', 69 | position: 'top_left' 70 | }, 71 | ``` 72 | 73 | ## Configuration 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 |
OptionTypeDefaultDescription
debugbooleantrueEnable printing debug information
refreshnumber5000Time in milliseconds to refresh automatically
itemAlignstring'left'MMM-Pinfo items alignment.
labelAlignstring'left'Item's label alignment.
valueAlignstring'center'Item's value alignment.
labelSizenumbernullSize of the item's label in px
containerSizenumbernullSize of the item's value container in px
DEVICE.labelModelstring'Model'Label of the model
DEVICE.displayModelbooleantrueDisplay model
DEVICE.orderModelnumber1Order of model
DEVICE.labelSerialstring'Serial'Label of serial
DEVICE.displaySerialbooleantrueDisplay serial
DEVICE.orderSerialnumber2Order of serial
OS.labelOsstring'OS'Label of OS
OS.displayOsbooleanfalseDisplay OS
OS.orderOsnumber3Order of OS
NETWORK.labelTypestring'NET Type'Label of NET Type
NETWORK.displayTypebooleanfalseDisplay NET Type
NETWORK.orderTypenumber4Order of NET Type
NETWORK.labelIPv4string'IPv4'Label of IPv4
NETWORK.displayIPv4booleantrueDisplay IPv4
NETWORK.orderIPv4number5Order of IPv4
NETWORK.labelIPv6string'IPv6'Label of IPv6
NETWORK.displayIPv6booleanfalseDisplay IPv6
NETWORK.orderIPv6number6Order of IPv6
NETWORK.labelMacstring'MAC'Label of MAC
NETWORK.displayMacbooleanfalseDisplay MAC
NETWORK.orderMacnumber7Order of MAC
RAM.labelRamstring'RAM'Label of RAM
RAM.displayRambooleantrueDisplay RAM
RAM.orderRamnumber8Order of RAM
STORAGE.labelStoragestring'Storage'Label of Storage
STORAGE.displayStoragebooleantrueDisplay Storage
STORAGE.orderStoragenumber9Order of Storage
CPU.labelTypestring'CPU Type'Label of CPU Type
CPU.displayTypebooleanfalseDisplay CPU Type
CPU.orderTypenumber10Order of CPU Type
CPU.labelUsagestring'CPU Usage'Label of CPU Usage
CPU.displayUsagebooleanfalseDisplay CPU Usage
CPU.orderUsagenumber11Order of CPU Usage
CPU.labelTempstring'CPU Temp'Label of CPU Temp
CPU.displayTempbooleantrueDisplay CPU Temp
CPU.orderTempnumber12Order of CPU Temp
UPTIME.labelUptimestring'Uptime'Label of Uptime
UPTIME.displayUptimebooleanfalseDisplay Uptime
UPTIME.orderUptimenumber13Order of Uptime
WARNING.enablebooleanfalseDisplay warning for unusual value
WARNING.intervalnumber5000Time in milliseconds to refresh warning
WARNING.check.CPU_TEMPnumber65Normal temperature for CPU Temp
WARNING.check.CPU_USAGEnumber75Normal usage for CPU
WARNING.check.RAM_USEDnumber80Normal usage for RAM
WARNING.check.STORAGE_USEDnumber80Normal usage for STORAGE
398 | 399 | ## Default Configuration 400 | 401 | ```js 402 | { 403 | module: 'MMM-Pinfo', 404 | position: 'top_left', 405 | config: { 406 | debug: true, 407 | refresh: 5000, 408 | itemAlign: 'left', 409 | labelAlign: 'left', 410 | valueAlign: 'center', 411 | labelSize: null, 412 | containerSize: null, 413 | 414 | DEVICE: { 415 | labelModel: "Model", 416 | displayModel: true, 417 | orderModel: 1, 418 | 419 | labelSerial: 'Serial', 420 | displaySerial: true, 421 | orderSerial: 2 422 | }, 423 | 424 | OS: { 425 | labelOs: 'OS', 426 | displayOs: false, 427 | orderOs: 3 428 | }, 429 | 430 | NETWORK: { 431 | labelType: 'NET Type', 432 | displayType: false, 433 | orderType: 4, 434 | 435 | labelIPv4: 'IPv4', 436 | displayIPv4: true, 437 | orderIPv4: 5, 438 | 439 | labelIPv6: 'IPv6', 440 | displayIPv6: false, 441 | orderIPv6: 6, 442 | 443 | labelMac: 'MAC', 444 | displayMac: false, 445 | orderMac: 7 446 | }, 447 | 448 | RAM: { 449 | labelRam: 'RAM', 450 | displayRam: true, 451 | orderRam: 8 452 | }, 453 | 454 | STORAGE: { 455 | labelStorage: 'Storage', 456 | displayStorage: true, 457 | orderStorage: 9, 458 | }, 459 | 460 | CPU: { 461 | labelType: 'CPU Type', 462 | displayType: false, 463 | orderType: 10, 464 | 465 | labelUsage: 'CPU Usage', 466 | displayUsage: false, 467 | orderUsage: 11, 468 | 469 | labelTemp: 'CPU Temp', 470 | displayTemp: true, 471 | orderTemp: 12 472 | }, 473 | UPTIME: { 474 | labelUptime: 'Uptime', 475 | displayUptime: false, 476 | orderUptime: 13 477 | }, 478 | WARNING: { 479 | enable: false, 480 | interval: 1000 * 60 * 5, 481 | check: { 482 | CPU_TEMP: 65, 483 | CPU_USAGE: 75, 484 | RAM_USED: 80, 485 | STORAGE_USED: 80 486 | } 487 | }, 488 | } 489 | }, 490 | ``` 491 | 492 | ## Issues 493 | 494 | - Support for multiple language is not yet complete. 495 | - If if have any other issues then let me know at [Issues](https://github.com/SalekurPolas/MMM-Pinfo/issues). 496 | 497 | ## Credits 498 | 499 | - Michael Teeuw for the awesome invention [MagicMirror²](https://github.com/MagicMirrorOrg/MagicMirror). 500 | - Bugsounet Cédricfor the original module [MMM-Tools](https://github.com/bugsounet/MMM-Tools). 501 | -------------------------------------------------------------------------------- /MMM-Pinfo.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Module.register('MMM-Pinfo', { 4 | defaults: { 5 | debug: false, 6 | refresh: 5000, 7 | itemAlign: 'left', 8 | labelAlign: 'left', 9 | valueAlign: 'center', 10 | labelSize: null, 11 | containerSize: null, 12 | header: 'Mirror Information', 13 | 14 | DEVICE: { 15 | labelModel: "Model", 16 | displayModel: true, 17 | orderModel: 1, 18 | 19 | labelSerial: 'Serial', 20 | displaySerial: true, 21 | orderSerial: 2 22 | }, 23 | OS: { 24 | labelOs: 'OS', 25 | displayOs: false, 26 | orderOs: 3 27 | }, 28 | NETWORK: { 29 | labelType: 'NET Type', 30 | displayType: false, 31 | orderType: 4, 32 | 33 | labelIPv4: 'IPv4', 34 | displayIPv4: true, 35 | orderIPv4: 5, 36 | 37 | labelIPv6: 'IPv6', 38 | displayIPv6: false, 39 | orderIPv6: 6, 40 | 41 | labelMac: 'MAC', 42 | displayMac: false, 43 | orderMac: 7 44 | }, 45 | RAM: { 46 | labelRam: 'RAM', 47 | displayRam: true, 48 | orderRam: 8 49 | }, 50 | STORAGE: { 51 | labelStorage: 'Storage', 52 | displayStorage: true, 53 | orderStorage: 9, 54 | }, 55 | CPU: { 56 | labelType: 'CPU Type', 57 | displayType: false, 58 | orderType: 10, 59 | 60 | labelUsage: 'CPU Usage', 61 | displayUsage: false, 62 | orderUsage: 11, 63 | 64 | labelTemp: 'CPU Temp', 65 | displayTemp: true, 66 | orderTemp: 12 67 | }, 68 | UPTIME: { 69 | labelUptime: 'Uptime', 70 | displayUptime: false, 71 | orderUptime: 13, 72 | }, 73 | WARNING: { 74 | enable: false, 75 | interval: 1000 * 60 * 5, 76 | check: { 77 | CPU_TEMP: 65, 78 | CPU_USAGE: 75, 79 | RAM_USED: 80, 80 | STORAGE_USED: 80 81 | } 82 | }, 83 | }, 84 | 85 | start: function() { 86 | this.item = 0; 87 | this.container = 0; 88 | 89 | this.status = { 90 | DEVICE: { 91 | model: 'Loading...', 92 | serial: 'Loading...' 93 | }, 94 | OS: 'Loading...', 95 | NETWORK: { 96 | type: 'Loading...', 97 | ipv4: 'Loading...', 98 | ipv6: 'Loading...', 99 | mac: 'Loading...' 100 | }, 101 | MEMORY: { 102 | total: 0, 103 | used: 0, 104 | percent: 0 105 | }, 106 | STORAGE: { 107 | total: 0, 108 | used: 0, 109 | percent: 0 110 | }, 111 | CPU: { 112 | type: 'Loading...', 113 | usage: 0, 114 | temp: 0 115 | }, 116 | UPTIME: 'Loading...', 117 | } 118 | 119 | this.config = this.merge({}, this.defaults, this.config); 120 | 121 | if(this.data.position === 'top_left' || this.data.position === 'bottom_left') { 122 | this.config.itemAlign = 'flex-start'; 123 | } else if(this.data.position === 'top_right' || this.data.position === 'bottom_right') { 124 | this.config.itemAlign = 'flex-end'; 125 | } else { 126 | this.config.header = null; 127 | this.config.itemAlign = 'center'; 128 | } 129 | 130 | this.sendSocketNotification('CONFIG', this.config); 131 | }, 132 | 133 | suspend: function() { 134 | this.hidden = true; 135 | Log.log("[ " + this.name + " ] " + " is suspended."); 136 | }, 137 | 138 | resume: function() { 139 | this.hidden = false; 140 | Log.log("[ " + this.name + " ] " + " is resumed."); 141 | }, 142 | 143 | getStyles: function () { 144 | return [this.file('MMM-Pinfo.css')]; 145 | }, 146 | 147 | getScripts: function() { 148 | return ['moment.js']; 149 | }, 150 | 151 | getHeader: function() { 152 | if(this.config.header) { 153 | return this.data.header ? this.data.header : this.config.header; 154 | } else { 155 | return null; 156 | } 157 | }, 158 | 159 | getDom: function() { 160 | var wrapper = document.createElement("div"); 161 | wrapper.className = "Pinfo"; 162 | 163 | if (this.config.DEVICE.displayModel) wrapper.appendChild(this.getDomDeviceModel()); 164 | if (this.config.DEVICE.displaySerial) wrapper.appendChild(this.getDomDeviceSerial()); 165 | if (this.config.OS.displayOs) wrapper.appendChild(this.getDomOS()); 166 | if (this.config.NETWORK.displayType) wrapper.appendChild(this.getDomNetworkType()); 167 | if (this.config.NETWORK.displayIPv4) wrapper.appendChild(this.getDomNetworkIPv4()); 168 | if (this.config.NETWORK.displayIPv6) wrapper.appendChild(this.getDomNetworkIPv6()); 169 | if (this.config.NETWORK.displayMac) wrapper.appendChild(this.getDomNetworkMac()); 170 | if (this.config.RAM.displayRam) wrapper.appendChild(this.getDomMemory()); 171 | if (this.config.STORAGE.displayStorage) wrapper.appendChild(this.getDomStorage()); 172 | if (this.config.CPU.displayType) wrapper.appendChild(this.getDomCPUType()); 173 | if (this.config.CPU.displayUsage) wrapper.appendChild(this.getDomCPUUsage()); 174 | if (this.config.CPU.displayTemp) wrapper.appendChild(this.getDomCPUTemp()); 175 | if (this.config.UPTIME.displayUptime) wrapper.appendChild(this.getDomUptime()); 176 | return wrapper; 177 | }, 178 | 179 | getDomDeviceModel: function() { 180 | var wrapper = document.createElement("div"); 181 | wrapper.className = "item"; 182 | wrapper.style.order = this.config.DEVICE.orderModel; 183 | wrapper.style.justifyContent = this.config.itemAlign; 184 | 185 | var label = document.createElement("div"); 186 | label.className = "label"; 187 | label.style.width = this.labelSize + "px"; 188 | label.style.textAlign = this.config.labelAlign; 189 | label.innerHTML = this.config.DEVICE.labelModel; 190 | 191 | var container = document.createElement("div"); 192 | container.className = "container"; 193 | container.style.width = this.containerSize + "px"; 194 | 195 | var value = document.createElement("div"); 196 | value.className = "value"; 197 | value.innerHTML = this.status['DEVICE'].model; 198 | value.style.textAlign = this.config.valueAlign; 199 | 200 | if (this.config.DEVICE.labelModel.length > this.item) this.item = this.config.DEVICE.labelModel.length; 201 | if (this.status['DEVICE'].model.length > this.container) this.container = this.status['DEVICE'].model.length; 202 | 203 | container.appendChild(value); 204 | wrapper.appendChild(label); 205 | wrapper.appendChild(container); 206 | return wrapper; 207 | }, 208 | 209 | getDomDeviceSerial: function() { 210 | var wrapper = document.createElement("div"); 211 | wrapper.className = "item"; 212 | wrapper.style.justifyContent = this.config.itemAlign; 213 | wrapper.style.order = this.config.DEVICE.orderSerial; 214 | 215 | var label = document.createElement("div"); 216 | label.className = "label"; 217 | label.style.width = this.labelSize + "px"; 218 | label.style.textAlign = this.config.labelAlign; 219 | label.innerHTML = this.config.DEVICE.labelSerial; 220 | 221 | var container = document.createElement("div"); 222 | container.className = "container"; 223 | container.style.width = this.containerSize + "px"; 224 | 225 | var value = document.createElement("div"); 226 | value.className = "value"; 227 | value.innerHTML = this.status['DEVICE'].serial; 228 | value.style.textAlign = this.config.valueAlign; 229 | 230 | if (this.config.DEVICE.labelSerial.length > this.item) this.item = this.config.DEVICE.labelSerial.length; 231 | if (this.status['DEVICE'].serial.length > this.container) this.container = this.status['DEVICE'].serial.length; 232 | 233 | container.appendChild(value); 234 | wrapper.appendChild(label); 235 | wrapper.appendChild(container); 236 | return wrapper; 237 | }, 238 | 239 | getDomOS: function() { 240 | var wrapper = document.createElement("div"); 241 | wrapper.className = "item"; 242 | wrapper.style.justifyContent = this.config.itemAlign; 243 | wrapper.style.order = this.config.OS.orderOs; 244 | 245 | var label = document.createElement("div"); 246 | label.className = "label"; 247 | label.style.width = this.labelSize + "px"; 248 | label.style.textAlign = this.config.labelAlign; 249 | label.innerHTML = this.config.OS.labelOs; 250 | 251 | var container = document.createElement("div"); 252 | container.className = "container"; 253 | container.style.width = this.containerSize + "px"; 254 | 255 | var value = document.createElement("div"); 256 | value.className = "value"; 257 | value.innerHTML = this.status['OS']; 258 | value.style.textAlign = this.config.valueAlign; 259 | 260 | if (this.config.OS.labelOs.length > this.item) this.item = this.config.OS.labelOs.length; 261 | if (this.status['OS'].length > this.container) this.container = this.status['OS'].length; 262 | 263 | container.appendChild(value); 264 | wrapper.appendChild(label); 265 | wrapper.appendChild(container); 266 | return wrapper; 267 | }, 268 | 269 | getDomNetworkType: function() { 270 | var wrapper = document.createElement("div"); 271 | wrapper.className = "item"; 272 | wrapper.style.justifyContent = this.config.itemAlign; 273 | wrapper.style.order = this.config.NETWORK.orderType; 274 | 275 | var label = document.createElement("div"); 276 | label.className = "label"; 277 | label.style.width = this.labelSize + "px"; 278 | label.style.textAlign = this.config.labelAlign; 279 | label.innerHTML = this.config.NETWORK.labelType; 280 | 281 | var container = document.createElement("div"); 282 | container.className = "container"; 283 | container.style.width = this.containerSize + "px"; 284 | 285 | var value = document.createElement("div"); 286 | value.className = "value"; 287 | value.innerHTML = this.status['NETWORK'].type; 288 | value.style.textAlign = this.config.valueAlign; 289 | 290 | if (this.config.NETWORK.labelType.length > this.item) this.item = this.config.NETWORK.labelType.length; 291 | if (this.status['NETWORK'].type.length > this.container) this.container = this.status['NETWORK'].type.length; 292 | 293 | container.appendChild(value); 294 | wrapper.appendChild(label); 295 | wrapper.appendChild(container); 296 | return wrapper; 297 | }, 298 | 299 | getDomNetworkIPv4: function() { 300 | var wrapper = document.createElement("div"); 301 | wrapper.className = "item"; 302 | wrapper.style.justifyContent = this.config.itemAlign; 303 | wrapper.style.order = this.config.NETWORK.orderIPv4; 304 | 305 | var label = document.createElement("div"); 306 | label.className = "label"; 307 | label.style.width = this.labelSize + "px"; 308 | label.style.textAlign = this.config.labelAlign; 309 | label.innerHTML = this.config.NETWORK.labelIPv4; 310 | 311 | var container = document.createElement("div"); 312 | container.className = "container"; 313 | container.style.width = this.containerSize + "px"; 314 | 315 | var value = document.createElement("div"); 316 | value.className = "value"; 317 | value.innerHTML = this.status['NETWORK'].ipv4; 318 | value.style.textAlign = this.config.valueAlign; 319 | 320 | if (this.config.NETWORK.labelIPv4.length > this.item) this.item = this.config.NETWORK.labelIPv4.length; 321 | if (this.status['NETWORK'].ipv4.length > this.container) this.container = this.status['NETWORK'].ipv4.length; 322 | 323 | container.appendChild(value); 324 | wrapper.appendChild(label); 325 | wrapper.appendChild(container); 326 | return wrapper; 327 | }, 328 | 329 | getDomNetworkIPv6: function() { 330 | var wrapper = document.createElement("div"); 331 | wrapper.className = "item"; 332 | wrapper.style.justifyContent = this.config.itemAlign; 333 | wrapper.style.order = this.config.NETWORK.orderIPv6; 334 | 335 | var label = document.createElement("div"); 336 | label.className = "label"; 337 | label.style.width = this.labelSize + "px"; 338 | label.style.textAlign = this.config.labelAlign; 339 | label.innerHTML = this.config.NETWORK.labelIPv6; 340 | 341 | var container = document.createElement("div"); 342 | container.className = "container"; 343 | container.style.width = this.containerSize + "px"; 344 | 345 | var value = document.createElement("div"); 346 | value.className = "value"; 347 | value.innerHTML = this.status['NETWORK'].ipv6; 348 | value.style.textAlign = this.config.valueAlign; 349 | 350 | if (this.config.NETWORK.labelIPv6.length > this.item) this.item = this.config.NETWORK.labelIPv6.length; 351 | if (this.status['NETWORK'].ipv6.length > this.container) this.container = this.status['NETWORK'].ipv6.length; 352 | 353 | container.appendChild(value); 354 | wrapper.appendChild(label); 355 | wrapper.appendChild(container); 356 | return wrapper; 357 | }, 358 | 359 | getDomNetworkMac: function() { 360 | var wrapper = document.createElement("div"); 361 | wrapper.className = "item"; 362 | wrapper.style.justifyContent = this.config.itemAlign; 363 | wrapper.style.order = this.config.NETWORK.orderMac; 364 | 365 | var label = document.createElement("div"); 366 | label.className = "label"; 367 | label.style.width = this.labelSize + "px"; 368 | label.style.textAlign = this.config.labelAlign; 369 | label.innerHTML = this.config.NETWORK.labelMac; 370 | 371 | var container = document.createElement("div"); 372 | container.className = "container"; 373 | container.style.width = this.containerSize + "px"; 374 | 375 | var value = document.createElement("div"); 376 | value.className = "value"; 377 | value.innerHTML = this.status['NETWORK'].mac; 378 | value.style.textAlign = this.config.valueAlign; 379 | 380 | if (this.config.NETWORK.labelMac.length > this.item) this.item = this.config.NETWORK.labelMac.length; 381 | if (this.status['NETWORK'].mac.length > this.container) this.container = this.status['NETWORK'].mac.length; 382 | 383 | container.appendChild(value); 384 | wrapper.appendChild(label); 385 | wrapper.appendChild(container); 386 | return wrapper; 387 | }, 388 | 389 | getDomCPUType: function() { 390 | var wrapper = document.createElement("div"); 391 | wrapper.className = "item"; 392 | wrapper.style.justifyContent = this.config.itemAlign; 393 | wrapper.style.order = this.config.CPU.orderType; 394 | 395 | var label = document.createElement("div"); 396 | label.className = "label"; 397 | label.style.width = this.labelSize + "px"; 398 | label.style.textAlign = this.config.labelAlign; 399 | label.innerHTML = this.config.CPU.labelType; 400 | 401 | var container = document.createElement("div"); 402 | container.className = "container"; 403 | container.style.width = this.containerSize + "px"; 404 | 405 | var value = document.createElement("div"); 406 | value.className = "value"; 407 | value.innerHTML = this.status['CPU'].type; 408 | value.style.textAlign = this.config.valueAlign; 409 | 410 | if (this.config.CPU.labelType.length > this.item) this.item = this.config.CPU.labelType.length; 411 | if (this.status['CPU'].type.length > this.container) this.container = this.status['CPU'].type.length; 412 | 413 | container.appendChild(value); 414 | wrapper.appendChild(label); 415 | wrapper.appendChild(container); 416 | return wrapper; 417 | }, 418 | 419 | getDomUptime : function() { 420 | var wrapper = document.createElement("div"); 421 | wrapper.className = "item"; 422 | wrapper.style.justifyContent = this.config.itemAlign; 423 | wrapper.style.order = this.config.UPTIME.orderUptime; 424 | 425 | var label = document.createElement("div"); 426 | label.className = "label"; 427 | label.style.width = this.labelSize + "px"; 428 | label.style.textAlign = this.config.labelAlign; 429 | label.innerHTML = this.config.UPTIME.labelUptime; 430 | 431 | var container = document.createElement("div"); 432 | container.className = "container"; 433 | container.style.width = this.containerSize + "px"; 434 | 435 | var value = document.createElement("div"); 436 | value.className = "value"; 437 | value.innerHTML = this.status['UPTIME']; 438 | value.style.textAlign = this.config.valueAlign; 439 | 440 | if (this.config.UPTIME.labelUptime.length > this.item) this.item = this.config.UPTIME.labelUptime.length; 441 | if (this.status['UPTIME'].length > this.container) this.container = this.status['UPTIME'].length; 442 | 443 | container.appendChild(value); 444 | wrapper.appendChild(label); 445 | wrapper.appendChild(container); 446 | return wrapper; 447 | }, 448 | 449 | getDomCPUTemp : function() { 450 | var wrapper = document.createElement("div"); 451 | wrapper.className = "item"; 452 | wrapper.style.justifyContent = this.config.itemAlign; 453 | wrapper.style.order = this.config.CPU.orderTemp; 454 | 455 | var label = document.createElement("div"); 456 | label.className = "label"; 457 | label.style.width = this.labelSize + "px"; 458 | label.style.textAlign = this.config.labelAlign; 459 | label.innerHTML = this.config.CPU.labelTemp; 460 | 461 | var container = document.createElement("div"); 462 | container.className = "container"; 463 | container.style.width = this.containerSize + "px"; 464 | 465 | var total = document.createElement("div"); 466 | total.className = "total"; 467 | if (config.units === 'imperial') { 468 | total.innerHTML = Math.round(this.status['CPU'].temp * 9/5 + 32, 0) + '\°F'; 469 | } 470 | else { 471 | total.innerHTML = this.status['CPU'].temp + '\°C'; 472 | } 473 | 474 | var used = document.createElement("div"); 475 | used.style.opacity = 0.75; 476 | used.style.width = this.status['CPU'].temp + "%"; 477 | 478 | var step = this.getLevel(this.status['CPU'].temp, -1); 479 | step > 100 ? step = 100 : step = step; 480 | used.className = "bar step" + step; 481 | 482 | if (this.config.CPU.labelTemp.length > this.item) this.item = this.config.CPU.labelTemp.length; 483 | 484 | total.appendChild(used); 485 | container.appendChild(total); 486 | wrapper.appendChild(label); 487 | wrapper.appendChild(container); 488 | return wrapper; 489 | }, 490 | 491 | getDomCPUUsage : function() { 492 | var wrapper = document.createElement("div"); 493 | wrapper.className = "item"; 494 | wrapper.style.justifyContent = this.config.itemAlign; 495 | wrapper.style.order = this.config.CPU.orderUsage; 496 | 497 | var label = document.createElement("div"); 498 | label.className = "label"; 499 | label.style.width = this.labelSize + "px"; 500 | label.style.textAlign = this.config.labelAlign; 501 | label.innerHTML = this.config.CPU.labelUsage; 502 | 503 | var container = document.createElement("div"); 504 | container.className = "container"; 505 | container.style.width = this.containerSize + "px"; 506 | 507 | var total = document.createElement("div"); 508 | total.className = "total"; 509 | total.innerHTML = "  "; 510 | 511 | var used = document.createElement("div"); 512 | used.style.opacity = 0.75; 513 | used.innerHTML = this.status["CPU"].usage + "%"; 514 | used.style.width = Math.round(this.status['CPU'].usage) + "%"; 515 | 516 | var step = this.getLevel(this.status["CPU"].usage, -1); 517 | step > 100 ? step = 100 : step = step; 518 | used.className = "bar step" + step; 519 | 520 | if (this.config.CPU.labelUsage.length > this.item ) this.item = this.config.CPU.labelUsage.length; 521 | 522 | total.appendChild(used); 523 | container.appendChild(total); 524 | wrapper.appendChild(label); 525 | wrapper.appendChild(container); 526 | return wrapper 527 | }, 528 | 529 | getDomMemory : function () { 530 | var wrapper = document.createElement("div"); 531 | wrapper.className = "item"; 532 | wrapper.style.justifyContent = this.config.itemAlign; 533 | wrapper.style.order = this.config.RAM.orderRam; 534 | 535 | var label = document.createElement("div"); 536 | label.className = "label"; 537 | label.style.width = this.labelSize + "px"; 538 | label.style.textAlign = this.config.labelAlign; 539 | label.innerHTML = this.config.RAM.labelRam; 540 | 541 | var container = document.createElement("div"); 542 | container.className = "container"; 543 | container.style.width = this.containerSize + "px"; 544 | 545 | var total = document.createElement("div"); 546 | total.className = "total"; 547 | total.innerHTML = this.status["MEMORY"].total; 548 | 549 | var used = document.createElement("div"); 550 | used.style.width = Math.round(this.status["MEMORY"].percent) + "%"; 551 | used.innerHTML = this.status["MEMORY"].used; 552 | 553 | var step = this.getLevel(this.status["MEMORY"].percent, -1); 554 | step > 100 ? step = 100 : step = step; 555 | used.className = "bar step" + step; 556 | used.style.opacity = 0.75; 557 | 558 | if (this.config.RAM.labelRam.length > this.item ) this.item = this.config.RAM.labelRam.length; 559 | 560 | total.appendChild(used) 561 | container.appendChild(total) 562 | wrapper.appendChild(label) 563 | wrapper.appendChild(container) 564 | return wrapper; 565 | }, 566 | 567 | getDomStorage : function () { 568 | var wrapper = document.createElement("div"); 569 | wrapper.className = "item"; 570 | wrapper.style.justifyContent = this.config.itemAlign; 571 | wrapper.style.order = this.config.STORAGE.orderStorage; 572 | 573 | var label = document.createElement("div"); 574 | label.className = "label"; 575 | label.style.width = this.labelSize + "px"; 576 | label.style.textAlign = this.config.labelAlign; 577 | label.innerHTML = this.config.STORAGE.labelStorage; 578 | 579 | var container = document.createElement("div"); 580 | container.className = "container"; 581 | container.style.width = this.containerSize + "px"; 582 | 583 | var total = document.createElement("div"); 584 | total.className = "total"; 585 | total.innerHTML = this.status["STORAGE"].total; 586 | 587 | var used = document.createElement("div"); 588 | used.style.width = Math.round(this.status["STORAGE"].percent) + "%"; 589 | used.innerHTML = this.status["STORAGE"].used; 590 | 591 | var step = this.getLevel(this.status["STORAGE"].percent, -1); 592 | step > 100 ? step = 100 : step = step; 593 | used.className = "bar step" + step; 594 | used.style.opacity = 0.75; 595 | 596 | if (this.config.STORAGE.labelStorage.length > this.item ) this.item = this.config.STORAGE.labelStorage.length; 597 | 598 | total.appendChild(used) 599 | container.appendChild(total) 600 | wrapper.appendChild(label) 601 | wrapper.appendChild(container) 602 | return wrapper; 603 | }, 604 | 605 | checkWarning : function() { 606 | if(this.config.WARNING.enable) { 607 | for(var name in this.config.WARNING.check) { 608 | var checkValue = this.config.WARNING.check[name]; 609 | if(name == "CPU_TEMP") { 610 | let actualValue = parseFloat(this.status["CPU"].temp); 611 | if(checkValue < actualValue) this.showWarning(name, actualValue, checkValue); 612 | } else if(name == "CPU_USAGE") { 613 | let actualValue = parseFloat(this.status["CPU"].usage); 614 | if(checkValue < actualValue) this.showWarning(name, actualValue, checkValue); 615 | } else if(name == "MEMORY_USED") { 616 | let actualValue = parseFloat(this.status["MEMORY"].percent); 617 | if(checkValue < actualValue) this.showWarning(name, actualValue, checkValue); 618 | } else if(name == "STORAGE_USED") { 619 | let actualValue = parseFloat(this.status["STORAGE"].percent); 620 | if(checkValue < actualValue) this.showWarning(name, actualValue, checkValue); 621 | } 622 | } 623 | } 624 | }, 625 | 626 | showWarning: function(name, value, check) { 627 | this.sendNotification("SHOW_ALERT", { 628 | type: "notification", 629 | title: this.name + " WARNING", 630 | message: name + " value " + value + " exceeds " + check 631 | }); 632 | }, 633 | 634 | getLevel: function(number, precision) { 635 | var factor = Math.pow(10, precision); 636 | var tempNumber = Math.round(number * factor); 637 | return tempNumber / factor; 638 | }, 639 | 640 | notificationReceived: function(notification, payload, sender) { 641 | if (notification === 'DOM_OBJECTS_CREATED') { 642 | //..... 643 | } 644 | }, 645 | 646 | socketNotificationReceived: function(notification, payload) { 647 | if (notification === "STATUS") { 648 | this.status = payload; 649 | this.checkWarning(); 650 | 651 | this.config.containerSize ? this.containerSize = this.config.containerSize : this.containerSize = (this.container * 7) + 10; 652 | this.config.labelSize ? this.labelSize = this.config.labelSize : this.labelSize = (this.item * 7) + 10; 653 | this.updateDom(); 654 | } 655 | }, 656 | 657 | merge: function(e) { 658 | for (var o, t, r = Array.prototype.slice.call(arguments, 1); r.length;) { 659 | o = r.shift(); 660 | for (t in o) o.hasOwnProperty(t) && ("object" == typeof e[t] && e[t] && "[object Array]" !== Object.prototype.toString.call(e[t]) && "object" == typeof o[t] && null !== o[t] ? e[t] = configMerge({}, e[t], o[t]) : e[t] = o[t]); 661 | } 662 | return e; 663 | } 664 | }); --------------------------------------------------------------------------------