add api for descriptor to root domain, tidying things up
This commit is contained in:
@ -9,4 +9,6 @@ The docker stack also uses a network on the 192.168.37.0/24 subnet, and secures
|
||||
Working on the network descriptor, and I think to make it easier on me i will use json output from ip
|
||||
The problem is that if an interface has multiple IPs, then I have multiple lines of data for IPs
|
||||
I think perhaps I will update my code to be aware of properties that may be arrays
|
||||
I do think this makes more sense than having multiple cards for a single interface...
|
||||
I do think this makes more sense than having multiple cards for a single interface...
|
||||
|
||||
Need to differentiate between LAN and WLAN, it's weird when it's not
|
||||
@ -272,6 +272,7 @@ class System:
|
||||
print(f"System initializing, name {self.name}")
|
||||
# system contains an array of component objects
|
||||
self.components = []
|
||||
self.component_class_tree = component_class_tree
|
||||
# initialize system properties and metrics dicts
|
||||
self._properties: Dict[str, str] = {}
|
||||
self._metrics: Dict[str, str] = {}
|
||||
@ -385,6 +386,9 @@ class System:
|
||||
def check_system_timer(self):
|
||||
time_lapsed = time.time() - float(self.recent_check)
|
||||
return time_lapsed < 30.0
|
||||
|
||||
def get_component_class_tree(self):
|
||||
return self.component_class_tree
|
||||
|
||||
########################################################
|
||||
# static metrics redis data functions
|
||||
|
||||
@ -125,6 +125,11 @@ def php_summary():
|
||||
def info():
|
||||
return jsonify(get_info())
|
||||
|
||||
# system info
|
||||
@app.route('/descriptor', methods=['GET'])
|
||||
def descriptor():
|
||||
return jsonify(get_descriptor())
|
||||
|
||||
# socket timer
|
||||
@app.route('/start_timer', methods=['GET'])
|
||||
def start_timer():
|
||||
@ -239,6 +244,9 @@ def get_php_summary():
|
||||
|
||||
return result
|
||||
|
||||
def get_descriptor():
|
||||
return cosmostat_system.get_component_class_tree()
|
||||
|
||||
#######################################################################
|
||||
### Other Functions
|
||||
#######################################################################
|
||||
|
||||
@ -36,22 +36,6 @@
|
||||
"RAM Voltage"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "STOR",
|
||||
"description": "{Device Path} is of type {Drive Type} with capacity of {Total Capacity}.",
|
||||
"multi_check": "True",
|
||||
"device_list": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{print $1}'",
|
||||
"properties": {
|
||||
"Device Name": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{{print $1}}' | grep {this_device}",
|
||||
"Device Path": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{{print \"/dev/\"$1}}' | grep {this_device}",
|
||||
"Drive Type": "lsblk -d -o NAME,TRAN | grep {this_device} | awk '{{print $2}}'",
|
||||
"Total Capacity": "lsblk -d -o NAME,SIZE | grep {this_device} | awk '{{print $2}}'",
|
||||
"SMART Check": "sudo /usr/sbin/smartctl -x --json /dev/{this_device} | jq -r .smart_status.passed"
|
||||
},
|
||||
"metrics": {
|
||||
"placeholder": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "LAN",
|
||||
"description": "{Device ID} - {Device Name} - {MAC Address}",
|
||||
@ -67,7 +51,7 @@
|
||||
"Data Transmitted": "ifconfig {this_device} | grep RX | grep bytes | cut -d '(' -f2 | tr -d ')'",
|
||||
"Data Received": "ifconfig {this_device} | grep TX | grep bytes | cut -d '(' -f2 | tr -d ')'",
|
||||
"Link State": "cat /sys/class/net/{this_device}/operstate",
|
||||
"Link Speed": "cat /sys/class/net/{this_device}/speed"
|
||||
"Link Speed": "cat /sys/class/net/{this_device}/speed || true"
|
||||
},
|
||||
"multi_metrics": [
|
||||
"IP Address"
|
||||
@ -82,7 +66,7 @@
|
||||
"Device Model": "nvidia-smi --id={this_device} --query-gpu=name --format=csv,noheader,nounits",
|
||||
"Device ID": "echo NVGPU{this_device}",
|
||||
"Driver Version": "nvidia-smi --id={this_device} --query-gpu=driver_version --format=csv,noheader,nounits",
|
||||
"Maximum Power": "nvidia-smi --id={this_device} --query-gpu=power.draw --format=csv,noheader,nounits",
|
||||
"Maximum Power": "nvidia-smi --id={this_device} --query-gpu=power.limit --format=csv,noheader,nounits",
|
||||
"Memory Size": "nvidia-smi --id={this_device} --query-gpu=memory.total --format=csv,noheader,nounits"
|
||||
|
||||
},
|
||||
@ -94,5 +78,21 @@
|
||||
|
||||
},
|
||||
"precheck": "lspci | grep NV | wc -l"
|
||||
},
|
||||
{
|
||||
"name": "STOR",
|
||||
"description": "{Device Path} is of type {Drive Type} with capacity of {Total Capacity}.",
|
||||
"multi_check": "True",
|
||||
"device_list": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{print $1}'",
|
||||
"properties": {
|
||||
"Device Name": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{{print $1}}' | grep {this_device}",
|
||||
"Device Path": "lsblk -d -o NAME,SIZE | grep -v -e 0B -e NAME | awk '{{print \"/dev/\"$1}}' | grep {this_device}",
|
||||
"Drive Type": "lsblk -d -o NAME,TRAN | grep {this_device} | awk '{{print $2}}'",
|
||||
"Total Capacity": "lsblk -d -o NAME,SIZE | grep {this_device} | awk '{{print $2}}'",
|
||||
"SMART Check": "sudo /usr/sbin/smartctl -x --json /dev/{this_device} | jq -r .smart_status.passed"
|
||||
},
|
||||
"metrics": {
|
||||
"placeholder": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
@ -20,7 +20,18 @@
|
||||
<div class="card">
|
||||
<h2>Matt-Cloud Cosmostat Dashboard</h2>
|
||||
This dashboard shows the local Matt-Cloud system stats.<p>
|
||||
<div class="help-link" id="helpToggle" >API</div>
|
||||
</div>
|
||||
|
||||
<div id="helpText" class="card">
|
||||
<strong>Component Desriptor</strong><p>
|
||||
To view the component descriptor, you may <br>
|
||||
<code>
|
||||
curl -s https://<?php echo $_SERVER['SERVER_NAME'] ?>/descriptor<br>
|
||||
</code>
|
||||
This will return the entire JSON descriptor variable
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<div id="host_components" class="column">
|
||||
|
||||
@ -115,5 +126,17 @@
|
||||
<!-- matt-cloud redis script -->
|
||||
<script src="src/redis.js"></script>
|
||||
|
||||
<!-- Toggle the help text when the link is clicked -->
|
||||
<script>
|
||||
document.getElementById('helpToggle').addEventListener('click', function () {
|
||||
const help = document.getElementById('helpText');
|
||||
if (help.style.display === 'none' || help.style.display === '') {
|
||||
help.style.display = 'block';
|
||||
} else {
|
||||
help.style.display = 'none';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -49,3 +49,15 @@ li {
|
||||
#host_metrics_table tbody tr td :nth-of-type(even) {
|
||||
background-color: #3e5c78;
|
||||
}
|
||||
|
||||
.help-link{
|
||||
cursor:pointer;
|
||||
user-select:none;
|
||||
color: #2c3e50;
|
||||
text-align: right;
|
||||
}
|
||||
.help-link:hover{ text-decoration:underline; }
|
||||
|
||||
#helpText{
|
||||
display:none; /* hidden by default */
|
||||
}
|
||||
|
||||
@ -10,31 +10,40 @@ server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# Proxy everything under "/" to the php server backend
|
||||
# --------------------------------------------------------------------
|
||||
location / {
|
||||
proxy_pass http://192.168.37.1:8080;
|
||||
# ---------------------------------------
|
||||
# The API – only /descriptor
|
||||
# ---------------------------------------
|
||||
location = /descriptor {
|
||||
proxy_pass http://192.168.37.1:5000/descriptor;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
# ----- Custom Nginx Configuration (inside <location> block) -----
|
||||
location /socket.io/ {
|
||||
# Forward to the Node WS server
|
||||
proxy_pass http://192.168.37.1:3000; # or <node_container_ip>
|
||||
proxy_set_header X-Forwarded-Proto $sceme;
|
||||
}
|
||||
|
||||
# Keep WebSocket upgrade headers
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
# ---------------------------------------
|
||||
# WebSocket endpoint
|
||||
# ---------------------------------------
|
||||
location /socket.io/ {
|
||||
proxy_pass http://192.168.37.1:3000/socket.io/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
# Optional: pass on other headers you care about
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
# ---------------------------------------
|
||||
# All other paths → Apache (PHP)
|
||||
# ---------------------------------------
|
||||
location / {
|
||||
proxy_pass http://192.168.37.1:8080;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user