feat: basic cluster overview
This commit is contained in:
74
src/client/example.js
Normal file
74
src/client/example.js
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
* Example usage of the SPORE API Client
|
||||
*/
|
||||
|
||||
const SporeApiClient = require('./index');
|
||||
|
||||
async function main() {
|
||||
// Create client instance
|
||||
const client = new SporeApiClient('http://10.0.1.60');
|
||||
|
||||
console.log('🚀 SPORE API Client Example');
|
||||
console.log('============================\n');
|
||||
|
||||
try {
|
||||
// Example 1: Get system status
|
||||
console.log('1. Getting system status...');
|
||||
const systemStatus = await client.getSystemStatus();
|
||||
console.log('✅ System Status:', JSON.stringify(systemStatus, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 2: Get task status
|
||||
console.log('2. Getting task status...');
|
||||
const taskStatus = await client.getTaskStatus();
|
||||
console.log('✅ Task Status:', JSON.stringify(taskStatus, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 3: Get device information
|
||||
console.log('3. Getting device information...');
|
||||
const deviceInfo = await client.getDeviceInfo();
|
||||
console.log('✅ Device Info:', JSON.stringify(deviceInfo, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 4: Get cluster discovery
|
||||
console.log('4. Getting cluster discovery...');
|
||||
const discovery = await client.getClusterDiscovery();
|
||||
console.log('✅ Cluster Discovery:', JSON.stringify(discovery, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 5: Get network configuration
|
||||
console.log('5. Getting network configuration...');
|
||||
const networkConfig = await client.getNetworkConfig();
|
||||
console.log('✅ Network Config:', JSON.stringify(networkConfig, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 6: Get health metrics
|
||||
console.log('6. Getting health metrics...');
|
||||
const healthMetrics = await client.getHealthMetrics();
|
||||
console.log('✅ Health Metrics:', JSON.stringify(healthMetrics, null, 2));
|
||||
console.log('');
|
||||
|
||||
// Example 7: Get system logs (limited to 5 entries)
|
||||
console.log('7. Getting recent system logs...');
|
||||
const logs = await client.getSystemLogs({ limit: 5 });
|
||||
console.log('✅ System Logs:', JSON.stringify(logs, null, 2));
|
||||
console.log('');
|
||||
|
||||
console.log('🎉 All API calls completed successfully!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error occurred:', error.message);
|
||||
|
||||
if (error.message.includes('fetch')) {
|
||||
console.log('\n💡 Make sure the SPORE device is running and accessible at the specified IP address.');
|
||||
console.log('💡 Check if the device is powered on and connected to the network.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Run the example if this file is executed directly
|
||||
if (require.main === module) {
|
||||
main().catch(console.error);
|
||||
}
|
||||
|
||||
module.exports = { main };
|
||||
Reference in New Issue
Block a user