Monitor your key metrics. Values can be edited directly on the dashboard or configured in the Data Configuration tab.
Configure Metrics
Add, edit, or remove metrics for your dashboard. Use the 'Apply Configuration' button to update the dashboard view.
${metric.description}
`;
if (metric.type === 'gauge') {
valueContent = `${metric.value}${metric.unit}`;
} else if (metric.type === 'status') {
const statusClass = `status-${metric.status.toLowerCase().replace(/\s/g, '-')}`;
valueContent = `${metric.status}`;
} else if (metric.type === 'bar') {
// For bar type, list the values in a simple table or list format
let barHtml = '
';
for (const key in metric.barValues) {
barHtml += `
${key}:${metric.barValues[key]}%
`;
}
barHtml += '
';
valueContent = barHtml;
} else if (metric.type === 'line') {
// For line type, just display the current value and unit
valueContent = `${metric.value}${metric.unit}`;
// Could add a simple trend indicator if desired
// valueContent += `↑`; // Example up arrow
}
metricCard.innerHTML = `
${metric.name}
${valueContent}
${descriptionContent}
`;
dashboardContentContainer.appendChild(metricCard);
});
// Attach event listeners for editable cells on the dashboard
dashboardContentContainer.querySelectorAll('.editable-cell').forEach(cell => {
cell.addEventListener('blur', function() {
// Update the underlying data when an editable cell is blurred
const metricId = this.id.split('-')[1]; // e.g., 'cpu_utilization' from 'value-cpu_utilization'
const metricIndex = dashboardMetrics.findIndex(m => m.id === metricId);
if (metricIndex !== -1) {
if (this.id.startsWith('value-')) {
dashboardMetrics[metricIndex].value = parseFloat(this.innerText) || 0;
} else if (this.id.startsWith('status-')) {
dashboardMetrics[metricIndex].status = this.innerText;
} else if (this.id.startsWith('bar-value-')) {
const category = this.id.split('-')[3]; // e.g., 'Web' from 'bar-value-app_error_rate-Web'
dashboardMetrics[metricIndex].barValues[category] = parseFloat(this.innerText) || 0;
}
// Re-render config to reflect changes if config tab is open
if (currentTab === 'dataConfig') {
renderConfigMetrics();
}
}
});
});
}
/**
* Renders the data configuration input fields based on dashboardMetrics.
*/
function renderConfigMetrics() {
configMetricsContainer.innerHTML = ''; // Clear existing config fields
dashboardMetrics.forEach((metric, index) => {
const metricConfigDiv = document.createElement('div');
metricConfigDiv.className = 'bg-blue-50 p-4 rounded-lg shadow-sm';
metricConfigDiv.innerHTML = `
Metric ${index + 1}: ${metric.name}
`;
configMetricsContainer.appendChild(metricConfigDiv);
// Call toggleMetricInputs to render initial specific inputs
window.toggleMetricInputs(index);
});
}
/**
* Toggles visibility of input fields based on metric type in config.
* @param {number} index - The index of the metric in dashboardMetrics.
*/
window.toggleMetricInputs = function(index) {
const typeSelect = document.getElementById(`configType${index}`);
const specificInputsDiv = document.getElementById(`metricSpecificInputs${index}`);
const currentMetric = dashboardMetrics[index];
if (!typeSelect || !specificInputsDiv || !currentMetric) return;
const selectedType = typeSelect.value;
let inputsHtml = '';
if (selectedType === 'gauge' || selectedType === 'line') {
inputsHtml = `