Custom Prometheus metrics

Hi, I don’t see any documentation to expose custom/application Prometheus metrics ?
Thanks !

@louis030195 What do you mean expose custom Prometheus metrics? I’m not sure what you’re trying to achieve :sweat_smile:

I want to expose my own metrics using nakama/metrics.go at 1af222ad9b86b1dd459a6d41e3274775b6f06892 · heroiclabs/nakama · GitHub
i.e. for example in authoritative match:

func (m *Match) MatchInit(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, params map[string]interface{}) (interface{}, int, string) {
    nk.NewCounter("my_message_counter")
    nk.NewCounter("number_of_superman_in_game")
}
func (m *Match) MatchLoop(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, data interface{}, messages []runtime.MatchData) interface{} {
    // If some message ...
    nk.GetCounter("my_message_counter").Inc()
}

// Or

func (m *Match) MatchJoin(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, dispatcher runtime.MatchDispatcher, tick int64, data interface{}, presences []runtime.Presence) interface{} {
    if presences[0].GetUsername() == "Superman" {
        nk.GetCounter("number_of_superman_in_game").Inc()
    }
}

Also it would be really nice if you had Grafana dashboards to share :smiley:

1 Like

@louis030195 This sounds like a good feature request. Please open an issue on the tracker and we can come up with a good interface to support custom metrics to be written via the server runtimes.