1
活動/聚會區 / Re: 2018 9月份 SA@Taipei Nextcloud 簡單分享 + 入門普羅米修斯
« 於: 2018-09-15 18:59 »
幫忙補充關於 Prometheus
有人問到 scrape_interval 的設定如下最上面的是global設定,然後每個scrape_configs job也可以設定
藍色的是全域,綠色的就是只針對這個 job
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']
另外在 Production 環境用 Docker 起 Prometheus 與 Grafana 因為他們都有資料要儲存,所以都要用到 Volume
Prometheus 官方預設的 Docker Image後端資料是存在 /prometheus,因為他參數是 --storage.tsdb.path=/prometheus
因為需要經常改設定檔不想每次用 docker exec 進去容器,所以也會把 Prometheus 的 YAML 也都用成 Volume
這樣可以在外面改 prometheus.yml 設定,然後要讓 Prometheus 重新載入設定可以送 HUP Signal
另一個讓Prometheus 重新讀去設定檔的做法是可以向prometheus發送 HTTP POST,不過因為官方 Docker Image 預設沒有加參數 --web.enable-lifecycle
所以要自己 Build Image 加上該參數才能這樣用
今天HaWay教的是基本用的是static_configs
對於監控數量多的公司要使用支援的服務發現機制來做 dynamically discovered 監控
目前支援的服務發現機制有 DNS, kubernetes, GCE, ec2, Azure, consul, openstack .....還蠻多的可以參考
https://prometheus.io/docs/prometheus/latest/configuration/configuration/
另外 Exporter 除了用限制 IP以外,因為我們公司的架構有 API gateway 所以比如 RD開發的程式有 Exporter功能
Prometheus 也支援類似的設定如下,要給 API key 才可以 Scrape 的到資料
Prometheus 資料儲存,如果不給參數的話預設是15天,參數是 --storage.tsdb.retention,參考官方文件如下
https://prometheus.io/docs/prometheus/latest/storage/
另外提到的 Prometheus 做 HA 跟資料集中的三方架構的設計可以參考這裡,只不過我也還沒實作沒辦法介紹就是
https://github.com/improbable-eng/thanos/blob/master/docs/design.md
Grafana的話支援多種儲存,存放路徑在 /var/lib/grafana
其實主要是存一些設定資料 json 檔跟plugin,資料部分預設好像是SQLite ,其實量不大也可以把資料存到資料庫比如Postgresql
Grafana 的話就有帳號密碼的驗證機制了,也支援Oauth等,直接用環境變數帶入來設定很方便可以參考官方文件
http://docs.grafana.org/installation/docker/
有人問到 scrape_interval 的設定如下最上面的是global設定,然後每個scrape_configs job也可以設定
藍色的是全域,綠色的就是只針對這個 job
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']
另外在 Production 環境用 Docker 起 Prometheus 與 Grafana 因為他們都有資料要儲存,所以都要用到 Volume
Prometheus 官方預設的 Docker Image後端資料是存在 /prometheus,因為他參數是 --storage.tsdb.path=/prometheus
因為需要經常改設定檔不想每次用 docker exec 進去容器,所以也會把 Prometheus 的 YAML 也都用成 Volume
這樣可以在外面改 prometheus.yml 設定,然後要讓 Prometheus 重新載入設定可以送 HUP Signal
代碼: [選擇]
docker exec <CONTAINER_ID_OR_NAME> kill -HUP 1
另一個讓Prometheus 重新讀去設定檔的做法是可以向prometheus發送 HTTP POST,不過因為官方 Docker Image 預設沒有加參數 --web.enable-lifecycle
所以要自己 Build Image 加上該參數才能這樣用
代碼: [選擇]
curl -XPOST http://<Prometheus_IP_OR_FQDN>/-/reload
今天HaWay教的是基本用的是static_configs
對於監控數量多的公司要使用支援的服務發現機制來做 dynamically discovered 監控
目前支援的服務發現機制有 DNS, kubernetes, GCE, ec2, Azure, consul, openstack .....還蠻多的可以參考
https://prometheus.io/docs/prometheus/latest/configuration/configuration/
另外 Exporter 除了用限制 IP以外,因為我們公司的架構有 API gateway 所以比如 RD開發的程式有 Exporter功能
Prometheus 也支援類似的設定如下,要給 API key 才可以 Scrape 的到資料
代碼: [選擇]
- job_name: 'my-prod-app'
scrape_interval: 30s
metrics_path: /app/v1/_metrics
params:
apikey: ['<KEY>']
scheme: https
static_configs:
- targets: ['api.example.com']
Prometheus 資料儲存,如果不給參數的話預設是15天,參數是 --storage.tsdb.retention,參考官方文件如下
https://prometheus.io/docs/prometheus/latest/storage/
另外提到的 Prometheus 做 HA 跟資料集中的三方架構的設計可以參考這裡,只不過我也還沒實作沒辦法介紹就是
https://github.com/improbable-eng/thanos/blob/master/docs/design.md
Grafana的話支援多種儲存,存放路徑在 /var/lib/grafana
其實主要是存一些設定資料 json 檔跟plugin,資料部分預設好像是SQLite ,其實量不大也可以把資料存到資料庫比如Postgresql
Grafana 的話就有帳號密碼的驗證機制了,也支援Oauth等,直接用環境變數帶入來設定很方便可以參考官方文件
http://docs.grafana.org/installation/docker/