-
Notifications
You must be signed in to change notification settings - Fork 6
grafana展示toplingdb运行指标 手动配置 基础
准备内容
- 自己使用 toplingdb 的可运行程序; 当前示例是使用 db_bench 完成。
- 安装 prometheus
- 安装 grafana
- 基本了解配置文件格式 toplingdb 直接内置和展示运行情况接口,通过一个配置文件设置,这里不展开介绍。
测试环境说明
- 使用 docker 测试
- toplingdb 地址为 toplingdb_host:55125
- prometheus 地址为 http://prometheus_host:55121
- grafana 地址为 http://grafana_host:55122
toplingdb 支持 prometheus 接口
- statistics 内容
示例是 /statistics/stat-strings,对应于配置中的 "Statistics" 的内容,可以有多个,依赖配置文件设置。
# 抓取配置列表
scrape_configs:
- job_name: 'stat-strings'
metrics_path: '/statistics/stat-strings'
params:
metric: ['1']
html: ['0']
static_configs:
- targets: ['db_ip_port']
- props 内容
可以有多个不同的内容(不同 db,不同 column_families),依赖配置文件,prometheus 设置示例如下。
后续运行示例中只有一个 strings 的 default column_families。
- job_name: 'props-zsets-default'
metrics_path: '/props/zsets/default'
params:
metric: ['1']
html: ['0']
noint: ['0']
static_configs:
- targets: ['db_ip_port']
- job_name: 'props-zsets-data_cf'
metrics_path: '/props/zsets/data_cf'
params:
metric: ['1']
html: ['0']
noint: ['0']
static_configs:
- targets: ['db_ip_port']
- job_name: 'props-zsets-score_cf'
metrics_path: '/props/zsets/score_cf'
params:
metric: ['1']
html: ['0']
noint: ['0']
static_configs:
- targets: ['db_ip_port']
注意: 接口展示具体内容时 rocksdb 相关统计信息,这里不展开介绍,请参考相关资料。
db_bench 使用说明:config.json 内容见"4 config.json 内容"
注意这里 LD_LIBRARY_PATH 的内容修改为你自己的代码位置,之后在代码目录直接执行即可。
/data 是自己创建的存储数据的目录
export LD_LIBRARY_PATH=/code/toplingdb:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/lib_shared:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/rls/boost-shared/bin.v2/libs/fiber/build/gcc-8/release/threading-multi/visibility-hidden:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/rls/boost-shared/bin.v2/libs/filesystem/build/gcc-8/release/threading-multi/visibility-hidden:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/rls/boost-shared/bin.v2/libs/context/build/gcc-8/release/threading-multi/visibility-hidden:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/rls/boost-shared/bin.v2/libs/system/build/gcc-8/release/threading-multi/visibility-hidden:/code/toplingdb/sideplugin/topling-zip/build/Linux-x86_64-g++-8.3-bmi2-1/rls/boost-shared/stage/lib
cp sideplugin/rockside/src/topling/web/{style.css,index.html} /data/toplingdb/strings
./db_bench -json ./config.json -num 1000000000 -disable_wal=true -value_size 2000 -benchmarks=fillrandom,readrandom -batch_size=10
toplingdb 有许多灵活设置,不是每个指标在你的设置下有有相应内容数据,一些不需要数据的数据指标可以通过这个设置忽略。目前操作的是 statistics 数据。
- discard_tickers
需要忽略的 prometheus gauge 或 conter 类型数据; - discard_histograms
需要忽略的 prometheus histogram 类型数据;
更详细可参见最后 config.json 内容
"Statistics": {
"stat-strings" : {
"class": "default",
"params": {
"discard_tickers": [
"# comment",
"// comment: 可以仅指定前缀,必须是以 . 为边界的前缀,例如下面两个必须分别指定",
"rocksdb.block.cache"
],
"discard_histograms": [
"# comment: ....",
"rocksdb.blobdb",
"rocksdb.bytes.compressed",
"# comment end of array"
],
"stats_level": "kAll",
"//stats_level": "kExceptDetailedTimers"
}
}
},
"/statistics/stat-strings"和"/props/strings/default" 对应请求的 url 地址。 数据示例:
$ curl -s "http://toplingdb_host:55125/statistics/stat-strings?html=0&metric=1" | head -5
engine:compaction:key:drop:new 426761
engine:number:keys:written 58279080
engine:bytes:written 117793676496
engine:no:file:opens 689
engine:db:mutex:wait:nanos 4462357547
$ curl -s "http://toplingdb_host:55125/props/strings/default?html=0&metric=1" | head -5
engine:num_immutable_mem_table 2
engine:num_immutable_mem_table_flushed 0
engine:mem_table_flush_pending 0
engine:compaction_pending 1
engine:background_errors 0
toplingdb_host:55125 是你的是使用 toplingdb 程序监听端口。
注意设置两个 http 请求参数:数据示例中的 “?html=0&metric=1” 部分。
- metric: ['1']
- html: ['0']
# 抓取配置列表
scrape_configs:
- job_name: 'stat-strings'
metrics_path: '/statistics/stat-strings'
params:
metric: ['1']
html: ['0']
static_configs:
- targets: ['toplingdb_host:55125']
- job_name: 'props-strings'
metrics_path: '/props/strings/default'
params:
metric: ['1']
html: ['0']
noint: ['0']
static_configs:
- targets: ['toplingdb_host:55125']
创建两个 dashboard 分别用来展示 prometheus 的 gauge 指标、counter 指标和 histogram 指标。
其他指标可以自行添加,指标内容可以通过数据示例curl请求或者直接网页打开的方式查看,推荐使用curl请求获取查看。
engine:number:superversion_acquires
histogram_quantile(0.5, rate(engine:bytes:per:write_bucket[1m]))
主要配置值:注意相关变量设置为这个值就可以了
- /toplingdb/strings
- 10005
这里使用了 docker,10005 是内部端口,映射到外部就是 55125。
参照 sideplugin/rockside/sample-conf/lcompact_community.json 修改如下
{
"http": {
"document_root": "/nvme-shared/toplingdb/strings",
"listening_ports": "10005"
},
"setenv": {
"DictZipBlobStore_zipThreads": 8,
"StrSimpleEnvNameNotOverwrite": "StringValue",
"IntSimpleEnvNameNotOverwrite": 16384,
"OverwriteThisEnv": {
"//comment": "overwrite is default to false",
"overwrite": true,
"value": "force overwrite this env by overwrite true"
}
},
"Cache": {
"clock-cache-default": {
"class-needs-TBB": "ClockCache",
"class": "LRUCache",
"params": {
"capacity": 0,
"num_shard_bits": -1,
"strict_capacity_limit": false,
"metadata_charge_policy": "kFullChargeCacheMetadata"
}
},
"lru_cache": {
"class": "LRUCache",
"params": {
"capacity": "4G",
"num_shard_bits": -1,
"strict_capacity_limit": false,
"high_pri_pool_ratio": 0.5,
"use_adaptive_mutex": false,
"metadata_charge_policy": "kFullChargeCacheMetadata"
}
}
},
"Statistics": {
"stat-strings" : {
"class": "default",
"params": {
"discard_tickers": [
"# comment",
"// comment: 可以仅指定前缀,必须是以 . 为边界的前缀,例如下面两个必须分别指定",
"rocksdb.block.cache",
"rocksdb.block.cachecompressed",
"# comment: 上面两个也可以用下面这一个概括",
"rocksdb.block",
"# 精确指定",
"rocksdb.memtable.payload.bytes.at.flush",
"rocksdb.memtable.garbage.bytes.at.flush",
"# pika 未使用 txn",
"rocksdb.txn",
"rocksdb.blobdb",
"rocksdb.row.cache",
"rocksdb.number.block",
"rocksdb.bloom.filter",
"rocksdb.persistent",
"rocksdb.sim.block.cache"
],
"discard_histograms": [
"# comment: ....",
"rocksdb.blobdb",
"rocksdb.bytes.compressed",
"rocksdb.bytes.decompressed",
"rocksdb.num.index.and.filter.blocks.read.per.level",
"rocksdb.num.data.blocks.read.per.level",
"rocksdb.compression.times.nanos",
"rocksdb.decompression.times.nanos",
"rocksdb.read.block.get.micros",
"rocksdb.write.raw.block.micros",
"# comment end of array"
],
"stats_level": "kAll",
"//stats_level": "kExceptDetailedTimers"
}
}
},
"TableFactory": {
"bb": {
"class": "BlockBasedTable",
"params": {
"checksum": "kCRC32c",
"block_size": "4K",
"block_restart_interval": 16,
"index_block_restart_interval": 1,
"metadata_block_size": "4K",
"enable_index_compression": true,
"block_cache": "${lru_cache}",
"block_cache_compressed": null,
"persistent_cache": null,
"filter_policy": null
}
},
"dispatch": {
"class": "DispatcherTable",
"params": {
"default": "bb",
"readers": {
"BlockBasedTable": "bb"
},
"level_writers": ["bb", "bb", "bb", "bb", "bb", "bb", "bb", "bb", "bb"]
}
}
},
"CFOptions": {
"default": {
"max_write_buffer_number": 4,
"write_buffer_size": "128M",
"target_file_size_base": "16M",
"target_file_size_multiplier": 2,
"table_factory": "dispatch",
"compression_per_level": [
"kNoCompression",
"kNoCompression",
"kNoCompression",
"kZlibCompression",
"kZlibCompression",
"kZlibCompression",
"kZlibCompression",
"kZlibCompression"
],
"level0_slowdown_writes_trigger": 20,
"level0_stop_writes_trigger": 36,
"//level0_file_num_compaction_trigger": -1,
"ttl": 0
}
},
"DBOptions": {
"dbo": {
"//bytes_per_sync": "2M",
"create_if_missing": true,
"create_missing_column_families": true,
"//db_paths" : "/dev/shm/db_mcf",
"max_background_compactions": 20,
"max_subcompactions": 1,
"max_level1_subcompactions": 7,
"inplace_update_support": false,
"WAL_size_limit_MB": 0,
"statistics": "${stat-strings}",
"allow_mmap_reads": true
}
},
"databases": {
"strings": {
"method": "DB::Open",
"params": {
"db_options": "$dbo",
"column_families": {
"default": "$default"
},
"//comments": "//path is optional, if not defined, use name as path",
"path": "/nvme-shared/toplingdb/strings/db_local_compact"
}
}
},
"open": "strings"
}