| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | package yugabytedb |
| 4 | |
| 5 | import ( |
| 6 | "net/http" |
| 7 | |
| 8 | "github.com/netdata/netdata/go/plugins/pkg/prometheus" |
| 9 | "github.com/netdata/netdata/go/plugins/pkg/prometheus/selector" |
| 10 | ) |
| 11 | |
| 12 | const ( |
| 13 | metricPxMasterLatencyMasterClient = "handler_latency_yb_master_MasterClient" |
| 14 | metricPxMasterLatencyMasterDdl = "handler_latency_yb_master_MasterDdl" |
| 15 | metricPxTserverHandlerLatency = "handler_latency_yb_tserver" |
| 16 | metricPxTserverResponseBytes = "service_response_bytes_yb_tserver" |
| 17 | metricPxTserverRequestBytes = "service_request_bytes_yb_tserver" |
| 18 | metricPxServerLatencyConsensusService = "handler_latency_yb_consensus_ConsensusService" |
| 19 | metricPxServerResponseBytesConsensusService = "service_response_bytes_yb_consensus_ConsensusService" |
| 20 | metricPxServerRequestBytesConsensusService = "service_request_bytes_yb_consensus_ConsensusService" |
| 21 | metricPxYCQLLatencySQLProcessor = "handler_latency_yb_cqlserver_SQLProcessor" |
| 22 | metricPxYSQLLatencySQLProcessor = "handler_latency_yb_ysqlserver_SQLProcessor" |
| 23 | ) |
| 24 | |
| 25 | const ( |
| 26 | metricHybridClockSkew = "hybrid_clock_skew" |
| 27 | metricSqlActiveConnTotal = "yb_ysqlserver_active_connection_total" |
| 28 | metricSqlConnTotal = "yb_ysqlserver_connection_total" |
| 29 | metricSqlMaxConnTotal = "yb_ysqlserver_max_connection_total" |
| 30 | metricSqlConnOverLimitTotal = "yb_ysqlserver_connection_over_limit_total" |
| 31 | metricSqlNewConnTotal = "yb_ysqlserver_new_connection_total" |
| 32 | ) |
| 33 | |
| 34 | func (c *Collector) initPrometheusClient(httpClient *http.Client) (prometheus.Prometheus, error) { |
| 35 | // Frequently used metrics |
| 36 | // https://docs.yugabyte.com/preview/launch-and-manage/monitor-and-alert/metrics/#frequently-used-metrics |
| 37 | |
| 38 | se := selector.Expr{Allow: []string{ |
| 39 | metricPxMasterLatencyMasterClient + "*", |
| 40 | metricPxMasterLatencyMasterDdl + "*", |
| 41 | |
| 42 | metricPxTserverRequestBytes + "*", |
| 43 | metricPxTserverResponseBytes + "*", |
| 44 | metricPxTserverHandlerLatency + "*", |
| 45 | |
| 46 | metricPxServerLatencyConsensusService + "*", |
| 47 | metricPxServerResponseBytesConsensusService + "*", |
| 48 | metricPxServerRequestBytesConsensusService + "*", |
| 49 | |
| 50 | metricHybridClockSkew, |
| 51 | |
| 52 | // https://docs.yugabyte.com/preview/launch-and-manage/monitor-and-alert/metrics/throughput/#ysql-query-processing |
| 53 | metricPxYSQLLatencySQLProcessor + "*", |
| 54 | |
| 55 | // https://docs.yugabyte.com/preview/launch-and-manage/monitor-and-alert/metrics/connections/ |
| 56 | metricSqlActiveConnTotal, |
| 57 | metricSqlConnTotal, |
| 58 | metricSqlMaxConnTotal, |
| 59 | metricSqlConnOverLimitTotal, |
| 60 | metricSqlNewConnTotal, |
| 61 | |
| 62 | metricPxYCQLLatencySQLProcessor + "*", |
| 63 | }} |
| 64 | |
| 65 | sr, err := se.Parse() |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | |
| 70 | return prometheus.NewWithSelector(httpClient, c.RequestConfig, sr), nil |
| 71 | } |