201 előtti mentés
This commit is contained in:
@@ -83,26 +83,42 @@ const generateMockAlerts = (count: number = 5): SystemAlert[] => {
|
||||
|
||||
// API Service
|
||||
class HealthMonitorApiService {
|
||||
private baseUrl = 'http://localhost:8000/api/v1/admin' // Should come from environment config
|
||||
private baseUrl = '/api/v1/admin' // Using proxy from nuxt.config.ts
|
||||
private delay = (ms: number) => new Promise(resolve => setTimeout(resolve, ms))
|
||||
|
||||
// Get health metrics
|
||||
async getHealthMetrics(): Promise<HealthMetrics> {
|
||||
// In a real implementation, this would call the actual API
|
||||
// const response = await fetch(`${this.baseUrl}/health-monitor`, {
|
||||
// headers: this.getAuthHeaders()
|
||||
// })
|
||||
//
|
||||
// if (!response.ok) {
|
||||
// throw new Error(`HTTP ${response.status}: ${response.statusText}`)
|
||||
// }
|
||||
//
|
||||
// return await response.json()
|
||||
|
||||
await this.delay(800) // Simulate network delay
|
||||
|
||||
// For now, return mock data
|
||||
return generateMockMetrics()
|
||||
try {
|
||||
console.log('Fetching health metrics from:', `${this.baseUrl}/health-monitor`)
|
||||
const response = await fetch(`${this.baseUrl}/health-monitor`, {
|
||||
headers: this.getAuthHeaders()
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text()
|
||||
console.error('Health monitor API error:', response.status, response.statusText, errorText)
|
||||
throw new Error(`HTTP ${response.status}: ${response.statusText} - ${errorText}`)
|
||||
}
|
||||
|
||||
const data = await response.json()
|
||||
console.log('Health monitor API response:', data)
|
||||
|
||||
// Transform API response to match HealthMetrics interface
|
||||
return {
|
||||
total_assets: data.total_assets || 0,
|
||||
total_organizations: data.total_organizations || 0,
|
||||
critical_alerts_24h: data.critical_alerts_24h || 0,
|
||||
system_status: 'healthy', // Default, API doesn't return this yet
|
||||
uptime_percentage: 99.9, // Default, API doesn't return this yet
|
||||
response_time_ms: 50, // Default, API doesn't return this yet
|
||||
database_connections: 0, // Default, API doesn't return this yet
|
||||
active_users: data.user_distribution ? Object.values(data.user_distribution).reduce((a: number, b: number) => a + b, 0) : 0,
|
||||
last_updated: new Date().toISOString()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch real health metrics:', error)
|
||||
throw error // Don't fall back to mock data - let the caller handle it
|
||||
}
|
||||
}
|
||||
|
||||
// Get system alerts
|
||||
|
||||
Reference in New Issue
Block a user