fix metrics

This commit is contained in:
ginuerzh 2022-04-07 23:01:35 +08:00
parent 688455dd0b
commit aeda8b11ca
2 changed files with 21 additions and 12 deletions

View File

@ -86,18 +86,18 @@ func (r *Route) connect(ctx context.Context) (conn net.Conn, err error) {
return nil, ErrEmptyRoute return nil, ErrEmptyRoute
} }
network := "ip"
node := r.nodes[0]
defer func() { defer func() {
if err != nil && r.chain != nil { if err != nil && r.chain != nil {
if v := metrics.GetCounter(metrics.MetricChainErrorsCounter, if v := metrics.GetCounter(metrics.MetricChainErrorsCounter,
metrics.Labels{"chain": r.chain.name}); v != nil { metrics.Labels{"chain": r.chain.name, "node": node.Name}); v != nil {
v.Inc() v.Inc()
} }
} }
}() }()
network := "ip"
node := r.nodes[0]
addr, err := resolve(ctx, network, node.Addr, node.Resolver, node.Hosts, r.logger) addr, err := resolve(ctx, network, node.Addr, node.Resolver, node.Hosts, r.logger)
if err != nil { if err != nil {
node.Marker.Mark() node.Marker.Mark()

View File

@ -3,15 +3,24 @@ package metrics
type MetricName string type MetricName string
const ( const (
MetricServicesGauge MetricName = "gost_services" // Number of services. Labels: host.
MetricServiceRequestsCounter MetricName = "gost_service_requests_total" MetricServicesGauge MetricName = "gost_services"
MetricServiceRequestsInFlightGauge MetricName = "gost_service_requests_in_flight" // Total service requests. Labels: host, service.
MetricServiceRequestsDurationObserver MetricName = "gost_service_request_duration_seconds" MetricServiceRequestsCounter MetricName = "gost_service_requests_total"
MetricServiceTransferInputBytesCounter MetricName = "gost_service_transfer_input_bytes_total" // Number of in-flight requests. Labels: host, service.
MetricServiceRequestsInFlightGauge MetricName = "gost_service_requests_in_flight"
// Request duration historgram. Labels: host, service.
MetricServiceRequestsDurationObserver MetricName = "gost_service_request_duration_seconds"
// Total service input data transfer size in bytes. Labels: host, service.
MetricServiceTransferInputBytesCounter MetricName = "gost_service_transfer_input_bytes_total"
// Total service output data transfer size in bytes. Labels: host, service.
MetricServiceTransferOutputBytesCounter MetricName = "gost_service_transfer_output_bytes_total" MetricServiceTransferOutputBytesCounter MetricName = "gost_service_transfer_output_bytes_total"
MetricNodeConnectDurationObserver MetricName = "gost_chain_node_connect_duration_seconds" // Chain node connect duration histogram. Labels: host, chain, node.
MetricServiceHandlerErrorsCounter MetricName = "gost_service_handler_errors_total" MetricNodeConnectDurationObserver MetricName = "gost_chain_node_connect_duration_seconds"
MetricChainErrorsCounter MetricName = "gost_chain_errors_total" // Total service handler errors. Labels: host, service.
MetricServiceHandlerErrorsCounter MetricName = "gost_service_handler_errors_total"
// Total chain connect errors. Labels: host, chain, node.
MetricChainErrorsCounter MetricName = "gost_chain_errors_total"
) )
type Labels map[string]string type Labels map[string]string