Skip to content
This repository has been archived by the owner on Sep 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from slametps/master
Browse files Browse the repository at this point in the history
add Uptime and support translations
  • Loading branch information
BenRoe authored Apr 18, 2017
2 parents e9ee75c + 615d09d commit 90f14a7
Show file tree
Hide file tree
Showing 7 changed files with 575 additions and 7 deletions.
45 changes: 41 additions & 4 deletions MMM-SystemStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,37 @@ Module.register('MMM-SystemStats', {
updateInterval: 10000,
animationSpeed: 0,
align: 'right',
language: config.language,
useSyslog: false,
thresholdCPUTemp: 75, // in celcius
baseURLSyslog: 'http://127.0.0.1:8080/syslog'
},

// Define required scripts.
getScripts: function () {
return ["moment.js", "moment-duration-format.js"];
},

// Define required translations.
getTranslations: function() {
return {
'en': 'translations/en.json',
'id': 'translations/id.json'
};
},

// Define start sequence
start: function() {
//Log.log('Starting module: ' + this.name);
Log.log('Starting module: ' + this.name);

// set locale
moment.locale(this.config.language);

this.stats = {};
this.stats.cpuTemp = this.translate('LOADING').toLowerCase();
this.stats.sysLoad = this.translate('LOADING').toLowerCase();
this.stats.freeMem = this.translate('LOADING').toLowerCase();
this.stats.upTime = this.translate('LOADING').toLowerCase();
this.sendSocketNotification('CONFIG', this.config);
},

Expand All @@ -30,8 +52,19 @@ Module.register('MMM-SystemStats', {
//Log.log(payload);
if (notification === 'STATS') {
this.stats.cpuTemp = payload.cpuTemp;
//console.log("this.config.useSyslog-" + this.config.useSyslog + ', this.stats.cpuTemp-'+parseInt(this.stats.cpuTemp)+', this.config.thresholdCPUTemp-'+this.config.thresholdCPUTemp);
if (this.config.useSyslog) {
var cpuTemp = Math.ceil(parseFloat(this.stats.cpuTemp));
//console.log('before compare (' + cpuTemp + '/' + this.config.thresholdCPUTemp + ')');
if (cpuTemp > this.config.thresholdCPUTemp) {
console.log('alert for threshold violation (' + cpuTemp + '/' + this.config.thresholdCPUTemp + ')');
this.sendSocketNotification('ALERT', {config: this.config, type: 'WARNING', message: this.translate("TEMP_THRESHOLD_WARNING") + ' (' + this.config.thresholdCPUTemp + ')' });
}
}
this.stats.sysLoad = payload.sysLoad[0];
this.stats.freeMem = Number(payload.freeMem).toFixed() + '%';
upTime = parseInt(payload.upTime[0]);
this.stats.upTime = moment.duration(upTime, "seconds").humanize();
this.updateDom(this.config.animationSpeed);
}
},
Expand All @@ -42,16 +75,20 @@ Module.register('MMM-SystemStats', {
var wrapper = document.createElement('table');

wrapper.innerHTML = '<tr>' +
'<td class="title" style="text-align:' + self.config.align + ';">CPU Temp:&nbsp;</td>' +
'<td class="title" style="text-align:' + self.config.align + ';">' + this.translate("CPU_TEMP") + ':&nbsp;</td>' +
'<td class="value" style="text-align:left;">' + this.stats.cpuTemp + '</td>' +
'</tr>' +
'<tr>' +
'<td class="title" style="text-align:' + self.config.align + ';">System Load:&nbsp;</td>' +
'<td class="title" style="text-align:' + self.config.align + ';">' + this.translate("SYS_LOAD") + ':&nbsp;</td>' +
'<td class="value" style="text-align:left;">' + this.stats.sysLoad + '</td>' +
'</tr>' +
'<tr>' +
'<td class="title" style="text-align:' + self.config.align + ';">Free RAM:&nbsp;</td>' +
'<td class="title" style="text-align:' + self.config.align + ';">' + this.translate("RAM_FREE") + ':&nbsp;</td>' +
'<td class="value" style="text-align:left;">' + this.stats.freeMem + '</td>' +
'</tr>' +
'<tr>' +
'<td class="title" style="text-align:' + self.config.align + ';">' + this.translate("UPTIME") + ':&nbsp;</td>' +
'<td class="value" style="text-align:left;">' + this.stats.upTime + '</td>' +
'</tr>';

return wrapper;
Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,37 @@ The following properties can be configured:
<br><b>Default value:</b> <code>0</code> (animation off)
</td>
</tr>
<tr>
<td><code>language</code></td>
<td>language id for text can be different from MM.
<br><b>Default value:</b> <code>config.language</code>
</td>
</tr>
<tr>
<td><code>align</code></td>
<td>Align the labels.
<br><b>Possible values:</b> <code>left</code> or <code>right</code>
<br><b>Default value:</b> <code>right</code>
</td>
</tr>
<tr>
<td><code>useSyslog</code></td>
<td>log event to MMM-syslog?
<br><b>Default value:</b> <code>false</code>
</td>
</tr>
<tr>
<td><code>thresholdCPUTemp</code></td>
<td>upper-threshold for CPU Temp. If CPU Temp is more than this value, log to MMM-syslog if useSyslog=true. (celcius)
<br><b>Default value:</b> <code>75</code>
</td>
</tr>
<tr>
<td><code>baseURLSyslog</code></td>
<td>URL base of MMM-syslog module
<br><b>Default value:</b> <code>http://127.0.0.1:8080/syslog</code>
</td>
</tr>
</tbody>
</table>

Expand Down
Loading

0 comments on commit 90f14a7

Please sign in to comment.