This Bash script is used to retrieve statistics for nodes in multiple clusters and generate a markdown table with the collected information.
Before using this script, make sure you have the following:
-
Cluster Authentication Files: You need to have the authentication files (
kubeconfig
) for each cluster you want to monitor. The authentication files should be located in the following directories:- Cluster 1:
/path/to/auth/cluster1/auth/kubeconfig
- Cluster 2:
/path/to/auth/cluster2/auth/kubeconfig
- Cluster 3:
/path/to/auth/cluster3/auth/kubeconfig
- Cluster 1:
-
SSH Access: The script uses SSH to execute commands on each node. Ensure that you have SSH access to the nodes using the specified username (
core
). You may need to configure SSH key-based authentication or provide the password interactively during script execution. -
Required Tools: The script relies on the following tools being installed and available in the specified paths:
oc
(OpenShift Command-Line Interface):/usr/local/bin/oc
Follow these steps to use the script:
- Open a terminal.
- Make sure the authentication files for the clusters are in the correct directories as mentioned in the prerequisites.
- Copy the script and save it as a Bash file, e.g.,
cluster_stats.sh
. - Open the script file in a text editor and modify the script variables if necessary:
clusters
: Update the array with the correct paths to the authentication files for your clusters.
clusters=(
"/path/to/auth/cluster1/auth/kubeconfig"
"/path/to/auth/cluster2/auth/kubeconfig"
"/path/to/auth/cluster3/auth/kubeconfig"
)
OC_PATH
: If theoc
command-line tool is installed in a different location, update theOC_PATH
variable accordingly.NODE_USR
: If the SSH username for node access is different fromcore
, modify theNODE_USR
variable.
- Save the changes to the script file.
- Make the script file executable by running the following command:
chmod +x cluster_stats.sh
- Run the script by executing the following command:
./cluster_stats.sh
-
The script will connect to each cluster, retrieve statistics for the nodes, and generate a markdown table with the collected information.
-
The generated table will be displayed in the terminal output. You can copy and paste the table into a markdown file or any other document as needed.
Note: The table includes the following columns: Cluster, Node, Total CPU, CPU Used, Total Memory (MB), Memory Used (MB), Total Disk (GB), Disk Used (GB).
-
This script assumes that the authentication files (
kubeconfig
) for each cluster are stored in the specified paths. Modify the script if your setup differs. -
The script relies on SSH access to the nodes using the specified username (
core
). Make sure you have the necessary SSH access and adjust theNODE_USR
variable if required. -
Ensure that the required tools, such as
oc
, are installed and accessible in the specified paths. Modify theOC_PATH
variable if the tool is installed in a different location. -
The script assumes the clusters are running OpenShift 4.6 or a compatible version. Modify the script if you are using a different version.
-
The script assumes the clusters are reachable and accessible from the machine running the script.
-
(Optional) If you encounter any issues or errors while running the script, ensure that you have the necessary permissions and dependencies installed correctly. Review the script variables and make sure they are set correctly for your environment.
-
Customize the script further if needed or integrate it into your automation workflows as required.