Setting and Managing Swarm Log Levels with script
- 1 Managing Log Levels in Swarm Cluster Using a Shell Script
- 1.1 Script Features
- 1.2 Requirements
- 1.3 Script Usage
- 1.4 Instruction for Use
- 1.4.2 Behavior
- 1.4.2.1 Output Messages
- 1.4.3 Example Output
- 1.4.4 Error Handling
- 1.5 Notes
- 1.6 Script Source Code
Managing Log Levels in Swarm Cluster Using a Shell Script
The Swarm Log Level Management Script (castor-change-log-level.sh
) is designed to manage and dynamically adjust log levels on a DataCore Swarm cluster, providing options to change the log level temporarily and automatically revert it after a specified duration. It supports background execution via screen
or tmux
, making it ideal for long-running operations that require detachment from the terminal.
Script Features
Set and Revert Log Levels: Temporarily change the log level and revert after a specified duration.
Flexible JSON Parsing: Uses
jq
for JSON parsing if available; defaults togrep
otherwise.Detachable Session Execution: Runs in a detachable session using
screen
ortmux
, allowing the script to continue running independently of the terminal session.Log Size Monitoring: Reports the log size generated during the temporary log level change.
Countdown Display: Shows a countdown for the specified duration.
Requirements
jq (optional): Used for parsing JSON responses; falls back to
grep
if unavailable.screen or tmux (optional): Required for background execution.
Permissions: Ensure sufficient permissions to execute on the DataCore Swarm server and access required files.
Script Usage
./castor-change-log-level.sh -d <node_ip> -p <admin:password> -i <new_log_level> [-t <duration_in_seconds>] [--detach] [-v]
Parameter | Description |
---|---|
| IP address of the Swarm API endpoint (or set |
| Admin credentials in the format |
| New log level to set (values: |
| Duration in seconds to keep the new log level (optional). |
| Runs the script in a detachable session using |
Instruction for Use
Example 1: Set cluster log level to 20
and keep it for 10
minutes
./castor-change-log-level.sh -d 192.168.8.84 -p admin:datacore -i 20 -t 600
Example 2: Set node(s) log level to debug (10) and keep it for 10 minutes
./castor-change-log-level.sh -d 192.168.8.84,192.168.8.86 -p admin:datacore -i debug -t 600
Example 3: Run in background mode
Running the Script at a Specific Time
The at
command can used to schedule the script to run at a later time. This is useful when you need to start collecting debug logs at a specific hour.
Example 4: Schedule the script to run at 3:00 AM and collect debug logs for 1 hour
Ensure the at service is installed, enabled and running
Schedule the script execution using
at
:
This schedules the script to run at 3:00 AM on Feb 16 2025 and collects log at debug level for 1 hour.
To verify scheduled job:
To remove a scheduled job (replace
JOB_ID
with the actual job number fromatq
output):
Behavior
Log Level Change: Sets the log level to the specified value. If the current log level matches the requested level, the script skips the update.
Countdown: During the specified duration, the script displays a countdown every second.
Revert Log Level: After the countdown, the log level reverts to the initial value.
Log Size Report: Provides approximately log size generated during the temporary log level change.
Output Messages
Message | Description |
---|---|
| Displays the specified Swarm IP address. |
| Credentials are masked for security. |
| Displays the cluster name retrieved from the Swarm API. |
| Shows the new log level requested. |
| Displays the current log level. |
| Indicates the beginning of the log level update process. |
| Confirms that the log level was successfully updated. |
| Shows the temporary period for which the new log level is retained, with a countdown. |
| Indicates that the temporary period has ended and the script is reverting the log level. |
| Provides information on the amount of logging activity generated during the temporary log level. |
Example Output
Error Handling
Missing Parameters: Missing parameters prompt a usage message.
Invalid Duration: If a non-numeric duration is provided, you’re prompted to enter a valid duration in seconds.
Connection Issues: If unable to connect to the Swarm API, check the IP, credentials, and network access.
Notes
Credentials are masked in the output for security.
Log file sizes are shown in human-readable format (GB, MB, KB, B).
This script provides administrators with an effective way to adjust and monitor Swarm logging, supporting both temporary and permanent log level changes for troubleshooting and performance monitoring.
Script Source Code
Latest version: castor-change-log-level.sh
Related content
© DataCore Software Corporation. · https://www.datacore.com · All rights reserved.