当前位置:网站首页>Grp: how to add Prometheus monitoring in GRP service?
Grp: how to add Prometheus monitoring in GRP service?
2022-06-24 03:19:00 【Trespass 】
Introduce
This article will show you how to gRPC In microservice , Join in Prometheus monitor .
gRPC Automatic monitoring of functions , It will be introduced in the following articles , Here we only introduce how to gRPC In the code , Realization prometheus monitor .
Please visit the following address for a complete tutorial :https://rkdev.info/cnhttps://rkdocs.netlify.app/cn ( spare )
install
go get github.com/rookie-ninja/rk-boot go get github.com/rookie-ninja/rk-grpc
Quick start
For detailed documents, please refer to :
- Official documents
- perhaps ,Github
1. establish boot.yaml
---
grpc:
- name: greeter # Name of grpc entry
port: 8080 # Port of grpc entry
enabled: true # Enable grpc entry
prom:
enabled: true # Enable prometheus client
# path: "metrics" # Default value is "metrics", set path as needed.2. establish main.go
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
_ "github.com/rookie-ninja/rk-grpc/boot"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}3. start-up main.go
$ go run main.go
4. verification
visit :http://localhost:8080/metrics
Prometheus Add monitoring to the client
We need to know Prometheus The following concepts in .
name | details |
|---|---|
RK Custom structure , adopt MetricsSet register Prometheus Of Counter,Gauge,Histogram and Summary | |
Prometheus Will pass Registrerer To manage Counter,Gauge,Histogram and Summary | |
Counter It's a cumulative measure , Represents a single monotonically increasing counter , Its value can only be increased or reset to zero | |
Gauge Values can be added or subtracted at will | |
Histogram sampling ( It's usually something like request duration or response size ) And calculate them in configurable buckets , It also provides the sum of all observations | |
And Histogram similar , Abstract sample observation ( It's usually something like request duration and response size ) | |
Prometheus Namespace | Prometheus Monitor name format : namespace_subSystem_metricsName |
Prometheus SubSystem | Prometheus Monitor name format : namespace_subSystem_metricsName |
1. stay main.go Add monitoring items to
package main
import (
"context"
"github.com/rookie-ninja/rk-boot"
"github.com/rookie-ninja/rk-grpc/boot"
"github.com/rookie-ninja/rk-prom"
)
// Application entrance.
func main() {
// Create a new boot instance.
boot := rkboot.NewBoot()
// Bootstrap
boot.Bootstrap(context.Background())
// Create a metrics set into prometheus.Registerer
set := rkprom.NewMetricsSet("rk", "demo", boot.GetEntry("greeter").(*rkgrpc.GrpcEntry).GwEntry.PromEntry.Registerer)
// Register counter, gauge, histogram, summary
set.RegisterCounter("my_counter", "label")
set.RegisterGauge("my_gauge", "label")
set.RegisterHistogram("my_histogram", []float64{}, "label")
set.RegisterSummary("my_summary", rkprom.SummaryObjectives, "label")
// Increase counter, gauge, histogram, summary with label value
set.GetCounterWithValues("my_counter", "value").Inc()
set.GetGaugeWithValues("my_gauge", "value").Add(1.0)
set.GetHistogramWithValues("my_histogram", "value").Observe(0.1)
set.GetSummaryWithValues("my_summary", "value").Observe(0.1)
// Wait for shutdown sig
boot.WaitForShutdownSig(context.Background())
}2. start-up main.go
$ go run main.go
3. verification
visit :http://localhost:8080/metrics
Pushed to the prometheus pushgateway
Next , Let's see , How to make gRPC service , Automatically push monitoring data to remote Pushgateway in .
1.boot.yaml Start in pusher
---
grpc:
- name: greeter # Name of grpc entry
port: 8080 # Port of grpc entry
enabled: true # Enable grpc entry
prom:
enabled: true # Enable prometheus client
pusher:
enabled : true # Enable backend job push metrics to remote pushgateway
jobName: "demo" # Name of current push job
remoteAddress: "localhost:9091" # Remote address of pushgateway
intervalMs: 2000 # Push interval in milliseconds
# basicAuth: "user:pass" # Basic auth of pushgateway
# cert:
# ref: "ref" # Cert reference defined in CertEntry. Please see advanced user guide for details.2. Start locally pushgateway
We use docker start-up pushgateway
$ docker run prom/pushgateway -p 9091:9091
3. start-up main.go
$ go run main.go
4. verification
visit :http://localhost:9091/metrics
边栏推荐
- 2022-2028 global aircraft front wheel steering system industry research and trend analysis report
- Innovation or hype? Is low code a real artifact or a fake tuyere?
- Windowsvpn client is coveted by vulnerabilities, 53% of companies face supply chain attacks | global network security hotspot
- How to query trademark registration? Where should I check?
- UI automation based on Selenium
- How to apply for trademark registration? What are the steps?
- What are the security guarantees for cloud desktop servers? What are the cloud desktop server platforms?
- Disaster recovery series (V) -- database disaster recovery construction
- How to select a cloud game server? Which cloud game server recommends?
- 2022-2028 global cancer biopsy instrument and kit industry research and trend analysis report
猜你喜欢

2022-2028 global aircraft audio control panel system industry research and trend analysis report

2022-2028 global marine clutch industry research and trend analysis report

2022-2028 global high tibial osteotomy plate industry research and trend analysis report
![[51nod] 3047 displacement operation](/img/cb/9380337adbc09c54a5b984cab7d3b8.jpg)
[51nod] 3047 displacement operation

Simple and beautiful weather code

On Sunday, I rolled up the uni app "uview excellent UI framework"

2022-2028 global aircraft wireless intercom system industry research and trend analysis report

2022-2028 global aircraft front wheel steering system industry research and trend analysis report

QT creator tips
![[51nod] 2106 an odd number times](/img/af/59b441420aa4f12fd50f5062a83fae.jpg)
[51nod] 2106 an odd number times
随机推荐
How to register a trademark? Is the process troublesome?
Introduce the comparison of various distributed configuration centers? Which distributed configuration center is better?
Why do I need a code signing certificate? Where can I get a code signing certificate?
How to install the cloud desktop security server certificate? What can cloud desktops do?
[summary of interview questions] zj6 redis
Dry goods how to build a data visualization project from scratch?
Which brand is a good backup all-in-one machine price
Why use code signing? What certificates are required for code signing?
Windowsvpn client is coveted by vulnerabilities, 53% of companies face supply chain attacks | global network security hotspot
What does elastic scaling of cloud computing mean? What are the application scenarios for elastic scaling of cloud computing?
What is edge computing? What are the characteristics of the Internet platform edge calculator?
Where is the cloud game server? Can individuals rent cloud game servers?
How do I check the trademark registration number? Where do I need to check?
2022-2028 global aircraft wireless intercom system industry research and trend analysis report
[51nod] 3395 n-bit gray code
EIP maximum EIP EIP remote desktop access
What is cloud desktop and how to connect to the server? What does the mainstream architecture of cloud desktop include?
Velocitytracker use
Troubleshooting and resolution of errors in easycvr calling batch deletion interface
Process kill problem