API Reference
Complete API documentation for the VigilAI SDK. Available for TypeScript/JavaScript and Python.
VigilAI
Main SDK class for monitoring and incident management.
Constructor
new VigilAI(config: VigilAIConfig)
| Parameter | Type | Required | Description |
|---|---|---|---|
config |
VigilAIConfig |
Yes | Configuration object for the SDK |
Methods
initialize()
Initialize the SDK and validate API key. Must be called before using other methods.
async initialize(): Promise<void>
// Example
const vigilai = new VigilAI({ apiKey: 'your-key' });
await vigilai.initialize();
expressMiddleware()
Returns Express.js middleware for automatic monitoring.
expressMiddleware(): (req: Request, res: Response, next: NextFunction) => void
// Example
import express from 'express';
const app = express();
app.use(vigilai.expressMiddleware());
nextMiddleware()
Returns Next.js middleware for automatic monitoring.
async nextMiddleware(
request: NextRequest,
handler: (req: NextRequest) => Promise<NextResponse>
): Promise<NextResponse>
django_middleware()
Returns Django middleware class for automatic monitoring.
fastapi_middleware()
Returns FastAPI middleware for automatic monitoring.
trackMetric()
Track a custom metric value.
trackMetric(name: string, value: number): void
| Parameter | Type | Description |
|---|---|---|
name |
string |
Metric name (e.g., 'user.login.count') |
value |
number |
Numeric metric value |
// Example
vigilai.trackMetric('user.login.count', 1);
vigilai.trackMetric('cache.hit_rate', 0.95);
vigilai.trackMetric('queue.size', 42);
trackError()
Track an error with optional context information.
trackError(error: Error, context?: Record<string, any>): void
| Parameter | Type | Required | Description |
|---|---|---|---|
error |
Error |
Yes | Error object to track |
context |
object |
No | Additional context information |
// Example
try {
await performDatabaseQuery();
} catch (error) {
vigilai.trackError(error as Error, {
operation: 'database_query',
userId: '12345',
query: 'SELECT * FROM users'
});
}
healthCheck()
Get SDK health status and metrics.
healthCheck(): HealthStatus
// Example
const health = vigilai.healthCheck();
console.log(health.status); // 'healthy' | 'degraded' | 'unhealthy'
console.log(health.metrics.bufferSize);
console.log(health.metrics.transmissionSuccessRate);
shutdown()
Gracefully shutdown the SDK and flush remaining data.
async shutdown(): Promise<void>
// Example
process.on('SIGTERM', async () => {
await vigilai.shutdown();
process.exit(0);
});
Configuration
Configuration options for the VigilAI SDK.
VigilAIConfig
interface VigilAIConfig {
apiKey: string;
monitoring?: MonitoringConfig;
thresholds?: ThresholdsConfig;
anomalyDetection?: AnomalyDetectionConfig;
security?: SecurityConfig;
}
| Property | Type | Required | Description |
|---|---|---|---|
apiKey |
string |
Yes | Your VigilAI API key |
monitoring |
MonitoringConfig |
No | Monitoring configuration |
thresholds |
ThresholdsConfig |
No | Performance thresholds |
anomalyDetection |
AnomalyDetectionConfig |
No | Anomaly detection settings |
security |
SecurityConfig |
No | Security and privacy settings |
MonitoringConfig
interface MonitoringConfig {
interval?: number; // Default: 60000 (60 seconds)
samplingRate?: number; // Default: 1.0 (100%)
bufferSize?: number; // Default: 1000
}
ThresholdsConfig
interface ThresholdsConfig {
responseTime?: number; // Default: 1000 (ms)
errorRate?: number; // Default: 5 (%)
memoryUsage?: number; // Default: 500 (MB)
cpuUsage?: number; // Default: 80 (%)
}
AnomalyDetectionConfig
interface AnomalyDetectionConfig {
sensitivity?: number; // Default: 2 (Z-score)
deduplicationWindow?: number; // Default: 300000 (5 minutes)
}
SecurityConfig
interface SecurityConfig {
enablePIIRedaction?: boolean; // Default: true
dataRetentionPeriod?: number; // Default: 7 days
redactionRules?: RedactionRule[];
}
Types
HealthStatus
interface HealthStatus {
status: 'healthy' | 'degraded' | 'unhealthy';
metrics: {
bufferSize: number;
transmissionSuccessRate: number;
lastTransmission: string;
};
}
Incident
interface Incident {
id: string;
type: 'error' | 'performance' | 'anomaly';
severity: 'low' | 'medium' | 'high' | 'critical';
description: string;
timestamp: number;
metadata: Record<string, any>;
}