/
/
/
1#!/bin/bash
2# NAS Performance Monitoring Script
3# Generated by Ansible NAS role
4
5LOG_FILE="{{ nas_log_file }}"
6TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
7
8log_performance() {
9 echo "[$TIMESTAMP] PERFORMANCE: $1" >> "$LOG_FILE"
10}
11
12# Monitor network throughput
13monitor_network() {
14 for interface in $(ls /sys/class/net/ | grep -E '^(eth|bond|ens)'); do
15 if [ -f "/sys/class/net/$interface/statistics/rx_bytes" ] && [ -f "/sys/class/net/$interface/statistics/tx_bytes" ]; then
16 rx_bytes=$(cat /sys/class/net/$interface/statistics/rx_bytes)
17 tx_bytes=$(cat /sys/class/net/$interface/statistics/tx_bytes)
18 log_performance "$interface: RX=$(($rx_bytes/1024/1024))MB TX=$(($tx_bytes/1024/1024))MB"
19 fi
20 done
21}
22
23# Monitor disk I/O
24monitor_disk_io() {
25 iostat -d 1 1 | awk 'NR>3 {print $1 " read:" $3 " write:" $4}' | while read line; do
26 log_performance "DISK I/O: $line"
27 done 2>/dev/null || true
28}
29
30# Monitor NFS statistics
31monitor_nfs() {
32 if [ -f /proc/net/rpc/nfsd ]; then
33 nfs_calls=$(awk '/proc4/ {print $3}' /proc/net/rpc/nfsd)
34 log_performance "NFS calls: $nfs_calls"
35 fi
36}
37
38# Monitor memory usage
39monitor_memory() {
40 mem_info=$(free -m | awk 'NR==2{printf "Memory: %.1f%% used", $3*100/$2}')
41 log_performance "$mem_info"
42}
43
44# Main execution
45if [ "{{ nas_performance_tuning_enabled | bool | lower }}" = "true" ]; then
46 monitor_network
47 monitor_disk_io
48 monitor_nfs
49 monitor_memory
50fi