Skip to content

Commit f503b2c

Browse files
committed
Add CPU utilization update demo and related configurations. Introduce new environment variables for CPU utilization CSV path and dry run mode in .env.example. Update README with detailed instructions for the CPU utilization update demo, including CSV format requirements and usage examples. Enhance .gitignore to exclude the data directory and add new npm scripts for CPU utilization demo.
1 parent 924dffb commit f503b2c

File tree

9 files changed

+645
-6
lines changed

9 files changed

+645
-6
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ LOG_LEVEL=info
55
BULK_BATCH_SIZE=50
66
BULK_CONCURRENT_BATCHES=3
77
BULK_RETRY_ATTEMPTS=3
8-
BULK_RETRY_DELAY=1000
8+
BULK_RETRY_DELAY=1000
9+
CPU_UTILIZATION_CSV_PATH=data-examples/server-utilization.csv
10+
DRY_RUN=false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
plans/
22
TODO.md
33
backups/
4+
data/
45

56
# Dependencies
67
node_modules/

README.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ TIDAL_WORKSPACE=your_workspace_name
3131
TIDAL_USERNAME=your_username
3232
TIDAL_PASSWORD=your_password
3333
LOG_LEVEL=info
34-
BULK_BATCH_SIZE=50
35-
BULK_CONCURRENT_BATCHES=3
36-
BULK_RETRY_ATTEMPTS=3
37-
BULK_RETRY_DELAY=1000
34+
BULK_BATCH_SIZE=5
35+
BULK_CONCURRENT_BATCHES=1
36+
BULK_RETRY_ATTEMPTS=5
37+
BULK_RETRY_DELAY=2000
38+
CPU_UTILIZATION_CSV_PATH=data-examples/server-utilization.csv
39+
DRY_RUN=false
3840
```
3941

4042
The base URL is automatically generated as `https://{workspace}.tidal.cloud/api/v1`.
@@ -107,9 +109,54 @@ Or run directly:
107109
npx ts-node examples/server-backup-demo.ts
108110
```
109111

112+
### CPU Utilization Update Demo
113+
114+
Updates server custom fields with CPU utilization data from CSV. Configure the CSV file path in your `.env` file using `CPU_UTILIZATION_CSV_PATH`.
115+
116+
**CSV Format Requirements:**
117+
```csv
118+
Name,CPU Utilization %,Memory Utilization %,Disk Utilization % (Peak)
119+
server01,25.5,65.2,45.3
120+
server02,78.9,92.1,67.8
121+
```
122+
123+
**Dry Run Mode:**
124+
Preview changes before applying them:
125+
126+
```bash
127+
# Using npm script (recommended)
128+
npm run demo:cpu-utilization:dry-run
129+
130+
# Using command line flag
131+
npx ts-node examples/cpu-utilization-update-demo.ts --dry-run
132+
133+
# Using environment variable
134+
DRY_RUN=true npm run demo:cpu-utilization
135+
```
136+
137+
**Apply Changes:**
138+
```bash
139+
npm run demo:cpu-utilization
140+
```
141+
142+
Or run directly:
143+
144+
```bash
145+
npx ts-node examples/cpu-utilization-update-demo.ts
146+
```
147+
148+
**Rate Limiting:**
149+
The demo includes built-in rate limiting protection:
150+
- Sequential processing (not concurrent) to avoid overwhelming the API
151+
- 500ms delays between individual API calls
152+
- 2-3 second delays between batches
153+
- Automatic retry with exponential backoff for 429 errors
154+
- Conservative batch sizes (5 records per batch)
155+
110156
### Available Examples
111157

112158
- `basic-authentication.ts` - Authentication methods and client setup
159+
- `cpu-utilization-update-demo.ts` - Update server custom fields from CSV data
113160
- `server-backup-demo.ts` - Server backup operations
114161
- `hostname-to-fqdn-demo.ts` - Hostname to FQDN conversion
115162
- `hostname-to-tag-demo.ts` - Hostname to tag operations

data-examples/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Data Directory
2+
3+
This directory contains sample data files used by the examples.
4+
5+
## server-utilization.csv
6+
7+
Sample CSV file for the CPU utilization update demo. This file demonstrates the required format for importing server utilization data.
8+
9+
### Format Requirements
10+
11+
The CSV file must have the following structure:
12+
13+
```csv
14+
Name,CPU Utilization %,Memory Utilization %,Disk Utilization % (Peak)
15+
server01,25.5,65.2,45.3
16+
server02,78.9,92.1,67.8
17+
```
18+
19+
### Column Descriptions
20+
21+
- **Name**: Server hostname (must match hostnames in your Tidal workspace)
22+
- **CPU Utilization %**: CPU utilization percentage (used to update the `cpu-util-manual-pct` custom field)
23+
- **Memory Utilization %**: Memory utilization percentage (currently for reference only)
24+
- **Disk Utilization % (Peak)**: Peak disk utilization percentage (currently for reference only)
25+
26+
### Usage
27+
28+
1. Replace the sample data with your actual server utilization data
29+
2. Ensure server names match the hostnames in your Tidal workspace
30+
3. Configure the path in your `.env` file:
31+
```env
32+
CPU_UTILIZATION_CSV_PATH=data-examples/server-utilization.csv
33+
```
34+
4. Run the demo:
35+
```bash
36+
npm run demo:cpu-utilization
37+
```
38+
39+
### Notes
40+
41+
- Rows with missing or invalid CPU utilization data (empty or "-") will be skipped
42+
- The demo will search for exact hostname matches (case-insensitive)
43+
- Servers not found in Tidal will be reported in the failed updates section

data-examples/server-utilization.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Name,CPU Utilization %,Memory Utilization %,Disk Utilization % (Peak)
2+
server01,25.5,65.2,45.3
3+
server02,78.9,92.1,67.8
4+
web-server-01,45.2,78.5,34.6
5+
db-server-01,89.3,95.7,78.2
6+
app-server-01,34.7,56.8,23.9
7+
web-server-02,52.1,71.3,56.4
8+
db-server-02,91.2,88.9,82.1
9+
cache-server-01,12.8,34.5,15.7
10+
api-server-01,67.4,82.3,49.5
11+
load-balancer-01,23.6,45.8,12.3

0 commit comments

Comments
 (0)