Skip to content

Commit 4c2019b

Browse files
authored
Merge pull request #2 from GameCodePlus/incorrect-player-counts
Updated method to get players count to account for incorrect count in…
2 parents 14b6d24 + 6c7f71a commit 4c2019b

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

source/ark-metrics-exporter/ark-metrics-exporter.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<SignAssembly>true</SignAssembly>
1717
<DelaySign>false</DelaySign>
1818
<AssemblyOriginatorKeyFile>ark-metrics-exporter.snk</AssemblyOriginatorKeyFile>
19+
<Version>1.0.1</Version>
1920
</PropertyGroup>
2021

2122
<ItemGroup>

source/ark-metrics-exporter/models/ArkServer.cs

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ private void ProcessPlayerInfo()
7575
PrometheusMgr.PlayerOnlineGague.RemoveLabelled(item);
7676
}
7777
}
78+
79+
curLabels = PrometheusMgr.PlayerCountGague.GetAllLabelValues();
80+
if (curLabels != null)
81+
{
82+
foreach (var item in curLabels)
83+
{
84+
PrometheusMgr.PlayerCountGague.RemoveLabelled(item);
85+
}
86+
}
7887
}
7988

89+
PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(playerInfo.Players.Count);
90+
8091
foreach (var player in playerInfo.Players)
8192
{
8293
if (!String.IsNullOrWhiteSpace(player.PlayerName))
@@ -108,7 +119,10 @@ private void ProcessPlayerInfo()
108119
}
109120
}
110121
}
111-
catch (Exception) { }
122+
catch (Exception)
123+
{
124+
PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(0);
125+
}
112126
}
113127

114128
private void ProcessServerInfo()
@@ -132,28 +146,28 @@ private void ProcessServerInfo()
132146
}
133147
}
134148

135-
curLabels = PrometheusMgr.PlayerCountGague.GetAllLabelValues();
136-
if (curLabels != null)
137-
{
138-
foreach (var item in curLabels)
139-
{
140-
PrometheusMgr.PlayerCountGague.RemoveLabelled(item);
141-
}
142-
}
149+
//curLabels = PrometheusMgr.PlayerCountGague.GetAllLabelValues();
150+
//if (curLabels != null)
151+
//{
152+
// foreach (var item in curLabels)
153+
// {
154+
// PrometheusMgr.PlayerCountGague.RemoveLabelled(item);
155+
// }
156+
//}
143157
}
144158
serverName = serverInfo.Name;
145159

146160
// Update the "IsUp" gague setting to "true"
147161
PrometheusMgr.IsUpGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(1);
148-
PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(serverInfo.Players);
162+
//PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(serverInfo.Players);
149163
}
150164
catch (Exception)
151165
{
152166
var curName = serverName ?? String.Empty;
153167

154168
// Update the "IsUp" gague setting to "false"
155169
PrometheusMgr.IsUpGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", curName }).Set(0);
156-
PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(0);
170+
//PrometheusMgr.PlayerCountGague.WithLabels(new string[] { configItem.IPAddress, configItem.Port.ToString(), $"{configItem.IPAddress}:{configItem.Port}", serverName }).Set(0);
157171
}
158172
}
159173
}

0 commit comments

Comments
 (0)