info_stats.sh 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/bash
  2. # LinuxGSM info_stats.sh function
  3. # Author: Daniel Gibbs
  4. # Website: https://linuxgsm.com
  5. # Description: Optional Stats to send to LinuxGSM Developer
  6. # Uses Google analytics
  7. info_distro.sh
  8. # generate uuid
  9. if [ ! -f "${datadir}/uuid.txt" ];then
  10. mkdir -p "${datadir}"
  11. touch "${datadir}/uuid.txt"
  12. if [ -n "$(command -v uuidgen 2>/dev/null)" ]; then
  13. uuidgen > "${datadir}/uuid.txt"
  14. else
  15. cat /proc/sys/kernel/random/uuid > "${datadir}/uuid.txt"
  16. fi
  17. fi
  18. uuid=$(cat "${datadir}/uuid.txt")
  19. # results are rounded up to reduce number of different results in analytics
  20. # nearest 100Mhz
  21. cpuusedmhzroundup=$(((cpuusedmhz + 99) / 100 * 100))
  22. # nearest 100MB
  23. memusedroundup=$(((memused + 99) / 100 * 100))
  24. # Level 1 Stats
  25. ## Distro
  26. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=distro" -d "ea=${gamename}" -d "el=${distroname}" -d "v=1" > /dev/null 2>&1
  27. ## Game Server Name
  28. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=game" -d "ea=${gamename}" -d "el=${gamename}" -d "v=1" > /dev/null 2>&1
  29. ## Game Server Name
  30. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=version" -d "ea=${version}" -d "el=${version}" -d "v=1" > /dev/null 2>&1
  31. # Level 2 Stats
  32. ## CPU usage of a game server
  33. if [ "${cpuusedmhzroundup}" ]; then
  34. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=cpuused" -d "ea=${gamename}" -d "el=${cpuusedmhzroundup}MHz" -d "v=1" > /dev/null 2>&1
  35. fi
  36. ## Ram usage of a game server
  37. if [ "${memusedroundup}" ]; then
  38. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=ramused" -d "ea=${gamename}" -d "el=${memusedroundup}MB" -d "v=1" > /dev/null 2>&1
  39. fi
  40. ## Disk usage of a game server
  41. if [ "${serverfilesdu}" ]; then
  42. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=diskused" -d "ea=${gamename}" -d "el=${serverfilesdu}" -d "v=1" > /dev/null 2>&1
  43. fi
  44. # Level 3 Stats
  45. ## CPU Model
  46. if [ "${cpumodel}" ]; then
  47. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=servercpu" -d "ea=${gamename}" -d "el=${cpumodel} cores:${cpucores}" -d "v=1" > /dev/null 2>&1
  48. fi
  49. ## Server RAM
  50. if [ "${physmemtotal}" ]; then
  51. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=serverram" -d "ea=${gamename}" -d "el=${physmemtotal}" -d "v=1" > /dev/null 2>&1
  52. fi
  53. ## Server Disk
  54. if [ "${totalspace}" ]; then
  55. curl https://www.google-analytics.com/collect -d "tid=UA-655379-31" -d "aip=1" -d "cid=${uuid}" -d "t=event" -d "ec=serverdisk" -d "ea=${gamename}" -d "el=${totalspace}" -d "v=1" > /dev/null 2>&1
  56. fi
  57. fn_script_log_info "Send LinuxGSM stats"
  58. fn_script_log_info "* UUID: ${uuid}"
  59. fn_script_log_info "* Game Name: ${gamename}"
  60. fn_script_log_info "* Distro Name: ${distroname}"
  61. fn_script_log_info "* Game Server CPU Used: ${cpuusedmhzroundup}MHz"
  62. fn_script_log_info "* Game Server RAM Used: ${memusedroundup}MB"
  63. fn_script_log_info "* Game Server Disk Used: ${serverfilesdu}"
  64. fn_script_log_info "* Server CPU Model: ${cpumodel}"
  65. fn_script_log_info "* Server RAM: ${physmemtotal}"
  66. fn_script_log_info "* Server Disk: ${totalspace}"