目錄
一、現狀介紹
1、背景
用es作爲prometheus的遠程存儲時,發現es特別的消耗磁盤內存,同時對於數據存入es,查看時也不太容易,es的查詢語句比較特殊,一般人還真不會寫。後期存儲的prometheus數據主要是想做統計彙總用的,感覺es做統計彙總也不太方便(可能自己不會吧),總其所有的原因,最後改用clickhouse作爲prometheus的遠程存儲。
2、組件
- prometheus-2.15.1.linux-amd64.tar.gz
- clickhouse-client-19.13.3.26-2
- prom2click
- grafana-6.2.5-1.x86_64.rpm
以上官網都有配置和簡單教程,自己安裝官網安裝即可。以下步驟,是在默認你已安裝好以上組件的基礎上進行的。
二、配置
1、clickhouse配置
需要將prometheus的metric數據存入到clickhouse裏面,首先需要做的是創建一張表,將metric數據存入到表內,所以要現在clickhouse裏面創建數據庫和表格。prometheus的數據格式是key-value格式的,如下所示:
CREATE DATABASE IF NOT EXISTS metrics;
CREATE TABLE IF NOT EXISTS metrics.samples
(
date Date DEFAULT toDate(0),
name String,
tags Array(String),
val Float64,
ts DateTime,
updated DateTime DEFAULT now()
)
ENGINE = GraphiteMergeTree(
date, (name, tags, ts), 8192, 'graphite_rollup'
);
- name用於存儲 key值,例如:jvm_gc_collection_seconds_count
- tags用於存儲Label值,例如:gc="ParNew"
- val用於存儲value值,例如:1297.0
關於clickhouse的創建表的語句,使用的是GraphiteMergeTree執行引擎,該執行引擎需要配置一個graphite_rollup,實話說本人看了很久也不懂什麼意思,如果不配置的話,創表語句會執行失敗的。需要先配置然後重啓clickhouse,再執行創表語句。需要改的地方是:/etc/clickhouse-server/config.xml.... 配置參考
<graphite_rollup>
<path_column_name>tags</path_column_name>
<time_column_name>ts</time_column_name>
<value_column_name>val</value_column_name>
<version_column_name>updated</version_column_name>
<default>
<function>avg</function>
<retention>
<age>0</age>
<precision>10</precision>
</retention>
<retention>
<age>86400</age>
<precision>30</precision>
</retention>
<retention>
<age>172800</age>
<precision>300</precision>
</retention>
</default>
</graphite_rollup>
2、prometheus配置
這個就是指定將數據寫出的端口,注意ip需要寫prome2click安裝機器的ip。
# Remote write configuration (for Graphite, OpenTSDB, InfluxDB or Clickhouse).
remote_write:
- url: "http://localhost:9201/write"
remote_read:
- url: "http://localhost:9201/read"
3、prome2click配置
官網給的安裝就三句話:......................................前提是需要安裝go語言環境,glide環境
$ make get-deps
$ make build
$ ./bin/prom2click
首先將源碼下載下來:wget https://github.com/iyacontrol/prom2click.git
執行第一句:make get-deps 報錯如下:問題1
執行第二句:make build 報錯如下:問題2
執行第三句:./bin/prom2click 報錯如下:問題3
4、grafana配置
三、安裝
四、測試
五、問題
1、make get-deps 報錯如下
#解決方法:執行
$ glide mirror set https://golang.org/x/time https://github.com/golang/time --vcs git
$ glide mirror set https://golang.org/x/crypto https://github.com/golang/crypto --vcs git
$ glide mirror set https://golang.org/x/net https://github.com/golang/net --vcs git
$ glide mirror set https://golang.org/x/tools https://github.com/golang/tools --vcs git
$ glide mirror set https://golang.org/x/text https://github.com/golang/text --vcs git
$ glide mirror set https://golang.org/x/image https://github.com/golang/image --vcs git
$ glide mirror set https://golang.org/x/sys https://github.com/golang/sys --vcs git
2、make build 報錯如下
解決方法:將prom2click/vendor文件夾下的所有文件,拷貝到/data/home/bgypub/apps/go/src/目錄下
3、./bin/prom2click 報錯如下
可能會報連接被拒絕,而且顯示的ip也並不是我們的ip和端口號
需要修改prom2click/main.go文件,修改裏面clickhouse的ip和端口號,然後重新執行make build,再執行./bin/prom2click 出現如下,表示啓動成功。。。。
歡迎留言評論!