Advertisement
danielcristho

aggregate_minutes_to_hourly_log.sh

Mar 23rd, 2024 (edited)
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.77 KB | None | 0 0
  1. #!/bin/bash
  2. OUTPUT=$(date "+%Y%m%d%H")
  3.  
  4. max_mem_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $1}' | sort | tail -1)
  5. min_mem_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $1}' | sort | head -1)
  6. avg_mem_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $1; count++ }
  7. END { print total/count }')
  8. avg_mem_total=${avg_mem_total/,/.}
  9.  
  10. max_mem_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $2}' | sort | tail -1)
  11. min_mem_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $2}' | sort | head -1)
  12. avg_mem_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $2; count++ }
  13. END { print total/count }')
  14. avg_mem_used=${avg_mem_used/,/.}
  15.  
  16. max_mem_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $3}' | sort | tail -1)
  17. min_mem_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $3}' | sort | head -1)
  18. avg_mem_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $3; count++ }
  19. END { print total/count }')
  20. avg_mem_free=${avg_mem_free/,/.}
  21.  
  22. max_mem_shared=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $4}' | sort | tail -1)
  23. min_mem_shared=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $4}' | sort | head -1)
  24. avg_mem_shared=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $4; count++ }
  25. END { print total/count }')
  26. avg_mem_shared=${avg_mem_shared/,/.}
  27.  
  28. max_mem_buff=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $5}' | sort | tail -1)
  29. min_mem_buff=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $5}' | sort | head -1)
  30. avg_mem_buff=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $5; count++ }
  31. END { print total/count }')
  32. avg_mem_buff=${avg_mem_buff/,/.}
  33.  
  34. max_mem_avail=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $6}' | sort | tail -1)
  35. min_mem_avail=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $6}' | sort | head -1)
  36. avg_mem_avail=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $6; count++ }
  37. END { print total/count }')
  38. avg_mem_avail=${avg_mem_avail/,/.}
  39.  
  40. max_swap_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $7}' | sort | tail -1)
  41. min_swap_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $7}' | sort | head -1)
  42. avg_swap_total=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $7; count++ }
  43. END { print total/count }')
  44. avg_swap_total=${avg_swap_total/,/.}
  45.  
  46. max_swap_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $8}' | sort | tail -1)
  47. min_swap_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $8}' | sort | head -1)
  48. avg_swap_used=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $8; count++ }
  49. END { print total/count }')
  50. avg_swap_used=${avg_swap_used/,/.}
  51.  
  52. max_swap_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $9}' | sort | tail -1)
  53. min_swap_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{print $9}' | sort | head -1)
  54. avg_swap_free=$(cat /home/{user}/metrics/metrics_$OUTPUT*.log | grep /home/ | awk -F "," '{ total += $9; count++ }
  55. END { print total/count }')
  56. avg_swap_free=${avg_swap_free/,/.}
  57.  
  58. echo "type,mem_total,mem_used,mem_free,mem_shared,mem_buff,mem_available,swap_total,swap_used,swap_free,path,path_size" > /home/{user}/metrics/metrics_agg_$OUTPUT.log
  59. echo "minimum,$min_mem_total,$min_mem_used,$min_mem_free,$min_mem_shared,$min_mem_buff,$min_mem_avail,$min_swap_total,$min_swap_used,$min_swap_free,/home/{user}/,$min_path_size" >> /home/{user}/metrics/metrics_agg_$OUTPUT.log
  60. echo "maximum,$max_mem_total,$max_mem_used,$max_mem_free,$max_mem_shared,$max_mem_buff,$max_mem_avail,$max_swap_total,$max_swap_used,$max_swap_free,/home/{user}/,$max_path_size" >> /home/{user}/metrics/metrics_agg_$OUTPUT.log
  61. echo "average,$avg_mem_total,$avg_mem_used,$avg_mem_free,$avg_mem_shared,$avg_mem_buff,$avg_mem_avail,$avg_swap_total,$avg_swap_used,$avg_swap_free,/home/{user}/,$avg_path_size" >> /home/{user}/metrics/metrics_agg_$OUTPUT.log
  62.  
  63. chmod u+x ./aggregate_minutes_to_hourly_log.sh
  64. chmod 400 /home/{user}/metrics/metrics_agg_$OUTPUT.log
  65.  
  66. # 59 * * * * /home/{user}/aggregate_minutes_to_hourly_log.sh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement