Oracledb_exporter 获取表大小信息的简单方法

发布时间 2023-11-06 18:30:34作者: 济南小老虎

Oracledb_exporter 获取表大小信息的简单方法


背景

用我儿子的现状作为背景: 
我爱学习, 学习让我妈快乐.

下载exporter

exporter 可以在github上面下载最新版本是 0.5.1 

https://github.com/iamseth/oracledb_exporter
可以直接下载release 好的二进制, 也可以docker pull 相关的镜像

docker pull iamseth/oracledb_exporter
可以用的tag 主要有 latest 嗨哟 0.5.1 和 0.2.9

运行方式

export DATA_SOURCE_NAME=oracle://grafana:Test20131127@192.168.254.210:1521/ora12c
export QUERY_TIMEOUT=30000

然后可以在某个目录下设置一个 toml 文件. 
比如这个为:

[[metric]]
context = "table_size"
labels = [ "tablename" ]
metricsdesc = { table_size = " Top 20 biggest tables. " }
request = '''
select   table_name as tablename ,round(num_rows * avg_row_len/1024/1024 , 2)  as table_size from dba_tables order by nvl(num_rows * avg_row_len/1024/1024,0) desc FETCH NEXT 20 ROWS ONLY
'''

启动的话就比较简单了
oracledb_exporter  --default.metrics "/oracle_exporter/custom-metrics.toml"

要是容器运行的话 比较郁闷 需要将这个文件打包进去 主要是修改 启动脚本
FROM iamseth/oracledb_exporter:0.2.9 
COPY custom-metrics.toml /
ENTRYPOINT ["/oracledb_exporter", "--custom.metrics", "/custom-metrics.toml"]

运行的话方式为:
docker run -d --name oracledb_exporter  -p 9161:9161 -e DATA_SOURCE_NAME=oracle://grafana:Test20131127@192.168.254.210:1521/ora12c  oracledb

查看metrics

http://192.168.254.210:9161/metrics


# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 12
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 1.721112e+06
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 2.1797752e+07
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 1.448806e+06
# HELP go_memstats_frees_total Total number of frees.
# TYPE go_memstats_frees_total counter
go_memstats_frees_total 205940
# HELP go_memstats_gc_sys_bytes Number of bytes used for garbage collection system metadata.
# TYPE go_memstats_gc_sys_bytes gauge
go_memstats_gc_sys_bytes 3.574024e+06
# HELP go_memstats_heap_alloc_bytes Number of heap bytes allocated and still in use.
# TYPE go_memstats_heap_alloc_bytes gauge
go_memstats_heap_alloc_bytes 1.721112e+06
# HELP go_memstats_heap_idle_bytes Number of heap bytes waiting to be used.
# TYPE go_memstats_heap_idle_bytes gauge
go_memstats_heap_idle_bytes 6.32832e+07
# HELP go_memstats_heap_inuse_bytes Number of heap bytes that are in use.
# TYPE go_memstats_heap_inuse_bytes gauge
go_memstats_heap_inuse_bytes 3.104768e+06
# HELP go_memstats_heap_objects Number of allocated objects.
# TYPE go_memstats_heap_objects gauge
go_memstats_heap_objects 5666
# HELP go_memstats_heap_released_bytes_total Total number of heap bytes released to OS.
# TYPE go_memstats_heap_released_bytes_total counter
go_memstats_heap_released_bytes_total 6.1988864e+07
# HELP go_memstats_heap_sys_bytes Number of heap bytes obtained from system.
# TYPE go_memstats_heap_sys_bytes gauge

Grafana增加panel

增加panel 然后可以选择信息进行展示. 

数据库降低抓取频率

--scrape.interval=300s

可以将 抓取频率降低, 这样的话对数据库的影响会低很多. 

Flags:
  -
, --[no-]help                Show context-sensitive help (also try --help-long and --help-man).
      --web.telemetry-path="/metrics"
                                 Path under which to expose metrics. (env: TELEMETRY_PATH)
      --default.metrics="default-metrics.toml"
                                 File with default metrics in a TOML file. (env: DEFAULT_METRICS)
      --custom.metrics=""        File that may contain various custom metrics in a TOML file. (env: CUSTOM_METRICS)
      --query.timeout=3000000    Query timeout (in seconds). (env: QUERY_TIMEOUT)
      --database.maxIdleConns=0  Number of maximum idle connections in the connection pool. (env: DATABASE_MAXIDLECONNS)
      --database.maxOpenConns=10
                                 Number of maximum open connections in the connection pool. (env: DATABASE_MAXOPENCONNS)
      --scrape.interval=0s       Interval between each scrape. Default is to scrape on collect requests
      --[no-]web.systemd-socket  Use systemd socket activation listeners instead of port listeners (Linux only).
      --web.listen-address=:9161 ...
                                 Addresses on which to expose metrics and web interface. Repeatable for multiple addresses.
      --web.config.file=""       [EXPERIMENTAL] Path to configuration file that can enable TLS or authentication.
                                 See: https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
      --log.level=info           Only log messages with the given severity or above. One of: [debug, info, warn, error]
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]
      --[no-]version             Show application version.