Skip to content

Commit

Permalink
loottracker: add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Aug 16, 2023
1 parent 6fdca05 commit 1c123b5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
package net.runelite.http.service.loottracker;

import com.google.gson.Gson;
import io.micrometer.core.instrument.MeterRegistry;
import java.util.Collection;
import net.runelite.http.api.RuneLiteAPI;
import net.runelite.http.api.loottracker.LootRecord;
import net.runelite.http.api.loottracker.LootRecordType;
import net.runelite.http.service.util.redis.RedisPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -46,12 +49,32 @@ public class LootTrackerController
@Autowired
private RedisPool redisPool;

@Autowired
private MeterRegistry meterRegistry;

@Value("${runelite.loottracker.metrics}")
private boolean enableMetrics;

@RequestMapping(method = RequestMethod.POST)
public void storeLootRecord(@RequestBody Collection<LootRecord> records)
{
try (Jedis jedis = redisPool.getResource())
{
jedis.publish("drops", GSON.toJson(records));
}

if (enableMetrics)
{
for (LootRecord record : records)
{
if (record.getType() == LootRecordType.EVENT || record.getType() == LootRecordType.NPC)
{
meterRegistry.counter("runelite loottracker",
"type", record.getType().name(),
"name", record.getEventId())
.increment();
}
}
}
}
}
4 changes: 3 additions & 1 deletion http-service/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,6 @@ runelite:
worlds:
url: http://www.runescape.com/g=oldscape/slr.ws?order=LPWM
item:
digestUrl: https://secure.runescape.com/m=itemdb_oldschool/digest.csv
digestUrl: https://secure.runescape.com/m=itemdb_oldschool/digest.csv
loottracker:
metrics: false

0 comments on commit 1c123b5

Please sign in to comment.