Project: YugabyteDB (App Definition and Development / Database)
File: macos.md

title: Prometheus integration headerTitle: Prometheus integration linkTitle: Prometheus integration description: Learn about exporting YugabyteDB metrics and monitoring the cluster with Prometheus. menu: v2.18: identifier: observability-1-macos parent: explore-observability weight: 235 type: docs You can monitor your local YugabyteDB cluster with a local instance of , a popular standard for time series monitoring of cloud native infrastructure. YugabyteDB services and APIs expose metrics in the Prometheus format at the `/prometheus-metrics` endpoint. For details on the metrics targets for YugabyteDB, see . and refer to for installation instructions. Follow the to start a local multi-node universe. Download the JAR file (`yb-sample-apps.jar`) using the following command: {{% yb-sample-apps-path %}} Run the `CassandraKeyValue` workload application in a separate shell. ```sh java -jar ./yb-sample-apps.jar \ --workload CassandraKeyValue \ --nodes 127.0.0.1:9042 \ --numthreadsread 1 \ --numthreadswrite 1 ``` From your Prometheus home directory, create a file `yugabytedb.yml` and add the following: ```yaml global: scrape_interval: 5s # Set the scrape interval to every 5 seconds. Default is every 1 minute. evaluation_interval: 5s # Evaluate rules every 5 seconds. The default is every 1 minute. scrape_configs: job_name: "yugabytedb" metrics_path: /prometheus-metrics relabel_configs: targetlabel: "nodeprefix" replacement: "cluster-1" metricrelabelconfigs: sourcelabels: ["name_"] regex: "(.*)" targetlabel: "savedname" replacement: "$1" sourcelabels: ["name_"] regex: "handlerlatency(yb[^])_([^_])([^])(.)" targetlabel: "servertype" replacement: "$1" sourcelabels: ["name_"] regex: "handlerlatency(yb[^])_([^_])([^])(.)" targetlabel: "servicetype" replacement: "$2" sourcelabels: ["name_"] regex: "handlerlatency(yb[^])_([^_])([^]*)(sum|count)?" targetlabel: "servicemethod" replacement: "$3" sourcelabels: ["name_"] regex: "handlerlatency(yb[^])_([^_])([^]*)(sum|count)?" targetlabel: "name_" replacement: "rpc_latency$4" static_configs: targets: ["127.0.0.1:7000", "127.0.0.2:7000", "127.0.0.3:7000"] labels: exporttype: "masterexport" targets: ["127.0.0.1:9000", "127.0.0.2:9000", "127.0.0.3:9000"] labels: exporttype: "tserverexport" targets: ["127.0.0.1:12000", "127.0.0.2:12000", "127.0.0.3:12000"] labels: exporttype: "cqlexport" targets: ["127.0.0.1:13000", "127.0.0.2:13000", "127.0.0.3:13000"] labels: exporttype: "ysqlexport" targets: ["127.0.0.1:11000", "127.0.0.2:11000", "127.0.0.3:11000"] labels: exporttype: "redisexport" ``` Start the Prometheus server from the Prometheus home directory as follows: ```sh ./prometheus --config.file=yugabytedb.yml ``` Open the Prometheus UI at <http://localhost:9090> and then navigate to the Targets page under Status. On the Prometheus Graph UI, you can plot the read or write throughput and latency for the `CassandraKeyValue` sample application. Because the of the application uses only SELECT statements for reads and INSERT statements for writes (aside from the initial CREATE TABLE), you can measure throughput and latency by using the metrics corresponding to the SELECT and INSERT statements. Paste the following expressions into the Expression box and click Execute followed by Add Graph. Read IOPS ```sh sum(irate(rpclatencycount{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="SelectStmt"}[1m])) ``` Write IOPS ```sh sum(irate(rpclatencycount{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="InsertStmt"}[1m])) ``` Read Latency (in microseconds) ```sh avg(irate(rpclatencysum{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="SelectStmt"}[1m])) / avg(irate(rpclatencycount{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="SelectStmt"}[1m])) ``` Write Latency (in microseconds) ```sh avg(irate(rpclatencysum{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="InsertStmt"}[1m])) / avg(irate(rpclatencycount{servertype="ybcqlserver", servicetype="SQLProcessor", servicemethod="InsertStmt"}[1m])) ``` Set up for better visualization of the metrics being collected by Prometheus.