Prometheus Java Client : Export String based Metrics

3.5k Views Asked by At

I`m Currently trying to write an Exporter for Minecraft to display some Metrics in our Grafana Dashboard. While most Metrics are working fine with the Metric Types Counter and Gauge, i couldn't find any documentation on how to export Strings as Metrics. I need those to export Location Data, so that we can have an Overview about where our Players are from, so we can focus localization on these regions. I wasn't able to find anything about that in the official Documentation, nor was I able to find anything in the Github Repository that could help me.

Anyone can help me with that?

With kind regards thelooter

1

There are 1 best solutions below

0
On BEST ANSWER

Metrics are always numeric. But you can use a labels to export string values, this is typically used to export build or version information. E.g.

version_info{version="1.23", builtOn="Windows", built_by="myUserName" gitTag="version_1.0"} = 1

so you can show in Grafana which version is currently running.

But (!!!) Prometheus is not designed to handle a lot of label combinations. Prometheus creates a new file for every unique label value combination. This would mean that you creat a file per player if you had one metric per player. (And you still need to calculate the amount of players per Region)

What you could do is define regions in your software and export a gauge for every region representing the amount of players logged in from this region:

player_count{region="Europe"} 234
player_count{region="North America"} 567
...

If you don't want to hardcode the regions in your software, you should export the locations of the players into a database and do the statistics later based on the raw data.