Closed ghost closed 3 years ago
Hi, i need to understand your needs first.
Do you want to summary CityName/StateCode/CountryCode/ContinentCode by IP-Address? And exposed these data by custom-metrics ?
Context: I am building an acme cdn (content delivery network) with gin/gin-cache and your repo.
So I would like to upgrade the grafana dashboard to use this panel: https://grafana.com/grafana/plugins/grafana-worldmap-panel/ and some others panel for summarizing the activity per city/country/state.
What would be your advice ?
Context: I am building an acme cdn (content delivery network) with gin/gin-cache and your repo.
So I would like to upgrade the grafana dashboard to use this panel: https://grafana.com/grafana/plugins/grafana-worldmap-panel/ and some others panel for summarizing the activity per city/country/state.
What would be your advice ?
Maybe this sample can meet your needs.
// 1. Define your custom-metric, and add it to global metrics.
gaugeMetric := &ginmetrics.Metric{
Type: ginmetrics.Counter,
Name: "summary_country",
Description: "Summary country/city... by IP Address",
Labels: []string{"country", "city", "state"},
}
_ = ginmetrics.GetMonitor().AddMetric(gaugeMetric)
// 2. Set geo interceptor
r.Use(func(ctx *gin.Context) {
geoResponse, ok := ctx.Get("GeoResponse")
if ok {
obj := new(geo.Response)
if err := json.Unmarshal(geoResponse, obj); err != nil {
// log err
// ...
} else {
_ = ginmetrics.GetMonitor().GetMetric("summary_country").Inc([]string{
obj.CountryCode,
obj.CityName,
obj.StateCode,
})
}
}
ctx.Next()
})
If the performance of this geo library is slow, you should consider optimize it.
awesome, I ll try it now :-)
take care
Sorry to re-open it again, but I am stucked to integrate it to grafana... ^^
Do you have an idea how to formulate the query in grafana for this panel ?
Sorry to re-open it again, but I am stucked to integrate it to grafana... ^^
Do you have an idea how to formulate the query in grafana for this panel ?
According to the above, your http_server have metrics. And you can access it with http://localhost:$port/debug/metrics
, this path will show you the summary_country
data.
Then, you need to install a Prometheus
, configure Prometheus
to grab these data. After that, you can query the data on Prometheus
Grafana is a front dashboard for backend(MySQL/Prometheus/PGSQL...).
Do you have a Prometheus
server now?
yes, I have setup/dockerized prometheus with grafana. I already imported your grafana dashboard and wanted to add the world map panel.
yes, I have setup/dockerized prometheus with grafana. I already imported your grafana dashboard and wanted to add the world map panel.
Yeah, has any summary_country
data been query by Prometheus?
yes, see the screenshot below:
yes, see the screenshot below:
You can install the plugin for Grafana first: https://grafana.com/grafana/plugins/grafana-worldmap-panel/?tab=installation
Download the zip and install plugin.
After Worldmap Panel
plugin installed, you should create a worldmap panel. And configure it with Prometheus Query
so the question is, what would like the query because I already installed the plugin :-)
so the question is, what would like the query because I already installed the plugin :-)
Probably like this, have an explore~ :)
I tried the following but no luck:
summary_country{job=~"$job", name=~"$city", key=~"$country", latitude=~"$latitude", longitude=~"$longitude"}
summary_country
You can run it in Prometheus first, see whether the grammar is ok.
I added longitude, latitude to the metrics as it is required by the panel but it does not display the points as it also needs a metric...
I'll do a test tonight and see how to configure a worldmap panel
Luc Michalski @.***> 于2021年4月7日周三 下午5:01写道:
I added longitude, latitude to the metrics as it is required by the panel but it does not display the points as it also needs a metric...
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/penglongli/gin-metrics/issues/2#issuecomment-814738448, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4FTN3U3B7ABOVJI5ZCXULTHQNNLANCNFSM42N6CTKA .
you are just awesome ^^
you are just awesome ^^
Try with this article: https://www.robustperception.io/using-the-worldmap-panel-with-prometheus
you are just awesome ^^
I made some fake data. (I don't know why the worldmap not showing up)
Hi @penglongli ,
Hope you are all well !
That's what I managed to get for now:
It is not displaying the total count , any ideas mate ?
count
Don't use rate
QL, just summary_country
I tried but I have the following message:
I tried but I have the following message:
Try sum(summary_country) by (country)
it works nicely :-)
Hi @penglongli ,
Hope you are all well !
I would like to add some custom metrics from the following middleware:
How should I do it with gin-metrics ?
Thanks for any insights or inputs on that question :-)
Cheers, Luc Michalski