oracle-db-appdev-monitoring

所属分类:Oracle数据库
开发工具:GO
文件大小:86KB
下载次数:0
上传日期:2023-05-23 20:59:04
上 传 者sh-1993
说明:  用于以数据为中心的应用程序开发和微服务的统一可观察性的脚本和代码
(Scripts and code for unified observability for data-centric app dev and microservices)

文件列表:
CONTRIBUTING.md (2199, 2023-05-24)
LICENSE.txt (1871, 2023-05-24)
Makefile (537, 2023-05-24)
SECURITY.md (2080, 2023-05-24)
THIRD_PARTY_LICENSE.txt (26457, 2023-05-24)
THIRD_PARTY_LICENSES_DEV.txt (1231, 2023-05-24)
docker-compose.yml (1556, 2023-05-24)
docker_vol (0, 2023-05-24)
docker_vol\graf_app_vol (0, 2023-05-24)
docker_vol\graf_app_vol\dashboard_concurrency.json (49095, 2023-05-24)
docker_vol\graf_app_vol\dashboard_io.json (13625, 2023-05-24)
docker_vol\graf_app_vol\dashboard_query.json (42991, 2023-05-24)
docker_vol\graf_app_vol\dashboard_sys.json (72091, 2023-05-24)
docker_vol\prom_app_vol (0, 2023-05-24)
docker_vol\prom_app_vol\config.yml (559, 2023-05-24)
docker_vol\prom_app_vol\myrules.yml (383, 2023-05-24)
docker_vol\prom_app_vol\web.yml (281, 2023-05-24)
exporter (0, 2023-05-24)
exporter\Dockerfile (574, 2023-05-24)
exporter\auth_config.yml (212, 2023-05-24)
exporter\default-metrics.toml (23699, 2023-05-24)
grafana (0, 2023-05-24)
grafana\Dockerfile (454, 2023-05-24)
grafana\dashboards (0, 2023-05-24)
grafana\dashboards\all.yml (329, 2023-05-24)
grafana\dashboards\dashboard.json (57392, 2023-05-24)
grafana\datasources (0, 2023-05-24)
grafana\datasources\all.yml (418, 2023-05-24)
grafana\grafana.ini (34711, 2023-05-24)
oracle-db-monitoring-exporter (0, 2023-05-24)
oracle-db-monitoring-exporter\Makefile (2614, 2023-05-24)
oracle-db-monitoring-exporter\default-asm-metrics.toml (7167, 2023-05-24)
oracle-db-monitoring-exporter\default-metrics.legacy-tablespace.toml (3979, 2023-05-24)
oracle-db-monitoring-exporter\default-metrics.toml (2503, 2023-05-24)
oracle-db-monitoring-exporter\go.mod (360, 2023-05-24)
oracle-db-monitoring-exporter\go.sum (7856, 2023-05-24)
oracle-db-monitoring-exporter\main.go (23696, 2023-05-24)
... ...

# Unified App Dev Monitoring with Oracle Database This distribution contains scripts and code for exporting metrics and logs from the Oracle Database, to provide converged app-dev monitoring for data-centric applications. Metrics from the application layer, Kubernetes, and Oracle Database will be combined to provide unified observability to developers. The project uses Prometheus for metrics and Loki for logs, and uses Grafana as the single pane-of-glass dashboard. v1 (preview) - contains export of key database metrics to Prometheus and suggested Grafana dashboard The following metrics are exposed currently by default. - oracledb_exporter_last_scrape_duration_seconds - oracledb_exporter_last_scrape_error - oracledb_exporter_scrapes_total - oracledb_up - oracledb_activity_execute_count - oracledb_activity_parse_count_total - oracledb_activity_user_commits - oracledb_activity_user_rollbacks - oracledb_sessions_activity - oracledb_wait_time_application - oracledb_wait_time_commit - oracledb_wait_time_concurrency - oracledb_wait_time_configuration - oracledb_wait_time_network - oracledb_wait_time_other - oracledb_wait_time_scheduler - oracledb_wait_time_system_io - oracledb_wait_time_user_io - oracledb_tablespace_bytes - oracledb_tablespace_max_bytes - oracledb_tablespace_free - oracledb_tablespace_used_percent - oracledb_process_count - oracledb_resource_current_utilization - oracledb_resource_limit_value ## Table of Contents - [Unified App Dev Monitoring with Oracle Database](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#unified-app-dev-monitoring-with-oracle-database) - [Table of Contents](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#table-of-contents) - [Directory Structure](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#directory-structure) - [Prerequisite Components Setup with Docker Swarm](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#prerequisite-components-setup-with-docker-swarm) - [Dockerfile and Images for Docker Swarm](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#dockerfile-and-images-for-docker-swarm) - [Oracle Database Docker Image Building](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#oracle-database-docker-image-building) - [Oracle Database Exporter Docker Image Building](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#oracle-database-exporter-docker-image-building) - [Prometheus Docker Image Building](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#prometheus-docker-image-building) - [Grafana Docker Image Building](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#grafana-docker-image-building) - [Docker Compose with Docker Swarm](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#docker-compose-with-docker-swarm) - [Oracle Database Part in Compose File](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#oracle-database-part-in-compose-file) - [Exporter Part in Compose File](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#exporter-part-in-compose-file) - [Docker Volume in Compose File](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#docker-volume-in-compose-file) - [Prometheus Part in Compose File](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#prometheus-part-in-compose-file) - [Grafana Part in Compose File](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#grafana-part-in-compose-file) - [Monitor Startup and Components Modification](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#monitor-startup-and-components-modification) - [Startup and Run](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#startup-and-run) - [i. Start the Monitor](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#i-start-the-monitor) - [ii. View Logging](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#ii-view-logging) - [iii. Stop/Remove the Monitor Program](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#iii-stopremove-the-monitor-program) - [Exporter Metrics modification and refresh](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#exporter-metrics-modification-and-refresh) - [Prometheus storage/alert rule modification and refresh](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#prometheus-storagealert-rule-modification-and-refresh) - [Grafana Setup and Refresh](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#grafana-setup-and-refresh) - [Oracle Database Monitoring Exporter](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#oracle-database-monitoring-exporter) - [Description](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#description) - [Installation](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#installation) - [Running](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#running) - [Usage](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#usage) - [Default metrics](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#default-metrics) - [Custom metrics](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#custom-metrics) - [Customize metrics in a docker image](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#customize-metrics-in-a-docker-image) - [Using a multiple host data source name](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#using-a-multiple-host-data-source-name) - [Files & Folder](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#files--folder) - [Environment Variables](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#environment-variables) - [TLS connection to database](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#tls-connection-to-database) - [FAQ/Troubleshooting](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#faqtroubleshooting) - [Unable to convert current value to float (metric=par,metri...in.go:285](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#unable-to-convert-current-value-to-float-metricparmetriingo285) - [Error scraping for wait_time](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#error-scraping-for-wait_time) - [An Oracle instance generates trace files](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#an-oracle-instance-generates-trace-files) - [Data Storage](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#data-storage) ## Directory Structure ```text . ├── Makefile ├── docker-compose.yml # aggregate all services ├── README.md # this! │ ├── docker_vol/ │ ├── graf_app_vol/ │ │ ├── dashboard_concurrency.json │ │ ├── dashboard_io.json │ │ ├── dashboard_query.json │ │ └── dashboard_sys.json │ │ │ └── prom_app_vol/ │ ├── myrules.yml # rules of prometheus metrics and alerts │ ├── config.yml # connection configuration │ └── web.yml # authentication configuration │ │ ├── oracledb/ # local Oracle Database(19c) container │ ├── Dockerfile │ └── oracledb_entrypoint.sh # docker secret setup scripts │ │ ├── oracle-db-monitoring-exporter/ # customized basic exporter program │ │ ├── exporter/ # query and format metrics │ ├── Dockerfile │ ├── auth_config.yml # http auth config of the exporter │ └── default-metrics.toml # queries to collect metrics │ │ ├── prometheus/ # time-series metrics storage │ ├── Dockerfile │ └── prom_entrypoint.sh # docker secret setup scripts │ │ └── grafana/ # monitor dashboard ├── Dockerfile ├── dashboards/ │ └── all.yml # config of dashboard │ └── datasources └── all.yml # specify prometheus as the datasource ``` --- ## Prerequisite Components Setup with Docker Swarm ### Dockerfile and Images for Docker Swarm In order to protect user's sensitive config info and data, a Docker Secret is used which requires Docker Swarm mode. ```sh docker swarm init # use `docker info` to check status of swarm mode ``` > For more details about docker swarm, please visit [docker swarm init official documentation](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/reference/commandline/swarm_init/). Each component in [Docker Swarm](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/swarm/) mode is a [Docker Service](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/reference/commandline/service/). A group of docker services is called [Docker Stack](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/reference/commandline/stack/). Hence, we are going to use following command to start the monitor. ``` sh docker stack deploy --compose-file {yaml_compose_file} {stack_name} ``` This is different from `docker-compose` which can build the image during setup as Docker Swarm requires a pre-built image for each service(container). #### Oracle Database Docker Image Building - Files involved - `./oracledb/Dockerfile` - `./oracledb/oracledb_entrypoint.sh` ```sh cd exporter docker build --tag {oracledb_image_name} . # or docker build --tag {oracledb_image_name}:{image_tag} . # examples docker build --tag oracledb_monitor_oracledb . docker build --tag oracledb_monitor_oracledb:1.0 . ``` > For more details about docker build, please visit the [official documentation](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/reference/commandline/build/) #### Oracle Database Exporter Docker Image Building An additional http authentication feature is provided to enhance connection security, therefore, it is necessary to build a basic exporter image from `oracle-db-monitoring-exporter` and then a customized image with configuration files. - Files involved: - `./oracle-db-monitoring-exporter/*` - `./exporter/Dockerfile` - `./exporter/auth_config.yml` - `./exporter/default-metrics.toml` - `./exporter/localhost.cert` (you need to create your own version) - `./exporter/localhost.key` (you need to create your own version) a. Base Image This is a required step. ```sh # Base Image cd oracle-db-monitoring-exporter make oraclelinux-image # This will build three base images and we are going to use either # "oracle-db-monitoring-exporter:0.3.0-oraclelinux" or "oracle-db-monitoring-exporter:oraclelinux" ``` b. Before creating the customized image, it is necessary to setup the authentication username and password for the exporter and encrypt it with a docker secret. Then, specify the docker secret names in `exporter/auth_config.yml` ```sh echo "{exp_auth_username}" | docker secret create {secret_name} - echo "{exp_auth_password}" | docker secret create {secret_name} - # examples echo "mntmgr" | docker secret create auth.username - echo "P@55w0rd" | docker secret create auth.password - ``` ```yaml # auth_config.yml username: auth.username password: auth.password ``` c. Ensure metric queries are finished and saved in `exporter/default-metrics.toml`. d. Generate ssl key and ssl certificate for https transportation. ```sh cd exporter openssl req \ -x509 \ -newkey rsa:4096 \ -nodes \ -keyout localhost.key \ -out localhost.crt ``` Make sure `localhost.key` and `localhost.crt` are under `./exporter/` *If you need to change file names of cert and key, don't forget to modify the `Dockerfile`.* e. Final Customized Image ```sh # Customized Image cd exporter docker build --tag {image_name}:{tag_name} . # example docker build --tag oracledb_monitor_exporter:1.0 . ``` #### Prometheus Docker Image Building - Files involved: - `./docker_vol/prom_app_vol/config.yml` - `./docker_vol/prom_app_vol/myrules.yml` - `./docker_vol/prom_app_vol/web.yml` - `./prometheus/Dockerfile` - `./prometheus/prom_entrypoint.sh` - `./prometheus/localhost.cert` (you need to create your own version) - `./prometheus/localhost.key` (you need to create your own version) a. Generate ssl key and ssl certificate for https transportation. ```sh cd exporter openssl req \ -x509 \ -newkey rsa:4096 \ -nodes \ -keyout localhost.key \ -out localhost.crt ``` Make sure your `localhost.key` and `localhost.crt` are under `./prometheus/` *If you need to change file names of cert and key, don't forget to modify the `Dockerfile` and `web.yml`.* b. Build Prometheus image ```sh cd prometheus docker build --tag {image_name}:{tag_name} . # example docker build --tag oracledb_monitor_prometheus:1.0 . ``` c. Setup http authentication username and password for Prometheus in `./docker_vol/prom_app_vol/web.yml` and Docker Secret. The password required to connect to Prometheus should be hashed with [bcrypt](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md#about-bcrypt). Use `htpasswd` command to hash the password with bcrypt. ```sh htpasswd -nBC 10 “” | tr -d ‘:\n’ ``` Copy and paste the result, and create such docker secret. For example, the bcrypt hashing of `test` is `$2b$12$hNf2lSsxfm0.i4a.1kVpSOVyBCfIB51VRjgBUyv6kdnyTlgWj81Ay`. ```sh echo "{prom_auth_password}" | docker secret create prom.auth.pwd - # example echo "\$2b\$12\$hNf2lSsxfm0.i4a.1kVpSOVyBCfIB51VRjgBUyv6kdnyTlgWj81Ay" | docker secret create prom.auth.pwd - # don't forget add a '\' before each '$' # you can also create a docker secret with a file. visit the documentation. ``` ***Here the secret name is required to be 'prom.auth.pwd'.*** ```yaml # web.yml basic_auth_users: {prom_auth_username}: {docker_secret_name_of_auth_pwd} # example: mntmgr: prom.auth.pwd ``` #### Grafana Docker Image Building - Files involved: - `./docker_vol/prom_app_vol/config.yml` - `./docker_vol/prom_app_vol/myrules.yml` - `./docker_vol/prom_app_vol/web.yml` - `./prometheus/Dockerfile` - `./prometheus/prom_entrypoint.sh` - `./prometheus/localhost.cert` (you need to create your own version) - `./prometheus/localhost.key` (you need to create your own version) a. Generate ssl key and ssl certificate for https transportation. ```sh cd exporter openssl req \ -x509 \ -newkey rsa:4096 \ -nodes \ -keyout localhost.key \ -out localhost.crt ``` Make sure your `localhost.key` and `localhost.crt` are under `./grafana/` *If you need to change file names of cert and key, don't forget to modify the `Dockerfile` and `grafana.ini`.* b. For Grafana, you can setup the connection to Prometheus in `./grafana/datasources/all.yml`, setup config of dashboards in `./grafana/dashboards/all.yml`, while all of the provision dashboards are in `./docker_vol/graf_app_vol/*.json`. You should setup connection and configuration of Grafana before building the image, but you can modify dashboard raw codes after startup. ```sh cd grafana docker build --tag {image_name}:{tag_name} . # example docker build --tag oracledb_monitor_grafana:1.0 . ``` ### Docker Compose with Docker Swarm To enable the usage of compose file in docker swarm command line, we need the version of `docker-compose.yml` to be at least 3.1. ```yaml # docker-compose.yml version: 3.1 # We have it by default. Don't delete it in your customization. ``` There is a default `docker-compose.yml`, but it is still necessary to setup docker secret in your environment. #### Oracle Database Part in Compose File ```yaml services: oracledb: image: {db_image_name:image_tab} # oracledb_monitor_oracledb:1.0 container_name: 'oracledb' environment: ORACLE_SID: ORCLCDB ORACLE_PWD: DOCKER_SECRET@{pwd_secret_name} # DOCKER_SECRET@oracle.pwd secrets: - {pwd_secret_name} # oracle.pwd ports: - '1521:1521' - '8080:8080' tty: true secrets: {pwd_secret_name}: # oracle.pwd: external: true ``` You need to create your password to DBA with Docker Secret. ```sh echo "{sysdba_pwd}" | docker secret create {secret_name} - # example echo "P@55w0rd" | docker secret create oracle.pwd - ``` > For more details about docker secret in compose file, please visit the [official documentation](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.docker.com/engine/swarm/secrets/#use-secrets-in-compose). #### Exporter Part in Compose File ```yaml services: exporter: image: {exporter_image_name:image_tab} # oracledb_monitor_exporter:1.0 container_name: 'exporter' environment: DATA_SOURCE_NAME: {dsn_secret_name} # data.source.name secrets: - {dsn_secret_name} # data.source.name - {exp_auth_username} # auth.username - {exp_auth_password} # auth.password depends_on: - oracledb ports: - '9161:9161' secrets: {dsn_secret_name}: # data.source.name external: true {exp_auth_username}: # auth.username external: true {exp_auth_password}: # auth.password external: true ``` `{exp_auth_username}` and `{exp_auth_password}` are the ones we've setup in the [previous step](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#oracle-database-exporter-docker-image-building). You need to setup your database connection string, auth username and password of the exporter with Docker Secret. For the Data Connection String, we strongly recommend not using sysdba, and instead creating your own common cdb user. ```sh # After the creation and initialization of your Oracle Database # in the shell of your database system # for container, to login to shell docker exec -it --user oracle {container_id} /bin/bash sqlplus sys/{sysdba_pwd} as sysdba ``` ```sql DROP USER c##mntmgr CASCADE; -- a prefix of c## is required CREATE USER c##mntmgr IDENTIFIED BY test CONTAINER=ALL; GRANT CREATE SESSION TO c##mntmgr; GRANT select_catalog_role TO c##mntmgr; GRANT select any dictionary TO c##mntmgr; ``` So the DSN of `c##mntmgr` to your Oracle Database is `c##mntmgr:test@oracledb/ORCLCDB`. Encrypt it with Docker Secret. ```sh echo "c##mntmgr:test@oracledb/ORCLCDB" | docker secret create data.source.name - ``` > For more details about Oracle Easy Connect Naming, please visit [official documentation](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://docs.oracle.com/en/database/oracle/oracle-database/18/ntcli/specifying-a-connection-by-using-the-easy-connect-naming-method.html#GUID-1035ABB3-5ADE-4697-A5F8-28F9F79A7504)* #### Docker Volume in Compose File Before Prometheus and Grafana Part, we need to set the docker volume. To use configuration files and dashboard of Prometheus and Grafana in `./docker_vol`, please setup volumes to Prometheus and Grafana containers. ```yaml services: prometheus: volumes: - {directory_to_prom_app_vol}:/etc/prometheus/prometheus_vol # for example # ?/docker_vol/prom_app_vol:/etc/prometheus/prometheus_vol ``` #### Prometheus Part in Compose File ```yaml # docker-compose.yml prometheus: image: oracledb_monitor_prometheus:1.0 container_name: 'prometheus' secrets: - prom.auth.pwd - auth.username # exporter auth username - auth.password # exporter auth password depends_on: - exporter ports: - '9090:9090' - '9093:9093' volumes: - ./docker_vol/prom_app_vol:/etc/prometheus/prometheus_vol tty: true secrets: prom.auth.pwd: external: true ``` ```yaml # config.yml in ./docker_vol/prom_app_vol/ # this file is for exporter connection global: scrape_interval: 30s scrape_timeout: 30s evaluation_interval: 30s scrape_configs: - job_name: 'TEQ Monitor' static_configs: - targets: ['exporter:9161'] basic_auth: username: auth.username # docker secret name of exporter auth username password: auth.password # docker secret name of exporter auth password rule_files: - "/etc/prometheus/prometheus_vol/myrules.yml" # your prom rules ``` #### Grafana Part in Compose File ```yaml # docker-compose.yml grafana: image: oracledb-monitor_graf container_name: 'grafana' depends_on: - prometheus ports: - '3000:3000' volumes: - ./docker_vol/graf_app_vol:/var/lib/grafana/grafana_vol ``` --- ## Monitor Startup and Components Modification Setup all [configurations prerequisites](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/#prerequisite-link). ### Startup and Run #### i. Start the Monitor ```sh docker stack deploy --compose-file docker-compose.yml {stack_name} # for example docker stack deploy --compose-file docker-compose.yml oracledb-monitor # or run `make deploy` # check Makefile to edit your own commands ``` The first time you build and start the Oracle Database container, it will take about 15 to 20 minutes for Oracle Database to get ready. Create your general user when it done. Then, go to the [Grafana Dashboard](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://localhost:3000). By default, username: admin, password: admin > If using Chrome, it may show "Your connection is not private" and "NET::ERR_CERT_INVALID", and prevent you from visiting the Grafana board. Please use other browser. You will meet the same problem during visiting local [Prometheus Dashboard](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://localhost:9090) and [exporter metrics](https://github.com/oracle/oracle-db-appdev-monitoring/blob/master/https://localhost:9161/metrics) with https protocol. This problem is due to that we are using self-signed certificates which Chrome does not recognize. ***To enable your Grafana to connect to your Prometheus database, when you login to Grafana dashboard, go to `Configuration` -> `Data Sources` -> `Prometheus`(data connection). Then A) enable the `Basic auth`, `Skip TLS Verify` and `With CA Cert` under ... ...

近期下载者

相关文件


收藏者