block storage init commit
This commit is contained in:
@ -11,6 +11,7 @@ cosmostat_packages:
|
|||||||
- python3-venv
|
- python3-venv
|
||||||
- lm-sensors
|
- lm-sensors
|
||||||
- jc
|
- jc
|
||||||
|
- smartmontools
|
||||||
|
|
||||||
# python venv packages
|
# python venv packages
|
||||||
cosmostat_venv_packages: |
|
cosmostat_venv_packages: |
|
||||||
@ -25,6 +26,7 @@ cosmostat_venv_packages: |
|
|||||||
# cosmostat sudoers file
|
# cosmostat sudoers file
|
||||||
cosmostat_sudoers_content: |
|
cosmostat_sudoers_content: |
|
||||||
cosmos ALL=(root) NOPASSWD: /usr/bin/lshw
|
cosmos ALL=(root) NOPASSWD: /usr/bin/lshw
|
||||||
|
cosmos ALL=(root) NOPASSWD: /usr/sbin/smartctl
|
||||||
|
|
||||||
# subnet for service
|
# subnet for service
|
||||||
docker_subnet: "192.168.37.0/24"
|
docker_subnet: "192.168.37.0/24"
|
||||||
|
|||||||
@ -20,9 +20,11 @@ component_types = [{"name": entry["name"], "multi_check": entry["multi_check"] =
|
|||||||
|
|
||||||
class Component:
|
class Component:
|
||||||
|
|
||||||
def __init__(self, name: str, comp_type: str ):
|
def __init__(self, name: str, comp_type: str, this_device="None"):
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type = comp_type
|
self.type = comp_type
|
||||||
|
self.this_device = this_device
|
||||||
|
print(f"This device - {self.this_device}")
|
||||||
for component in component_class_tree:
|
for component in component_class_tree:
|
||||||
if component["name"] == self.type:
|
if component["name"] == self.type:
|
||||||
COMPONENT_DESCRIPTORS = component
|
COMPONENT_DESCRIPTORS = component
|
||||||
@ -39,7 +41,12 @@ class Component:
|
|||||||
self.multi_check = self.is_multi()
|
self.multi_check = self.is_multi()
|
||||||
self._properties: Dict[str, str] = {}
|
self._properties: Dict[str, str] = {}
|
||||||
for key, command in descriptor.get('properties', {}).items():
|
for key, command in descriptor.get('properties', {}).items():
|
||||||
self._properties[key] = run_command(command, True)
|
if self.this_device != "None":
|
||||||
|
print(f"command - {command}; this_device - {self.this_device}")
|
||||||
|
formatted_command = command.format(this_device=self.this_device)
|
||||||
|
self._properties[key] = run_command(formatted_command, True)
|
||||||
|
else:
|
||||||
|
self._properties[key] = run_command(command, True)
|
||||||
# build the description string
|
# build the description string
|
||||||
self._description_template: str | None = descriptor.get("description")
|
self._description_template: str | None = descriptor.get("description")
|
||||||
self.description = self._description_template.format(**self._properties)
|
self.description = self._description_template.format(**self._properties)
|
||||||
@ -59,7 +66,11 @@ class Component:
|
|||||||
|
|
||||||
def update_metrics(self):
|
def update_metrics(self):
|
||||||
for key, command in self._descriptor.get('metrics', {}).items():
|
for key, command in self._descriptor.get('metrics', {}).items():
|
||||||
self._metrics[key] = run_command(command, True)
|
if self.this_device != "None":
|
||||||
|
formatted_command = command.format(this_device=self.this_device)
|
||||||
|
self._properties[key] = run_command(formatted_command, True)
|
||||||
|
else:
|
||||||
|
self._metrics[key] = run_command(command, True)
|
||||||
|
|
||||||
# complex data type return
|
# complex data type return
|
||||||
def get_metrics(self, type = None):
|
def get_metrics(self, type = None):
|
||||||
@ -207,15 +218,25 @@ class System:
|
|||||||
for component in component_types:
|
for component in component_types:
|
||||||
component_name = component["name"]
|
component_name = component["name"]
|
||||||
multi_check = component["multi_check"]
|
multi_check = component["multi_check"]
|
||||||
|
# if multi, note that the command in device_list creates the list of things to pipe into this_device
|
||||||
if multi_check:
|
if multi_check:
|
||||||
print("placeholder...")
|
letters = [chr(c) for c in range(ord('a'), ord('z')+1)]
|
||||||
|
print(f"Creating one component of type {component_name} for each one found")
|
||||||
|
component_type_device_list = get_device_list(component_name)
|
||||||
|
|
||||||
|
for this_device in component_type_device_list:
|
||||||
|
this_component_letter = letters[component_type_device_list.index(this_device)]
|
||||||
|
this_component_name = f"{this_device}_{this_component_letter}"
|
||||||
|
print(f"{this_component_name} - {component_name} - {this_device}")
|
||||||
|
self.add_components(Component(this_component_name, component_name, this_device))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
if debug_output:
|
if debug_output:
|
||||||
print(f"Creating component {component["name"]}")
|
print(f"Creating component {component["name"]}")
|
||||||
self.add_components(Component(component_name, component_name))
|
self.add_components(Component(component_name, component_name))
|
||||||
|
|
||||||
# Add a component to the system
|
# Add a component to the system
|
||||||
def add_components(self, component: Component):
|
def add_components(self, component: Component,):
|
||||||
if debug_output:
|
if debug_output:
|
||||||
print(f"Component description: {component.description}")
|
print(f"Component description: {component.description}")
|
||||||
self.components.append(component)
|
self.components.append(component)
|
||||||
@ -357,3 +378,13 @@ def run_command(cmd, zero_only=False):
|
|||||||
return output_lines[0] if zero_only else output_lines
|
return output_lines[0] if zero_only else output_lines
|
||||||
except:
|
except:
|
||||||
return output_lines
|
return output_lines
|
||||||
|
|
||||||
|
def get_device_list(device_type_name: str):
|
||||||
|
result = []
|
||||||
|
for component in component_class_tree:
|
||||||
|
if component["name"] == device_type_name:
|
||||||
|
device_list_command = component["device_list"]
|
||||||
|
device_list_result = run_command(device_list_command)
|
||||||
|
result = device_list_result
|
||||||
|
|
||||||
|
return result
|
||||||
|
|||||||
@ -25,5 +25,22 @@
|
|||||||
"used_capacity_mb": "free -m | grep Mem | awk '{print $3}'",
|
"used_capacity_mb": "free -m | grep Mem | awk '{print $3}'",
|
||||||
"free_capacity_mb": "free -m | grep Mem | awk '{print $4}'"
|
"free_capacity_mb": "free -m | grep Mem | awk '{print $4}'"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Block_Storage",
|
||||||
|
"description": "{device_id} is of type {drive_type} with capacity of {drive_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_id": "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}}'",
|
||||||
|
"drive_capacity": "lsblk -d -o NAME,SIZE | grep {this_device} | awk '{{print $2}}'"
|
||||||
|
},
|
||||||
|
"metrics": {
|
||||||
|
"smart_status": "sudo smartctl -x --json /dev/{this_device} | jq -r .smart_status.passed",
|
||||||
|
"ssd_endurance_string": "sudo smartctl -x --json /dev/{this_device} | jq -r '.physical_block_size as $block |.ata_device_statistics.pages[] | select(.name == \"General Statistics\") | .table[] | select(.name == \"Logical Sectors Written\") | .value as $sectors | ($sectors * $block) / 1073741824 ' | awk '{{printf \"%.2f GiB Written\\n\", $0}}' || true",
|
||||||
|
"nvme_endurance_string": "sudo smartctl -x --json /dev/{this_device} | jq -r ' .nvme_smart_health_information_log.data_units_written as $dw | .logical_block_size as $ls | ($dw * $ls) / 1073741824 ' | awk '{{printf \"%.2f GiB Written\\n\", $0}}' || true"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -1,32 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Matt-Cloud Cosmostat</title>
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="src/styles.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<h2>Matt-Cloud Cosmostat Dashboard</h2>
|
|
||||||
This dashboard shows the local Matt-Cloud system stats.<p>
|
|
||||||
</div>
|
|
||||||
<div class="container">
|
|
||||||
<h2>System Stats</h2>
|
|
||||||
<div id="host_stats" class="column">Connecting…</div>
|
|
||||||
</div>
|
|
||||||
<!--
|
|
||||||
Here will go the graphs once i have all the stats first
|
|
||||||
<div class="container">
|
|
||||||
<h2>System Graphs</h2>
|
|
||||||
<div id="host_graphs" class="column">Connecting…</div>
|
|
||||||
</div>
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Socket.IO client library -->
|
|
||||||
<script src="socket.io/socket.io.js"></script>
|
|
||||||
<!-- matt-cloud redis script -->
|
|
||||||
<script src="src/redis.js"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,181 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>Matt-Cloud Cosmostat</title>
|
|
||||||
|
|
||||||
|
|
||||||
<link rel="stylesheet" href="styles.css">
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="container">
|
|
||||||
<h2>Matt-Cloud Cosmostat Dashboard</h2>
|
|
||||||
This dashboard shows the local Matt-Cloud system stats.<p>
|
|
||||||
</div>
|
|
||||||
<div class="container">
|
|
||||||
<h2>System Stats</h2>
|
|
||||||
<div id="host_stats" class="column">Connecting...</div>
|
|
||||||
</div>
|
|
||||||
<!--
|
|
||||||
Here will go the graphs once i have all the stats first
|
|
||||||
-->
|
|
||||||
<div class="container">
|
|
||||||
<h2>System Graphs</h2>
|
|
||||||
<div id="host_graphs" class="column">
|
|
||||||
<div id="history_graphs" class="container">
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Socket.IO client library -->
|
|
||||||
<script src="socket.io/socket.io.js"></script>
|
|
||||||
<script>
|
|
||||||
|
|
||||||
const socket = io();
|
|
||||||
|
|
||||||
// listen for redis updates, render and error handle
|
|
||||||
socket.on('host_stats', renderStatsTable);
|
|
||||||
|
|
||||||
socket.on('connect_error', err => {
|
|
||||||
safeSetText('host_stats', `Could not connect to server - ${err.message}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
socket.on('reconnect', attempt => {
|
|
||||||
safeSetText('host_stats', `Re-connected (attempt ${attempt})`);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function safeSetText(id, txt) {
|
|
||||||
const el = document.getElementById(id);
|
|
||||||
if (el) el.textContent = txt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// table rendering functions
|
|
||||||
function renderStatsTable(data) { renderGenericTable('host_stats', data, 'No Stats available'); }
|
|
||||||
|
|
||||||
function renderGenericTable(containerId, data, emptyMsg) {
|
|
||||||
const container = document.getElementById(containerId);
|
|
||||||
if (!Array.isArray(data) || !data.length) {
|
|
||||||
container.textContent = emptyMsg;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const table = renderTable(data);
|
|
||||||
container.innerHTML = '';
|
|
||||||
container.appendChild(table);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderTable(data) {
|
|
||||||
// Columns are inferred from the first object (order matters)
|
|
||||||
const cols = Object.keys(data[0]);
|
|
||||||
// Create table
|
|
||||||
const table = document.createElement('table');
|
|
||||||
// Header
|
|
||||||
const thead = table.createTHead();
|
|
||||||
const headerRow = thead.insertRow();
|
|
||||||
cols.forEach(col => {
|
|
||||||
const th = document.createElement('th');
|
|
||||||
th.textContent = col;
|
|
||||||
headerRow.appendChild(th);
|
|
||||||
});
|
|
||||||
// Body
|
|
||||||
const tbody = table.createTBody();
|
|
||||||
data.forEach(item => {
|
|
||||||
const tr = tbody.insertRow();
|
|
||||||
cols.forEach(col => {
|
|
||||||
const td = tr.insertCell();
|
|
||||||
td.textContent = item[col];
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return table;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
|
|
||||||
// ────────────────────── Globals ──────────────────────
|
|
||||||
const chartInstances = {}; // {metricName: Chart}
|
|
||||||
const colorPalette = [
|
|
||||||
'#ff6384', '#36a2eb', '#ffcd56', '#4bc0c0',
|
|
||||||
'#9966ff', '#ff9f40', '#8e5ea2', '#3e95cd'
|
|
||||||
];
|
|
||||||
|
|
||||||
// ────────────────────── Socket.io ──────────────────────
|
|
||||||
socket.on('history_stats', renderHistoryGraphs);
|
|
||||||
|
|
||||||
// ────────────────────── Rendering ──────────────────────
|
|
||||||
function renderHistoryGraphs(components) {
|
|
||||||
// 1️⃣ Sanity check – components is an array of objects
|
|
||||||
if (!Array.isArray(components) || !components.length) {
|
|
||||||
console.warn('history_stats payload is empty or malformed');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2️⃣ Clean up any old charts & canvases
|
|
||||||
Object.values(chartInstances).forEach(ch => ch.destroy());
|
|
||||||
chartInstances = {}; // reset map
|
|
||||||
const container = document.getElementById('history_graphs');
|
|
||||||
container.innerHTML = ''; // empty the container
|
|
||||||
|
|
||||||
// 3️⃣ For each component create a canvas & a Chart
|
|
||||||
components.forEach((comp, idx) => {
|
|
||||||
const metricName = comp.info?.metric_name || comp.info?.name || `component-${idx+1}`;
|
|
||||||
|
|
||||||
// 3a. Create a canvas element
|
|
||||||
const canvas = document.createElement('canvas');
|
|
||||||
canvas.id = `chart-${metricName}`;
|
|
||||||
canvas.width = 800; // optional – you can use CSS instead
|
|
||||||
canvas.height = 400;
|
|
||||||
canvas.style.marginBottom = '2rem';
|
|
||||||
|
|
||||||
// 3b. Append the canvas to the container
|
|
||||||
container.appendChild(canvas);
|
|
||||||
|
|
||||||
// 3c. Build the dataset for this component
|
|
||||||
const history = comp.history?.history_data || [];
|
|
||||||
const dataPoints = history.map(d => ({
|
|
||||||
x: new Date(d.timestamp * 1000), // convert seconds → ms
|
|
||||||
y: parseFloat(d.value) // values are strings in Redis
|
|
||||||
}));
|
|
||||||
|
|
||||||
const dataset = {
|
|
||||||
label: metricName,
|
|
||||||
data: dataPoints,
|
|
||||||
borderColor: colorPalette[idx % colorPalette.length],
|
|
||||||
fill: false,
|
|
||||||
tension: 0.1
|
|
||||||
};
|
|
||||||
|
|
||||||
// 3d. Create the chart
|
|
||||||
const ctx = canvas.getContext('2d');
|
|
||||||
chartInstances[metricName] = new Chart(ctx, {
|
|
||||||
type: 'line',
|
|
||||||
data: { datasets: [dataset] },
|
|
||||||
options: {
|
|
||||||
responsive: true,
|
|
||||||
maintainAspectRatio: false,
|
|
||||||
plugins: {
|
|
||||||
legend: { position: 'bottom' },
|
|
||||||
tooltip: { mode: 'index', intersect: false }
|
|
||||||
},
|
|
||||||
scales: {
|
|
||||||
x: {
|
|
||||||
type: 'time',
|
|
||||||
time: { unit: 'minute', tooltipFormat: 'YYYY‑MM‑DD HH:mm:ss' },
|
|
||||||
title: { display: true, text: 'Time' }
|
|
||||||
},
|
|
||||||
y: {
|
|
||||||
title: { display: true, text: 'Value' },
|
|
||||||
beginAtZero: false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
Reference in New Issue
Block a user