Browse Source

feat: Send stats to Google Analytics GA4

This commit adds the functionality to send server statistics to Google Analytics GA4. The payload includes metrics such as CPU usage, disk usage, memory usage, and server information. The data is sent using a POST request to the Google Analytics API.

The previous code that sent stats to the LinuxGSM stats endpoint has been removed.

Note: This commit does not include any specific file changes.
pull/4295/head
Daniel Gibbs 2 years ago
parent
commit
daa0f485ad
  1. 41
      lgsm/modules/info_stats.sh

41
lgsm/modules/info_stats.sh

@ -56,11 +56,7 @@ cpuusedmhzroundup="$(((cpuusedmhz + 99) / 100 * 100))"
# nearest 100MB # nearest 100MB
memusedroundup="$(((memused + 99) / 100 * 100))" memusedroundup="$(((memused + 99) / 100 * 100))"
# Spliting the metrics in to 3 propertys allows more accurate metrics on numbers of invidual instances, installs and hardware. # Sending stats to Google Analytics GA4
# Instance Property - UA-165287622-1
# Install Property - UA-165287622-2
# Hardware Property - UA-165287622-3
payload="{ payload="{
\"client_id\": \"${uuidinstance}\", \"client_id\": \"${uuidinstance}\",
\"events\": [ \"events\": [
@ -99,7 +95,6 @@ if [ "${telegramalert}" == "on" ]; then
payload="${payload} \"alert\": \"telegram\"," payload="${payload} \"alert\": \"telegram\","
fi fi
payload="${payload} payload="${payload}
\"cpuusedmhzroundup\": \"${cpuusedmhzroundup}MHz\", \"cpuusedmhzroundup\": \"${cpuusedmhzroundup}MHz\",
\"diskused\": \"${serverfilesdu}\", \"diskused\": \"${serverfilesdu}\",
@ -124,40 +119,6 @@ payload="${payload}
curl -X POST "https://www.google-analytics.com/mp/collect?api_secret=A-OzP02TSMWt4_vHi6ZpUw&measurement_id=G-0CR8V7EMT5" -H "Content-Type: application/json" -d "${payload}" curl -X POST "https://www.google-analytics.com/mp/collect?api_secret=A-OzP02TSMWt4_vHi6ZpUw&measurement_id=G-0CR8V7EMT5" -H "Content-Type: application/json" -d "${payload}"
curl -X POST https://stats.linuxgsm.com/api/event \
-H 'User-Agent: curl' \
-H 'Content-Type: application/json' \
--data "{\"name\":\"pageview\",
\"url\":\"https://stats.linuxgsm.com\",
\"domain\":\"stats.linuxgsm.com\",
\"cpuusedmhzroundup\": \"${cpuusedmhzroundup}MHz\",
\"memusedroundup\": \"${memusedroundup}MB\",
\"serverfilesdu\": \"${serverfilesdu}\",
\"uuidhardware\": \"${uuidhardware}\",
\"uuidinstall\": \"${uuidinstall}\",
\"uuidinstance\": \"${uuidinstance}\",
\"diskused\": \"${serverfilesdu}\",
\"distro\": \"${distroname}\",
\"game\": \"${gamename}\",
\"ramused\": \"${memusedroundup}MB\",
\"servercpu\": \"${cpumodel} ${cpucores} cores\",
\"servercpufreq\": \"${cpufreqency} x${cpucores}\",
\"serverdisk\": \"${totalspace}\",
\"serverram\": \"${physmemtotal}\",
\"version\": \"${version}\",
\"virtualenvironment\": \"${virtualenvironment}\",
\"discordalert\": \"${discordalert}\",
\"emailalert\": \"${emailalert}\",
\"gotifyalert\": \"${gotifyalert}\",
\"iftttalert\": \"${iftttalert}\",
\"mailgunalert\": \"${mailgunalert}\",
\"pushbulletalert\": \"${pushbulletalert}\",
\"pushoveralert\": \"${pushoveralert}\",
\"rocketchatalert\": \"${rocketchatalert}\",
\"slackalert\": \"${slackalert}\",
\"telegramalert\": \"${telegramalert}\"
}"
fn_script_log_info "Send LinuxGSM stats" fn_script_log_info "Send LinuxGSM stats"
fn_script_log_info "* uuid-${selfname}: ${uuidinstance}" fn_script_log_info "* uuid-${selfname}: ${uuidinstance}"
fn_script_log_info "* uuid-install: ${uuidinstall}" fn_script_log_info "* uuid-install: ${uuidinstall}"

Loading…
Cancel
Save