In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about how to use Prometheus to monitor Golang services. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
Golang service program
Golang's Web program, I used the YoyoGo framework, "YoyoGo based on ASP.NET Core design of Golang implementation" can see this article to understand. The latest version of v1.5.0 has also been released, and the following Prometheus interface is the new feature of this version. If you want the program to be monitored, you must expose the project indicators in the operation of the program and provide it to Promtheus for information collection. Of course, Prometheus also provides push, which will be used in this example. We can use the golang client provided by Prometheus to expose our own runtime information. The code example is as follows:
Import ("github.com/yoyofx/yoyogo/WebFramework"github.com/yoyofx/yoyogo/WebFramework/Context"github.com/yoyofx/yoyogo/WebFramework/Endpoints") func main () {YoyoGo.CreateDefaultBuilder (func (router Router.IRouterBuilder) {Endpoints.UsePrometheus (router) router.GET ("/ info", func (ctx * Context.HttpContext) {ctx.JSON Context.M {"info": "ok"})}) .Build () .Run ()}
You can see the monitored metrics by visiting the local port 8080. The metrics monitored here are all default metrics. Of course, you can customize the quantitative metrics you need and expose them, which will not be discussed here.
Configure Prometheus
After downloading the Prometheus official website, let's configure Prometheus to serve as the monitoring metrics of the Golang service programs we collected:
Prometheus.yml:
-job_name: 'golang'
Scrape_interval: 10s
Metrics_path: / actuator/metrics
Static_configs:
-targets: ['localhost:8080']
Start Prometheus:
.\ prometheus.exe
Start Promethues and wait for 10s Golang index to be collected into Promethues's time series database. Access http://localhost:9090/ to get the following results
Grafana
After downloading from the Grafana website, the next step is to graphically display these indicators on grafana:
Start Grafana:
. / grafana-server
After entering the http://localhost:3000/, the configuration data source DataSource,Dashboard directly uses the official plug-in 10826 to import the ID, and the final result is as follows:
After reading the above, do you have any further understanding of how to use Prometheus to monitor Golang services? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.