今天看到德哥分享的基于postgresql的prometheus數(shù)據(jù)遠(yuǎn)端存儲(chǔ)方案,于是有了本文的實(shí)驗(yàn)。
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比石拐網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式石拐網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋石拐地區(qū)。費(fèi)用合理售后完善,10多年實(shí)體公司更值得信賴。通常,prometheus的外置存儲(chǔ)方案有好幾種選擇,例如influxdb,m3db, es,postgresql。
m3db一般在云原生環(huán)境下,用的更趁手些。
這里我們演示下postgresql的遠(yuǎn)端存儲(chǔ)方案(可讀可寫),具體看下面的實(shí)驗(yàn)。
實(shí)驗(yàn)環(huán)境:
CentOS7.4
PG11-git-1921 編譯安裝版
參考文檔:?
https://blog.csdn.net/qq_43303221/article/details/88574693#cmake_34_50? ?編譯安裝 TimescaleDB 擴(kuò)展
https://studygolang.com/articles/13522?fr=sidebar? ?遠(yuǎn)端存儲(chǔ)的介紹
https://github.com/timescale/prometheus-postgresql-adapter? ?prometheus-postgresql-adapter的官方文檔介紹
https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write? 官方文檔
https://github.com/digoal/blog/blob/master/201910/20191027_04.md? ? 德哥blog
https://github.com/timescale/pg_prometheus? ? ?pg_prometheus擴(kuò)展的官方文檔
1、安裝llvm
yum?install?centos-release-scl-rh yum?install?llvm-toolset-7-clang yum?install?llvm5.0? yum?install?llvm5.0-libs yum?install?llvm5.0-devel yum?install?clang2、安裝cmake-3.4以上的版本
cd?/usr/local/ wget?https://github.com/Kitware/CMake/releases/download/v3.16.0-rc2/cmake-3.16.0-rc2-Linux-x86_64.sh sh?cmake-3.16.0-rc2-Linux-x86_64.sh 即可在當(dāng)前路徑下安裝cmake-3.16 載入cmake-3.16到環(huán)境變量: export?PATH=/usr/local/cmake-3.16.0-rc2-Linux-x86_64/bin:$PATH3、編譯安裝PG11帶jit模塊
su?-?postgres cd?/home/postgres/ wget?? yum?localinstall?epel-release-latest-7.noarch.rpm yum?install?llvm5.0?llvm5.0-devel?clang cd?/home/postgres/pg_sources/postgresql-11 ./configure?--prefix=/usr/local/pgsql-11.5-jit-1921?\ --with-python?--with-perl?--with-tcl?--with-pam?\ --with-openssl?--with-libxml?--with-libxslt?\ --with-llvm?LLVM_CONFIG='/usr/lib64/llvm5.0/bin/llvm-config' make? make?install? 然后,還有些數(shù)據(jù)庫的基礎(chǔ)配置,這里就不細(xì)說了。4、安裝TimescaleDB擴(kuò)展
su?-?postgres cd?/home/postgres/ cd?timescaledb-1.4.2/ export?PATH=/usr/local/pgsql-11.5-jit-1921/bin:$PATH ./bootstrap?輸入y cd?./build?&&?make make?install??日志如下: [??0%]?Built?target?sqlfile [?25%]?Built?target?sqlupdatescripts [?81%]?Built?target?timescaledb [?85%]?Built?target?timescaledb-loader [100%]?Built?target?timescaledb-tsl Install?the?project... --?Install?configuration:?"Release" --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb.control --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.4.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.4.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.4.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.3.2--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.3.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.3.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.2.2--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.2.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.2.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.1.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.1.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.0.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.0.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.0.0-rc3--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.0.0-rc2--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--1.0.0-rc1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.12.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.12.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.11.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.10.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.10.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.9.2--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.9.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.9.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.8.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.7.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.7.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.6.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.6.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.5.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.4.2--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.4.1--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.4.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.3.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.2.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/share/extension/timescaledb--0.1.0--1.4.2.sql --?Installing:?/usr/local/pgsql-11.5-jit-1921/lib/timescaledb-1.4.2.so --?Installing:?/usr/local/pgsql-11.5-jit-1921/lib/timescaledb.so --?Installing:?/usr/local/pgsql-11.5-jit-1921/lib/timescaledb-tsl-1.4.2.so即可完成timescaledb擴(kuò)展的安裝
編輯pg的配置文件,修改如下:
shared_preload_libraries?=?'timescaledb'完成后重啟PG進(jìn)程
然后,登錄到PG中,創(chuàng)建擴(kuò)展:
postgres=#?CREATE?EXTENSION?timescaledb;5、安裝pg_prometheus擴(kuò)展
su?-?postgres cd?/home/postgres/ export?PATH=/usr/local/pgsql-11.5-jit-1921/bin:$PATH USE_PGXS=1?make?? USE_PGXS=1?make?install編輯pg的配置文件,修改如下:
shared_preload_libraries?=?'timescaledb,pg_prometheus'完成后重啟PG進(jìn)程
然后,登錄到PG中,創(chuàng)建擴(kuò)展:
postgres=#?CREATE?EXTENSION?pg_prometheus?; postgres=#?SELECT?create_prometheus_table('metrics');???或者使用?SELECT?create_prometheus_table('metrics',use_timescaledb=>true); postgres=#?INSERT?INTO?metrics?VALUES?('cpu_usage{service="nginx",host="machine1"}?34.6?1494595898000');?? postgres=#?\d ??????????????????List?of?relations ?Schema?|?????????Name??????????|???Type???|??Owner??? --------+-----------------------+----------+---------- ?public?|?metrics???????????????|?view?????|?postgres ?public?|?metrics_copy??????????|?table????|?postgres ?public?|?metrics_labels????????|?table????|?postgres ?public?|?metrics_labels_id_seq?|?sequence?|?postgres ?public?|?metrics_values????????|?table????|?postgres (5?rows)6、啟動(dòng)prometheus-postgresql-adapter
直接到https://github.com/timescale/prometheus-postgresql-adapter?下載解壓prometheus-postgresql-adapter
./prometheus-postgresql-adapter?-pg-port?1921?--pg-user?postgres??即可在前臺(tái)啟動(dòng)adapter進(jìn)程7、使用prometheus連接adapter端口:
vim /usr/local/prometheus/prometheus.yml? 在最后加2個(gè)配置;
remote_write: ?-?url:?"http://192.168.2.4:9201/write" ???write_relabel_configs: ??????-?source_labels:?[__name__] ????????regex:?'go_.*' ????????action:?drop remote_read: ??-?url:?"http://192.168.2.4:9201/read" ????read_recent:?false說明: 我這里設(shè)置的read_recent為false,表示查詢prometheus近期數(shù)據(jù)不要到PG庫里來撈數(shù)據(jù),而是直接查prometheus本地緩存的數(shù)據(jù),這樣提高查詢的速度并且能降低PG庫的負(fù)載。
不足:
目前的配置來看,我們同事運(yùn)行的prometheus和PG庫, 存放同樣歷史周期的的metrics,PG庫的體積遠(yuǎn)遠(yuǎn)超過了prometheus的體積。
PG庫的metrics_values表已經(jīng) 40 MB,此時(shí)的prometheus的data目錄才 16MB 。 磁盤空間占用上,相差接近3倍。
優(yōu)化方案待定:
調(diào)整remote_write 寫入策略,通過drop操作來降低存儲(chǔ)到PG的metrics的體積?
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
當(dāng)前題目:Prometheus遠(yuǎn)端數(shù)據(jù)存儲(chǔ)方案之PostgreSQL-創(chuàng)新互聯(lián)
網(wǎng)頁地址:http://muchs.cn/article20/pegjo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、微信公眾號(hào)、營銷型網(wǎng)站建設(shè)、品牌網(wǎng)站制作、面包屑導(dǎo)航、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容