Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dgkanatsios committed Feb 28, 2024
1 parent 40894fe commit 0bb505a
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
3 changes: 0 additions & 3 deletions windows_custom_gameserver_metrics/README.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ echo "PlayFab Build ID is $env:PF_BUILD_ID" # Guid, e.g. 09d91059-22d3-4d0a-8c99
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
echo "Shared content folder is $env:PF_SHARED_CONTENT_FOLDER_VM" # e.g. D:\sharedcontentfolder (All servers running on this VM have access to this folder through the PF_SHARED_CONTENT_FOLDER env variable.)

67 changes: 67 additions & 0 deletions windows_linux_custom_gameserver_metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Windows/Linux custom game server metrics

## Introduction

[Telegraf](https://github.com/influxdata/telegraf) is a plugin-driven server agent for collecting and reporting metrics. It supports a wide variety of inputs, processors, aggregators, and outputs.

## What it does

This script uses [telegraf](https://www.influxdata.com/time-series-platform/telegraf/) agent that sets up an HTTP server to listen for external metrics. Using this solution, you can send any kind of metrics from your game server to telegraf. You can use any of the [telegraf output plugins](https://github.com/influxdata/telegraf/blob/master/docs/OUTPUTS.md) to store them.

The documentation for the [http listener telegraf input plugin is here](https://github.com/influxdata/telegraf/blob/master/plugins/inputs/http_listener_v2/README.md).

You can see the [telegraf.conf](./telegraf.conf) file for an example of how to configure telegraf to listen for metrics on port 8080. To send metrics from your game server, you need to find the localhost IP address and send a POST request to the telegraf server.

### Host IP using Windows or Linux Processes

If you are using [process mode](https://learn.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/deploy-using-game-manager#server-details-for-process-mode), you can talk to telegraf using `localhost` or `127.0.0.1`.

### Host IP using Windows Containers

To get the IP of the host when using Windows Containers, you can use the following Powershell script from inside the container, before you start your game server:

```powershell
$gateway = (Get-WmiObject -Class Win32_IP4RouteTable | where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0' } | sort metric1 | select nexthop).nexthop
Write-Output $gateway
```

### Host IP using Linux Containers

To get the IP of the host when using Linux Containers, you can a script from inside the container, before you start your game server. The script you car run depends on your container image. If, for example, you are using Ubuntu, you can do `sudo apt update && sudo apt install net-tools` and then grab the gateway IP using:

```bash
netstat -rn | grep '^0.0.0.0' | awk '{print $2}'
```

```bash
curl -i -XPOST 'http://localhost:8080/telegraf' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
```

```powershell
$headers = @{
"Content-Type" = "application/octet-stream"
}
$body = "cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000"
$response = Invoke-WebRequest -Uri "http://localhost:8080/telegraf" -Method POST -Headers $headers -Body $body
```

## Usage

You should download telegraf from the [GitHub releases](https://github.com/influxdata/telegraf/releases) section. The [Windows amd64 package](https://dl.influxdata.com/telegraf/releases/telegraf-1.24.4_windows_amd64.zip) works with this sample. Then, you should grab either the DeveloperSecretKey or the TelemetryKey from your PlayFab account and add it to the plugin.conf file.

Then, create a zip file with the following contents:

- telegraf.conf
- plugin.conf
- telegraf package file (e.g. telegraf.exe)
- PF_StartupScript.ps1 file

You can now create a new MPS Build with your startup script using the [instructions here](https://learn.microsoft.com/en-us/gaming/playfab/features/multiplayer/servers/vmstartupscript).

![Windows logs with telegraf and PlayFab](../media/windows_logs_telegraf_playfab.png)
| :--: |
|Windows logs with telegraf and PlayFab|




27 changes: 27 additions & 0 deletions windows_linux_custom_gameserver_metrics/telegraf.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "0s"
flush_interval = "60s"
flush_jitter = "0s"
precision = ""
debug = true
omit_hostname = true

[global_tags]
titleID = "59F84"
buildID = "f49eeebd-9a7a-4bd1-a7a9-92b5b1a9568d"
vmID = "vmss:EastUs:59F84_a7582365-e048-4a88-9271-40a74b87ba83:45c93cbe-83d0-4220-9f25-24b5e4f20665"

[[outputs.file]]
## Files to write to, "stdout" is a specially handled file.
files = ["stdout"]

# Generic HTTP write listener
[[inputs.http_listener_v2]]
## Address and port to host HTTP listener on
service_address = ":8080"
data_format = "influx"

0 comments on commit 0bb505a

Please sign in to comment.