Skip to content

Commit 67ec692

Browse files
author
Jared Hendrickson
committed
Fixed temp logic in system status endpoint, updated JSON structure in system status endpoint, updated docs
1 parent 5bb9e23 commit 67ec692

4 files changed

Lines changed: 19 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3594,7 +3594,7 @@ URL: https://{{$hostname}}/api/v1/status/log/system
35943594
### 1. Read System Status
35953595

35963596

3597-
Read system status and metrics.<br><br>
3597+
Read system status and metrics. All usage values are represented as a decimal percentage. Temperature readings require thermal sensor and/or driver configuration.<br><br>
35983598

35993599
_Requires at least one of the following privileges:_ [`page-all`, `page-dashboard-widgets`, `page-dashboard-all`]
36003600

docs/documentation.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4705,7 +4705,7 @@
47054705
"system"
47064706
]
47074707
},
4708-
"description": "Read system status and metrics.<br><br>\n\n_Requires at least one of the following privileges:_ [`page-all`, `page-dashboard-widgets`, `page-dashboard-all`]"
4708+
"description": "Read system status and metrics. All usage values are represented as a decimal percentage. Temperature readings require thermal sensor and/or driver configuration.<br><br>\n\n_Requires at least one of the following privileges:_ [`page-all`, `page-dashboard-widgets`, `page-dashboard-all`]"
47094709
},
47104710
"response": []
47114711
}

pfSense-pkg-API/files/etc/inc/api/models/APIStatusSystemRead.inc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
require_once("api/framework/APIModel.inc");
1717
require_once("api/framework/APIResponse.inc");
18+
require_once("includes/functions.inc.php");
1819

1920

2021
class APIStatusSystemRead extends APIModel {
@@ -29,13 +30,6 @@ class APIStatusSystemRead extends APIModel {
2930
}
3031

3132
private function __get_metrics() {
32-
include_once("includes/functions.inc.php");
33-
# Pre-return definitions
34-
foreach(get_mounted_filesystems() as $fs) {
35-
if ($fs["mountpoint"] === "/") {
36-
$disk_usage = APITools\float_percent($fs["percent_used"]);
37-
}
38-
}
3933

4034
# Place each gathered metric into our return array
4135
$sys_info = [
@@ -46,14 +40,15 @@ class APIStatusSystemRead extends APIModel {
4640
"bios_version" => $this->__get_bios_info()["bios_version"],
4741
"bios_date" => $this->__get_bios_info()["bios_date"],
4842
"cpu_model" => get_single_sysctl("hw.model"),
43+
"kernel_pti" => boolval(get_single_sysctl('vm.pmap.pti')),
4944
"mds_mitigation" => get_single_sysctl('hw.mds_disable_state'),
50-
"mbuf_usage" => $this->__get_mbuf_usage(),
5145
"temp_c" => $this->__get_temp(),
5246
"temp_f" => $this->__get_temp(false),
5347
"load_avg" => $this->__get_load_avg(),
48+
"mbuf_usage" => $this->__get_mbuf_usage(),
5449
"mem_usage" => (!is_null(mem_usage())) ? APITools\float_percent(mem_usage()) : null,
5550
"swap_usage" => (!is_null(swap_usage())) ? APITools\float_percent(swap_usage()) : null,
56-
"disk_usage" => $disk_usage
51+
"disk_usage" => $this->__get_filesystem_usage()
5752
];
5853
return $sys_info;
5954
}
@@ -69,9 +64,9 @@ class APIStatusSystemRead extends APIModel {
6964
# Gets the current CPU temperatures in either Fº or Cº, return null if no temperature could be found
7065
private function __get_temp($celsius=true) {
7166
if ($celsius) {
72-
return (!empty(get_temp())) ? get_temp() : null;
67+
return (!empty(get_temp())) ? floatval(get_temp()) : null;
7368
} else {
74-
return (!empty(get_temp())) ? get_temp() * 1.8 + 32 : null;
69+
return (!empty(get_temp())) ? floatval(get_temp()) * 1.8 + 32 : null;
7570
}
7671
}
7772

@@ -96,4 +91,13 @@ class APIStatusSystemRead extends APIModel {
9691
return $bios_info;
9792
}
9893

94+
# Gathers filesystem usage data
95+
private function __get_filesystem_usage() {
96+
foreach(get_mounted_filesystems() as $fs) {
97+
if ($fs["mountpoint"] === "/") {
98+
return APITools\float_percent($fs["percent_used"]);
99+
}
100+
}
101+
}
102+
99103
}

pfSense-pkg-API/files/usr/local/www/api/documentation/index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@
12361236
<a class=text-info data-toggle=collapse data-parent=#accordion-STATUS_2FSYSTEM href=#collapse-STATUS_2FSYSTEM-ReadSystemStatus><h4 class=panel-title><span class="glyphicon glyphicon-plus"></span><strong>Read System Status</strong> &nbsp;|&nbsp;
12371237
<strong class="request-method border-info">GET</strong>
12381238
&nbsp;
1239-
https://<?echo $_SERVER['HTTP_HOST'];?>/api/v1/status/system</h4></a></div><div id=collapse-STATUS_2FSYSTEM-ReadSystemStatus class="panel-collapse collapse"><div class=panel-body><h5 class="label label-default">Description</h5><br><small><p>Read system status and metrics.<br><br><p><em>Requires at least one of the following privileges:</em> [<code>page-all</code>, <code>page-dashboard-widgets</code>, <code>page-dashboard-all</code>]</small><br><br><h5 class="label label-primary">Body</h5><span class=resp-prettyprint>{
1239+
https://<?echo $_SERVER['HTTP_HOST'];?>/api/v1/status/system</h4></a></div><div id=collapse-STATUS_2FSYSTEM-ReadSystemStatus class="panel-collapse collapse"><div class=panel-body><h5 class="label label-default">Description</h5><br><small><p>Read system status and metrics. All usage values are represented as a decimal percentage. Temperature readings require thermal sensor and/or driver configuration.<br><br><p><em>Requires at least one of the following privileges:</em> [<code>page-all</code>, <code>page-dashboard-widgets</code>, <code>page-dashboard-all</code>]</small><br><br><h5 class="label label-primary">Body</h5><span class=resp-prettyprint>{
12401240
}</span><div class=clearfix></div></div></div></div></div></div></div></div><div class="panel panel-default"><div class=panel-heading><h3 class=panel-title id=SYSTEM_2FAPI>SYSTEM/API
12411241
<span class=badge>2</span></h3></div><div class=panel-body><p><div class=request-item><div class=panel-group id=accordion-SYSTEM_2FAPI><div class="panel panel-info" id=jump-SYSTEM_2FAPI-ReadSystemAPIConfiguration><div class=panel-heading><small class="pull-right text-muted">raw</small>
12421242
<a class=text-info data-toggle=collapse data-parent=#accordion-SYSTEM_2FAPI href=#collapse-SYSTEM_2FAPI-ReadSystemAPIConfiguration><h4 class=panel-title><span class="glyphicon glyphicon-plus"></span><strong>Read System API Configuration</strong> &nbsp;|&nbsp;
@@ -1497,7 +1497,7 @@
14971497
function IsJsonString(str){try{JSON.parse(str);}catch(e){return false;}
14981498
return true;}
14991499
String.prototype.replaceAll=function(replaceThis,withThis){var re=new RegExp(RegExp.quote(replaceThis),"g");return this.replace(re,withThis);};RegExp.quote=function(str){return str.replace(/([.?*+^$[\]\\(){}-])/g,"\\$1");};function syntaxHighlight(json){json=json.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g,function(match){var cls='number';if(/^"/.test(match)){if(/:$/.test(match)){cls='key';}else{cls='string';}}else if(/true|false/.test(match)){cls='boolean';}else if(/null/.test(match)){cls='null';}
1500-
return '<span class="'+cls+'">'+match+'</span>';});}</script><br><br><footer class="navbar-default navbar-fixed-bottom"><div class=container-fluid><div class="span12 text-center"><span data-toggle=tooltip title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Made with <em class=love-color>&#9829;</em> by <a href=https://github.com/thedevsaddam target=_blank class=text-muted>thedevsaddam</a> | Generated at: 2020-11-12 19:16:43 by <a href=https://github.com/thedevsaddam/docgen target=_blank class=text-muted>docgen</a></span></div></div></footer>
1500+
return '<span class="'+cls+'">'+match+'</span>';});}</script><br><br><footer class="navbar-default navbar-fixed-bottom"><div class=container-fluid><div class="span12 text-center"><span data-toggle=tooltip title="If the application help you, please feel free to give a star to the project in github. Your star inspire me to work more on open-source projects like this!">Made with <em class=love-color>&#9829;</em> by <a href=https://github.com/thedevsaddam target=_blank class=text-muted>thedevsaddam</a> | Generated at: 2020-11-13 09:31:55 by <a href=https://github.com/thedevsaddam/docgen target=_blank class=text-muted>docgen</a></span></div></div></footer>
15011501
<style>
15021502
body {
15031503
display: block;

0 commit comments

Comments
 (0)