From 609dd5b72f68feb716582632484f68b54e49020a Mon Sep 17 00:00:00 2001 From: Dimitris Gkanatsios Date: Mon, 12 Feb 2024 15:56:24 -0800 Subject: [PATCH] fix for previous PR --- .../PF_StartupScript.ps1 | 42 +++++++++++++++++++ .../PF_StartupScript.sh | 28 ------------- windows_logs_telegraf_playfab/README.md | 2 +- 3 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 windows_logs_telegraf_playfab/PF_StartupScript.ps1 delete mode 100644 windows_logs_telegraf_playfab/PF_StartupScript.sh diff --git a/windows_logs_telegraf_playfab/PF_StartupScript.ps1 b/windows_logs_telegraf_playfab/PF_StartupScript.ps1 new file mode 100644 index 0000000..18c75cf --- /dev/null +++ b/windows_logs_telegraf_playfab/PF_StartupScript.ps1 @@ -0,0 +1,42 @@ +<# +.SYNOPSIS + +.DESCRIPTION + +.NOTES + Version: 1.0 + Author: + Creation Date: + Purpose/Change: Initial script development +#> + +# Set Error Action to Stop +$ErrorActionPreference = "Stop" + +# Grab the script path +$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition +echo "the current script path is $scriptPath" + +# these are some of the env variables that are available to you +echo "PlayFab Title ID is $env:PF_TITLE_ID" # e.g. 59F84 +echo "PlayFab Build ID is $env:PF_BUILD_ID" # Guid, e.g. 09d91059-22d3-4d0a-8c99-f34f80525aae +echo "PlayFab Virtual Machine ID is $env:PF_VM_ID" # e.g. vmss:SouthCentralUs:2458795A9259968E_12fe54be-fae1-41aa-83d9-09b809d5ef01:09d91059-22d3-4d0a-8c99-f34f80525aae +echo "Region where the VM is deployed is $env:PF_REGION" # e.g. SouthCentralUs + +$telegrafConfPath = "$scriptPath\telegraf.conf" +((Get-Content -path $telegrafConfPath -Raw) -replace '_%PF_TITLE_ID%_', "$env:PF_TITLE_ID") | Set-Content -Path $telegrafConfPath +((Get-Content -path $telegrafConfPath -Raw) -replace '_%PF_BUILD_ID%_', "$env:PF_BUILD_ID") | Set-Content -Path $telegrafConfPath +((Get-Content -path $telegrafConfPath -Raw) -replace '_%PF_VM_ID%_', "$env:PF_VM_ID") | Set-Content -Path $telegrafConfPath + +$telegrafPath = 'C:\Program Files\telegraf' +New-Item -ItemType Directory -Force -Path "$telegrafPath" +cp "$scriptPath\telegraf.*" "$telegrafPath" +cd "$telegrafPath" +.\telegraf.exe --service install --config "$telegrafPath\telegraf.conf" + +$registryPath = "HKLM:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\telegraf" +$values = @("AZURE_TENANT_ID=", "AZURE_CLIENT_ID=", "AZURE_CLIENT_SECRET=") +New-ItemProperty -Path $registryPath -Name "Environment" -Value $values -PropertyType MultiString -Force + +# start the telegraf service +.\telegraf.exe --service start \ No newline at end of file diff --git a/windows_logs_telegraf_playfab/PF_StartupScript.sh b/windows_logs_telegraf_playfab/PF_StartupScript.sh deleted file mode 100644 index a044d0b..0000000 --- a/windows_logs_telegraf_playfab/PF_StartupScript.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -set -o errexit # script exits when a command fails == set -e -set -o nounset # script exits when tries to use undeclared variables == set -u -set -o xtrace # trace what's executed == set -x (useful for debugging) -set -o pipefail # causes pipelines to retain / set the last non-zero status - -# get script's path -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" - -# install telegraf -sudo apt-get -yq --no-install-recommends install "${DIR}"/telegraf.deb - -chmod +x "${DIR}"/telegraftoplayfab - -systemctl stop telegraf - -# remove \r\n in-place -sed -i -e 's/\r$//' ${DIR}/telegraf.conf -sed -i -e 's/\r$//' ${DIR}/plugin.conf - -mkdir -p /etc/telegraf || echo 'Warning: /etc/telegraf already exists' - -# add PF_TITLE_ID, PF_BUILD_ID, PF_VM_ID to telegraf.conf as dimensions -sed -e "s/_%PF_TITLE_ID%_/${PF_TITLE_ID}/g" -e "s/_%PF_BUILD_ID%_/${PF_BUILD_ID}/g" -e "s/_%PF_VM_ID%_/${PF_VM_ID}/g" -e "s/_%PF_REGION%_/${PF_REGION}/g" ${DIR}/telegraf.conf > /etc/telegraf/telegraf.conf - -sudo usermod -a -G docker telegraf - -systemctl restart telegraf diff --git a/windows_logs_telegraf_playfab/README.md b/windows_logs_telegraf_playfab/README.md index 312f05c..ad0be2c 100644 --- a/windows_logs_telegraf_playfab/README.md +++ b/windows_logs_telegraf_playfab/README.md @@ -10,7 +10,7 @@ You can see documentation about [Telegraf output plugin for PlayFab here](https: ## What it does -This script uses [telegraf](https://www.influxdata.com/time-series-platform/telegraf/) agent to grab game server logs emitted via the [Game Server SDK (GSDK)](https://github.com/playfab/gsdk) and send them to PlayFab. GSDK logs from game servers are written in paths `"D:\\GameLogs\\*\\GSDK_output_*.txt"`. These text files contents' are grabbed by the [tail](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/tail/README.md) telegraf plugin and converted to proper telegraf metrics via the [grok](https://docs.influxdata.com/telegraf/v1.26/data_formats/input/grok/) format. Finally, the [Telegraf output plugin for PlayFab here](https://github.com/dgkanatsios/telegraftoplayfab) pushes these logs to PlayFab. +This script uses [telegraf](https://www.influxdata.com/time-series-platform/telegraf/) agent to grab game server logs emitted via the [Game Server SDK (GSDK)](https://github.com/playfab/gsdk) and send them to PlayFab. GSDK logs from game servers are written in paths `"D:\\GameLogs\\*\\GSDK_output_*.txt"`. Content in these text files is grabbed by the [tail](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/tail/README.md) telegraf plugin and converted to proper telegraf metrics via the [grok](https://docs.influxdata.com/telegraf/v1.26/data_formats/input/grok/) format. Finally, the [Telegraf output plugin for PlayFab here](https://github.com/dgkanatsios/telegraftoplayfab) pushes these logs to PlayFab. This script is applicable if you are running Windows MPS Builds using Windows game servers.