-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sql-logging.js
More file actions
44 lines (36 loc) · 1.86 KB
/
Copy pathtest-sql-logging.js
File metadata and controls
44 lines (36 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { DatabaseUtils } = require('./dist/agent/agent/services/db-utils');
async function testSQLLogging() {
try {
console.log('Testing SQL logging functionality...');
const dbUtils = new DatabaseUtils();
// Get database statistics
const stats = await dbUtils.getDatabaseStats();
console.log('Database Statistics:');
console.log('- Total events:', stats.totalEvents);
console.log('- Events by type:', stats.eventsByType);
console.log('- Events by date (last 30 days):', stats.eventsByDate);
if (stats.totalEvents === 0) {
console.log('\nNo events found in database. This is expected if the agent has not been running.');
console.log('To generate events, start the application and perform some activities.');
console.log('The SQL logger will automatically log events alongside Kafka streaming.');
} else {
// Get recent events
const recentEvents = await dbUtils.getRecentEvents(10);
console.log('\nRecent Events (last 10):');
recentEvents.forEach((event, index) => {
console.log(`${index + 1}. ${event.event_type} - ${event.timestamp} - ${event.app_name || event.file_name || 'N/A'}`);
});
// Get events by type
const appEvents = await dbUtils.getEventsByType('APP_ACTIVE', 5);
console.log('\nRecent App Events (last 5):');
appEvents.forEach((event, index) => {
console.log(`${index + 1}. ${event.app_name} - ${event.window_title || 'N/A'} - ${event.timestamp}`);
});
}
console.log('\nSQL logging test completed successfully!');
} catch (error) {
console.error('Error testing SQL logging:', error);
}
}
// Run the test
testSQLLogging();