Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
433 views
in Technique[技术] by (71.8m points)

Prometheus Java Client : Export String based Metrics

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

question from:https://stackoverflow.com/questions/65850083/prometheus-java-client-export-string-based-metrics

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...