Golang ?? ?? ????? ?? ??? ?????? ??? ??????
Jun 05, 2024 pm 10:18 PMGo ??????? Prometheus? ???? ?? ??? ?????? ?? ?????. Prometheus ??? ?????. Prometheus ????? ?????? ???? MetricsHandler? ????. ??? ??? HTTP ??? ????? promhttp ??? ??????. ???? ????? Prometheus.Register()? ??????. NewTimer() ? ObserveDuration()? ???? ?? ?? ??? ?????. Prometheus ? UI? ????? ?? ??? ??????.
Prometheus? ???? Go ???? ?? ?? ????
Go ??????? ?? ?? ????? ??? ??? ?? ? ?? ?? ??? ???? ???? ???? ? ?????. Prometheus? ??? ??? ????? ???? ? ??? ?? ?? ?? ?? ?? ?????. ? ?? ?? Prometheus? ???? Go ????? ?? ??? ?????? ??? ?? ??? ???? ???? ??? ?????.
Prometheus ?? ? ??
-
???? Prometheus ??:
wget https://github.com/prometheus/prometheus/releases/download/v2.39.3/prometheus-2.39.3.linux-amd64.tar.gz tar -xzvf prometheus-2.39.3.linux-amd64.tar.gz
Prometheus ??? ??:
cd prometheus-2.39.3.linux-amd64 ./prometheus
Prometheus ????? ??
-
Go ?????? Prometheus ?????? ?????:
go get github.com/prometheus/client_golang/prometheus go get github.com/prometheus/client_golang/prometheus/promhttp
MetricsHandler ???:
package main import ( "log" "net/http" "time" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) const ( // RequestDuration defines the prometheus metric to track the time elapsed // for the handling of incoming requests RequestDuration = "http_server_request_duration_seconds" ) var requestDuration = prometheus.NewHistogram(prometheus.HistogramOpts{ Name: RequestDuration, Help: "HTTP server request duration in seconds.", Buckets: []float64{0.1, 0.3, 0.5, 0.75, 1}, }) func main() { // Register the RequestDuration metric prometheus.Register(requestDuration) // Create a new HTTP Server with a MetricsHandler http.Handle("/metrics", promhttp.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { timer := prometheus.NewTimer(requestDuration.WithLabelValues(r.URL.Path)) defer timer.ObserveDuration() time.Sleep(time.Millisecond * 100) }) // Start the server log.Fatal(http.ListenAndServe(":8080", nil)) }
Go ???? ??:
go run main.go
?? ?? ???
- Prometheus ? UI ??: http://localhost:9090
- ??? "???" ?? ???? "http_server_request_duration_seconds" ????? ?????.
?? ??
- ?? ?? ???? ??? ??? ??? ?????.
- ??? ?? ?? ??? ???????.
- ????? ?? ??? ????? ?? ??? ?????.
- Grafana? ?? ??? ??? ???? ????? ????.
? ??? Golang ?? ?? ????? ?? ??? ?????? ??? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Golang? ?? ?? ? ?? ????? ???? C? ??? ?? ? ??? ??? ??? ????? ?????. 1) Golang? ??? ?? ? ??? ????? ?? ??? ?????, ??? ? ??? ??? ?????. 2) C? ?? ??? ?? ? ???? ???? ?? ??? ? ??? ???? ???? ??? ??? ?????.

Golang? ????? C?? ?? C? ?? ???? Golang?? ????. 1) Golang? Goroutine ? Channel? ?? ???? ???? ????, ?? ?? ?? ??? ???? ? ?????. 2) C ???? ??? ? ?? ?????? ?? ????? ??? ???? ???? ??? ???? ??? ??????? ?????.

GO? ?? ?????? ????? ? ??? ?? ?? ?????? ?? ????? GO? ????? ? ? ???? ?? ? ?? ???? ??? ????.

Golang? ??? ?? ? ???? Python?? ????. 1) Golang? ??? ?? ??? ???? ??? ??? ?? ??? ?????? ? ?????. 2) ?? ? ???? ???? ??? ????? Cython? ?? ??? ?? ??? ??? ? ? ????.

Go Language? ????? ?? ??? ???? ???? ? ? ?????. ??? ??? ????. 1. ??? : ?? ??? ???, ?? ??? ??; 2. ?? ????? : ?? ?? ? ??? ?? ?? ??? ???; 3. ??? : ??? ??, ?? ? ?? ?? ?? ??; 4. ??? ??? : ??? ??? ???, ?? ??? ?????.

Golang? Python? ?? ?? ? ??? ????. Golang? ??? ? ?? ?????? ????? Python? ??? ?? ? ? ??? ?????. Golang? ??? ??? ???? ???? ???? Python? ??? ?? ? ??? ????? ???? ?????.

C? ???? ??? ? ??? ???? ?? ???? ????? ? ????? Golang? ?? ?? ? ?? ??? ??? ??? ????? ? ?????. 1.C? ??? ?? ??? ?? ??? ??? ??? ???? ?? ? ?? ??? ??? ?????. 2. Golang? ??? ??? ?? ? ?? ??? ??? ???, ?? ??? ??? ??? ?????.

Golang? ?? ??? ??? ? ????? Python? ???? ? ?? ??? ????. 1. Golang? Goroutine ? ??? ?? ???? ????? ?????. 2. Python? GIL? ????? ??? ? Asyncio? ????? ?? ??? ??? ?????. ??? ?? ?? ??? ?????????.
