Skip to content

Commit 233e253

Browse files
authored
Given Table Growth Analysis (#2666)
* Create getMidServerAgentLog.js Code to get Mid server log file * Create README.md Readme docs about the script used to retrieve the agent log file on demand from the mid server * Create tableGrowthAnalysis.js Script to assess the given table growth in the instance * Add README md file Instructions about the usage of the script provided for assessing the given table growth
1 parent 41f736e commit 233e253

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Table Size Analysis Script
2+
3+
This script checks the number of records in selected ServiceNow tables and shows how many were created in the last 30 days.
4+
5+
## Tables Checked
6+
- `task`
7+
- `cmdb_ci`
8+
- `sc_cat_item`
9+
10+
## What It Does
11+
- Logs the start of the analysis.
12+
- Counts total records in each table.
13+
- Counts records created in the last 30 days.
14+
- Logs both counts to the system log.
15+
16+
## How to Use
17+
1. Add or remove table names in the `tablesToCheck` list.
18+
2. Run the script in a background script or scheduled job.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// === TABLE SIZE ANALYSIS SCRIPT ===
2+
// Log the start of the analysis
3+
gs.info('=== TABLE SIZE ANALYSIS ===');
4+
5+
// Define the list of tables to analyze
6+
var tablesToCheck = ['task', 'cmdb_ci', 'sc_cat_item'];
7+
8+
// Loop through each table in the list
9+
for (var i = 0; i < tablesToCheck.length; i++) {
10+
var tableName = tablesToCheck[i]; // Get current table name
11+
12+
// Create a GlideAggregate object to count total records in the table
13+
var grCount = new GlideAggregate(tableName);
14+
grCount.addAggregate('COUNT'); // Add COUNT aggregate
15+
grCount.query(); // Execute the query
16+
17+
// If the query returns a result
18+
if (grCount.next()) {
19+
var recordCount = grCount.getAggregate('COUNT'); // Get total record count
20+
gs.info('Table: ' + tableName + ' | Record count: ' + recordCount); // Log the count
21+
22+
// Optional: Analyze growth by checking records created in the last 30 days
23+
var grRecent = new GlideAggregate(tableName);
24+
grRecent.addAggregate('COUNT'); // Add COUNT aggregate
25+
grRecent.addQuery('sys_created_on', '>=', gs.daysAgo(30)); // Filter records created in last 30 days
26+
grRecent.query(); // Execute the query
27+
28+
// If the query returns a result
29+
if (grRecent.next()) {
30+
var recentCount = grRecent.getAggregate('COUNT'); // Get count of recent records
31+
gs.info(' - Records created last 30 days: ' + recentCount); // Log the recent count
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)