# 实现结果# 配置前
PS D:\Codes\gin_middleware> ab.exe -n 400 -c 12 -t 20 http://127.0.0.1/test
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
......
Server Software:
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /test
Document Length: 26 bytes
Concurrency Level: 12
Time taken for tests: 8.597 seconds
Complete requests: 50000
Failed requests: 0
Total transferred: 7450000 bytes
HTML transferred: 1300000 bytes
Requests per second: 5815.81 [#/sec] (mean)
Time per request: 2.063 [ms] (mean)
Time per request: 0.172 [ms] (mean, across all concurrent requests)
Transfer rate: 846.25 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 5
Processing: 0 2 0.6 2 13
Waiting: 0 1 0.7 1 11
Total: 0 2 0.6 2 13
Percentage of the requests served within a certain time (ms)
50% 2 66% 2 75% 2 80% 2 90% 3 95% 3 98% 3 99% 4 100% 13 (longest request)
# 配置后
PS D:\Codes\gin_middleware> ab.exe -n 400 -c 12 -t 20 http://127.0.0.1/test
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
......
Server Software:
Server Hostname: 127.0.0.1
Server Port: 80
Document Path: /test
Document Length: 26 bytes
Concurrency Level: 12
Time taken for tests: 8.657 seconds
Complete requests: 50000
Failed requests: 0
Total transferred: 7450000 bytes
HTML transferred: 1300000 bytes
Requests per second: 5775.92 [#/sec] (mean)
Time per request: 2.078 [ms] (mean)
Time per request: 0.173 [ms] (mean, across all concurrent requests)
Transfer rate: 840.44 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 5
Processing: 0 2 0.7 2 21
Waiting: 0 1 0.8 1 21
Total: 0 2 0.7 2 21
Percentage of the requests served within a certain time (ms)
50% 2 66% 2 75% 2 80% 2 90% 3 95% 3 98% 3 99% 4 100% 21 (longest request)
8:go-gin-prometheus
这个是我们用Gin写程序的时候基于Prometheus的一个Exporter包,我们可以用它暴露一个接口,专门提供Prometheus监控
# 下载
go get github.com/zsais/go-gin-prometheus
# 验证
PS D:\Codes\gin_middleware> http http://127.0.0.1/
HTTP/1.1 200 OK
Content-Length: 25
Content-Type: application/json; charset=utf-8
Date: Sun, 13 Aug 2023 13:06:38 GMT
{
"message": "hello world"
}
# 验证监控,它默认是/metrics,当然,我们可以直接用p.MetricsPath来指定监控路径哈,默认是/metrics
# 验证监控接口
PS D:\Codes\gin_middleware> http http://127.0.0.1/metrics
HTTP/1.1 200 OK
Content-Type: text/plain; version=0.0.4; charset=utf-8
Date: Sun, 13 Aug 2023 13:11:26 GMT
# HELP gin_request_duration_seconds The HTTP request latencies in seconds.# TYPE gin_request_duration_seconds summary
gin_request_duration_seconds_sum 0.0007537
gin_request_duration_seconds_count 3
# HELP gin_request_size_bytes The HTTP request sizes in bytes.# TYPE gin_request_size_bytes summary
gin_request_size_bytes_sum 1632
gin_request_size_bytes_count 3
# HELP gin_requests_total How many HTTP requests processed, partitioned by status code and HTTP method.# TYPE gin_requests_total counter
gin_requests_total{code="200",handler="main.main.func1",host="127.0.0.1",method="GET",url="/"} 2
gin_requests_total{code="404",handler="github.com/zsais/go-gin-prometheus.(*Prometheus).HandlerFunc.func1",host="127.0.0.1",method="GET",url="/favicon.ico"} 1
# HELP gin_response_size_bytes The HTTP response sizes in bytes.# TYPE gin_response_size_bytes summary
gin_response_size_bytes_sum 49
gin_response_size_bytes_count 3
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0
go_gc_duration_seconds{quantile="0.75"} 0
go_gc_duration_seconds{quantile="1"} 0
go_gc_duration_seconds_sum 0
go_gc_duration_seconds_count 6
# HELP go_goroutines Number of goroutines that currently exist.# TYPE go_goroutines gauge
go_goroutines 8
# HELP go_info Information about the Go environment.# TYPE go_info gauge
go_info{version="go1.20.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.774304e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 4.39404e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 7229
# HELP go_memstats_frees_total Total number of frees.# TYPE go_memstats_frees_total counter
go_memstats_frees_total 18264
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 7.211832e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 1.774304e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 8.257536e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 4.030464e+06
# HELP go_memstats_heap_objects Number of allocated objects.# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 9809
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 7.979008e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 1.2288e+07
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.6919322382780173e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 28073
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 14016
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16352
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 126560
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 130560
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.194304e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 1.673499e+06
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 294912
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 294912
# HELP go_memstats_sys_bytes Number of bytes obtained from system.# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 2.1622384e+07
# HELP go_threads Number of OS threads created.# TYPE go_threads gauge
go_threads 11
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.015625
# HELP process_max_fds Maximum number of open file descriptors.# TYPE process_max_fds gauge
process_max_fds 1.6777216e+07
# HELP process_open_fds Number of open file descriptors.# TYPE process_open_fds gauge
process_open_fds 135
# HELP process_resident_memory_bytes Resident memory size in bytes.# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.6252928e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.691931584e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2.4154112e+07
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 1
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
# 例如,如果您有一个模板化路线,并且不想为每个可能的客户名称生成时间序列,则可以向中间件提供此映射函数:/customer/:name
package main
import (
"github.com/gin-gonic/gin"
ginprometheus "github.com/zsais/go-gin-prometheus""log""strings"
)
funcmain() {
// 设置gin为发布模式
gin.SetMode(gin.ReleaseMode)
// 初始化gin
r := gin.Default()
// 初始化prometheus中间件
p := ginprometheus.NewPrometheus("gin")
p.ReqCntURLLabelMappingFn = func(c *gin.Context)string {
url := c.Request.URL.Path
for _, p := range c.Params {
if p.Key == "name" {
url = strings.Replace(url, p.Value, ":name", 1)
break
}
}
return url
}
p.Use(r)
r.GET("/", func(c *gin.Context) {
c.JSON(200, "Hello world!")
})
// 启动gin
err := r.Run(":80")
if err != nil {
log.Println(err)
}
}
# 验证
PS D:\Codes\gin_middleware> http http://127.0.0.1/metrics
HTTP/1.1 200 OK
Content-Type: text/plain; version=0.0.4; charset=utf-8
Date: Sun, 13 Aug 2023 13:42:48 GMT
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.0005035
go_gc_duration_seconds{quantile="0.25"} 0.0005035
go_gc_duration_seconds{quantile="0.5"} 0.0005035
go_gc_duration_seconds{quantile="0.75"} 0.0005035
go_gc_duration_seconds{quantile="1"} 0.0005035
go_gc_duration_seconds_sum 0.0005035
go_gc_duration_seconds_count 1
# HELP go_goroutines Number of goroutines that currently exist.# TYPE go_goroutines gauge
go_goroutines 7
# HELP go_info Information about the Go environment.# TYPE go_info gauge
go_info{version="go1.20.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.70396e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 3.179688e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 7218
# HELP go_memstats_frees_total Total number of frees.# TYPE go_memstats_frees_total counter
go_memstats_frees_total 16236
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 6.565848e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 1.70396e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 4.063232e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 3.997696e+06
# HELP go_memstats_heap_objects Number of allocated objects.# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 9495
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 3.514368e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 8.060928e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.6919340856959622e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 25731
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 14016
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16352
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 95840
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 97920
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 4.194304e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 905014
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 327680
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 327680
# HELP go_memstats_sys_bytes Number of bytes obtained from system.# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 1.598096e+07
# HELP go_threads Number of OS threads created.# TYPE go_threads gauge
go_threads 9
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.015625
# HELP process_max_fds Maximum number of open file descriptors.# TYPE process_max_fds gauge
process_max_fds 1.6777216e+07
# HELP process_open_fds Number of open file descriptors.# TYPE process_open_fds gauge
process_open_fds 119
# HELP process_resident_memory_bytes Resident memory size in bytes.# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.5040512e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.691934085e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2.2925312e+07
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 0
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
# HELP service_uptime HTTP service uptime.# TYPE service_uptime counter
service_uptime 82
# 我们请求一次/接口之后的结果
PS D:\Codes\gin_middleware> http http://127.0.0.1/metrics
HTTP/1.1 200 OK
Content-Type: text/plain; version=0.0.4; charset=utf-8
Date: Sun, 13 Aug 2023 13:44:46 GMT
# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0
go_gc_duration_seconds{quantile="0.25"} 0
go_gc_duration_seconds{quantile="0.5"} 0.0005035
go_gc_duration_seconds{quantile="0.75"} 0.0005035
go_gc_duration_seconds{quantile="1"} 0.0005035
go_gc_duration_seconds_sum 0.0005035
go_gc_duration_seconds_count 2
# HELP go_goroutines Number of goroutines that currently exist.# TYPE go_goroutines gauge
go_goroutines 7
# HELP go_info Information about the Go environment.# TYPE go_info gauge
go_info{version="go1.20.4"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.59308e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 4.219792e+06
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 7218
# HELP go_memstats_frees_total Total number of frees.# TYPE go_memstats_frees_total counter
go_memstats_frees_total 17778
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 7.114344e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 2.59308e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 3.31776e+06
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 4.775936e+06
# HELP go_memstats_heap_objects Number of allocated objects.# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 9749
# HELP go_memstats_heap_released_bytes Number of heap bytes released to OS.# TYPE go_memstats_heap_released_bytes gauge
go_memstats_heap_released_bytes 2.449408e+06
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.# TYPE go_memstats_heap_sys_bytes gauge
go_memstats_heap_sys_bytes 8.093696e+06
# HELP go_memstats_last_gc_time_seconds Number of seconds since 1970 of last garbage collection.# TYPE go_memstats_last_gc_time_seconds gauge
go_memstats_last_gc_time_seconds 1.6919342057001953e+09
# HELP go_memstats_lookups_total Total number of pointer lookups.# TYPE go_memstats_lookups_total counter
go_memstats_lookups_total 0
# HELP go_memstats_mallocs_total Total number of mallocs.# TYPE go_memstats_mallocs_total counter
go_memstats_mallocs_total 27527
# HELP go_memstats_mcache_inuse_bytes Number of bytes in use by mcache structures.# TYPE go_memstats_mcache_inuse_bytes gauge
go_memstats_mcache_inuse_bytes 14016
# HELP go_memstats_mcache_sys_bytes Number of bytes used for mcache structures obtained from system.# TYPE go_memstats_mcache_sys_bytes gauge
go_memstats_mcache_sys_bytes 16352
# HELP go_memstats_mspan_inuse_bytes Number of bytes in use by mspan structures.# TYPE go_memstats_mspan_inuse_bytes gauge
go_memstats_mspan_inuse_bytes 95840
# HELP go_memstats_mspan_sys_bytes Number of bytes used for mspan structures obtained from system.# TYPE go_memstats_mspan_sys_bytes gauge
go_memstats_mspan_sys_bytes 97920
# HELP go_memstats_next_gc_bytes Number of heap bytes when next garbage collection will take place.# TYPE go_memstats_next_gc_bytes gauge
go_memstats_next_gc_bytes 5.6048e+06
# HELP go_memstats_other_sys_bytes Number of bytes used for other system allocations.# TYPE go_memstats_other_sys_bytes gauge
go_memstats_other_sys_bytes 946342
# HELP go_memstats_stack_inuse_bytes Number of bytes in use by the stack allocator.# TYPE go_memstats_stack_inuse_bytes gauge
go_memstats_stack_inuse_bytes 294912
# HELP go_memstats_stack_sys_bytes Number of bytes obtained from system for stack allocator.# TYPE go_memstats_stack_sys_bytes gauge
go_memstats_stack_sys_bytes 294912
# HELP go_memstats_sys_bytes Number of bytes obtained from system.# TYPE go_memstats_sys_bytes gauge
go_memstats_sys_bytes 1.6570784e+07
# HELP go_threads Number of OS threads created.# TYPE go_threads gauge
go_threads 10
# HELP process_cpu_seconds_total Total user and system CPU time spent in seconds.# TYPE process_cpu_seconds_total counter
process_cpu_seconds_total 0.015625
# HELP process_max_fds Maximum number of open file descriptors.# TYPE process_max_fds gauge
process_max_fds 1.6777216e+07
# HELP process_open_fds Number of open file descriptors.# TYPE process_open_fds gauge
process_open_fds 128
# HELP process_resident_memory_bytes Resident memory size in bytes.# TYPE process_resident_memory_bytes gauge
process_resident_memory_bytes 1.6953344e+07
# HELP process_start_time_seconds Start time of the process since unix epoch in seconds.# TYPE process_start_time_seconds gauge
process_start_time_seconds 1.691934085e+09
# HELP process_virtual_memory_bytes Virtual memory size in bytes.# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes 2.4629248e+07
# HELP promhttp_metric_handler_requests_in_flight Current number of scrapes being served.# TYPE promhttp_metric_handler_requests_in_flight gauge
promhttp_metric_handler_requests_in_flight 1
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 1
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
# HELP service_http_request_count_total Total number of HTTP requests made.# TYPE service_http_request_count_total counter
service_http_request_count_total{endpoint="/",method="GET",status="200"} 1
service_http_request_count_total{endpoint="/metrics",method="GET",status="200"} 1
# HELP service_http_request_duration_seconds HTTP request latencies in seconds.# TYPE service_http_request_duration_seconds histogram
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.005"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.01"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.025"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.05"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.1"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.25"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="0.5"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="1"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="2.5"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="5"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="10"} 1
service_http_request_duration_seconds_bucket{endpoint="/",method="GET",status="200",le="+Inf"} 1
service_http_request_duration_seconds_sum{endpoint="/",method="GET",status="200"} 0
service_http_request_duration_seconds_count{endpoint="/",method="GET",status="200"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.005"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.01"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.025"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.05"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.1"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.25"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="0.5"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="1"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="2.5"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="5"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="10"} 1
service_http_request_duration_seconds_bucket{endpoint="/metrics",method="GET",status="200",le="+Inf"} 1
service_http_request_duration_seconds_sum{endpoint="/metrics",method="GET",status="200"} 0.0009488
service_http_request_duration_seconds_count{endpoint="/metrics",method="GET",status="200"} 1
# HELP service_http_request_size_bytes HTTP request sizes in bytes.# TYPE service_http_request_size_bytes summary
service_http_request_size_bytes_sum{endpoint="/",method="GET",status="200"} 65
service_http_request_size_bytes_count{endpoint="/",method="GET",status="200"} 1
service_http_request_size_bytes_sum{endpoint="/metrics",method="GET",status="200"} 72
service_http_request_size_bytes_count{endpoint="/metrics",method="GET",status="200"} 1
# HELP service_http_response_size_bytes HTTP response sizes in bytes.# TYPE service_http_response_size_bytes summary
service_http_response_size_bytes_sum{endpoint="/",method="GET",status="200"} 26
service_http_response_size_bytes_count{endpoint="/",method="GET",status="200"} 1
service_http_response_size_bytes_sum{endpoint="/metrics",method="GET",status="200"} 1330
service_http_response_size_bytes_count{endpoint="/metrics",method="GET",status="200"} 1
# HELP service_uptime HTTP service uptime.# TYPE service_uptime counter
service_uptime 201
package revision
import (
"github.com/gin-gonic/gin""io/ioutil""log""strings"
)
// GetRevision will get revision string from file.funcGetRevision(fileName string) (string, error) {
// Revision file contents will be only loaded once per process
data, err := ioutil.ReadFile(fileName)
// If we cant read file, just skip to the next request handler// This is pretty much a NOOP middlware :)if err != nil {
log.Printf("Unable to read config file '%s'", fileName)
return"", err
}
// Clean up the value since it could contain line breaksreturn strings.TrimSpace(string(data)), err
}
// Middleware will auto set Revision on header.funcMiddleware(args ...string) gin.HandlerFunc {
fileName := "REVISION"iflen(args) > 0 {
fileName = args[0]
}
revision, err := GetRevision(fileName)
if err != nil {
returnfunc(c *gin.Context) {
c.Next()
}
}
// Set out header value for each responsereturnfunc(c *gin.Context) {
c.Writer.Header().Set("X-Revision", revision)
c.Next()
}
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· 一次Java后端服务间歇性响应慢的问题排查记录
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(四):结合BotSharp
· 一个基于 .NET 开源免费的异地组网和内网穿透工具
· 《HelloGitHub》第 108 期
· Windows桌面应用自动更新解决方案SharpUpdater5发布
· 我的家庭实验室服务器集群硬件清单