什么是Prometheus?
Prometheus是由SoundCloud開發(fā)的開源監(jiān)控報(bào)警系統(tǒng)和時序列數(shù)據(jù)庫(TSDB)。Prometheus使用Go語言開發(fā)颠锉,是Google BorgMon監(jiān)控系統(tǒng)的開源版本己儒。
2016年由Google發(fā)起Linux基金會旗下的原生云基金會(Cloud Native Computing Foundation), 將Prometheus納入其下第二大開源項(xiàng)目记焊。Prometheus目前在開源社區(qū)相當(dāng)活躍芳杏。
Prometheus和Heapster(Heapster是K8S的一個子項(xiàng)目豫领,用于獲取集群的性能數(shù)據(jù)抡柿。)相比功能更完善、更全面氏堤。Prometheus性能也足夠支撐上萬臺規(guī)模的集群沙绝。
Prometheus的特點(diǎn)
- 多維度數(shù)據(jù)模型。
- 靈活的查詢語言鼠锈。
- 不依賴分布式存儲闪檬,單個服務(wù)器節(jié)點(diǎn)是自主的。
- 通過基于HTTP的pull方式采集時序數(shù)據(jù)购笆。
- 可以通過中間網(wǎng)關(guān)進(jìn)行時序列數(shù)據(jù)推送粗悯。
- 通過服務(wù)發(fā)現(xiàn)或者靜態(tài)配置來發(fā)現(xiàn)目標(biāo)服務(wù)對象。
- 支持多種多樣的圖表和界面展示同欠,比如Grafana等样傍。
安裝步驟
本文中安裝環(huán)境為mac,其他環(huán)境的安裝請自行到官網(wǎng)查看:
下載解壓
在官網(wǎng) 下在最新版本壓縮包:prometheus-2.3.0.darwin-amd64.tar.gz
解壓并進(jìn)入該目錄:
tar xvfz prometheus-*.tar.gz
cd prometheus-*
修改配置文件
本文將配置文件修改為檢測Prometheus自身:
修改配置文件為:
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
配置文件具體含義: configuration documentation
啟動Prometheus
在當(dāng)前文件夾中啟動Prometheus:
# Start Prometheus.
# By default, Prometheus stores its database in ./data (flag --storage.tsdb.path).
./prometheus --config.file=prometheus.yml
在瀏覽器頁面 localhost:9090 中就可以看到Prometheus的web頁面了:
Grafana
Grafana安裝
安裝步驟參考grafana官方文檔:http://docs.grafana.org/installation/mac/
使用homebrew安裝:
brew update
brew install grafana
安裝成功后你可以使用默認(rèn)配置啟動:
brew services start grafana
登錄
使用默認(rèn)賬號密碼 : admin/admin 登錄
在首頁點(diǎn)擊添加數(shù)據(jù)源铺遂,Grafana默認(rèn)支持Prometheus衫哥,不需要其他的插件
配置Prometheus數(shù)據(jù)源:
點(diǎn)擊右側(cè)Dashboards,import三個數(shù)據(jù)源襟锐,點(diǎn)擊任意一個就可以查看它的dashboard了撤逢。
Grafana基本操作
新建Dashboard
新建圖表
導(dǎo)入圖表
新建數(shù)據(jù)源
Type 選 Prometheus, 填好URL粮坞,如果是Prometheus默認(rèn)的配置蚊荣,那么就是
http://localhost:9090