CentOS7搭建Prometheus监控Linux主机
1.下载安装Prometheus
下载地址:https://github.com/prometheus/prometheus/releases
下载完成后,解压缩
tar -xzvf prometheus-*.tar.gz
进入解压缩后的目录
cd prometheus-*
执行安装命令
./configure --prefix=/usr/local/prometheus/
make && make install
2.配置Prometheus
进入安装目录
cd /usr/local/prometheus/
新建配置文件
vim prometheus.yml
global: scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute. # A scrape configuration containing exactly one endpoint to scrape: # Here it is scraping itself. scrape_configs: # The job name is added as a label `job=` 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 scrape_timeout: 5s # metrics_path defaults to '/metrics' # scheme defaults to 'http'. metrics_path: /metrics scheme: http # A scrape configuration for running Apache exporters on specific ports: - job_name: 'apache' scrape_interval: 5s scrape_timeout: 5s metrics_path: /metrics scheme: http # scrape_configs contains job definitions. scrape_configs: # The job name is added as a label job= to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. metrics_path: /metrics scheme: http # A scrape configuration for running Apache exporters on specific ports: - job_name: 'apache' scrape_interval: 5s scrape_timeout: 5s metrics_path: /metrics scheme: http # The job name is added as a label job= to any timeseries scraped from this config. - job_name: 'node' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s scrape_timeout: 5s metrics_path: /metrics scheme: http # A scrape configuration for running Apache exporters on specific ports: - job_name: 'apache' scrape_interval: 5s scrape_timeout: 5s metrics_path: /metrics scheme: http # The job name is added as a label job= to any timeseries scraped from this config. - job_name: 'mysql' # Override the global default and scrape targets from this job every 5 seconds. scrape_interval: 5s scrape_timeout: 5s metrics_path: /metrics scheme: http
3.启动Prometheus
./prometheus --config.file=prometheus.yml
4.查看Prometheus监控状态
curl http://localhost:9090/status
5.停止Prometheus
./prometheus --config.file=prometheus.yml --storage.tsdb.path=data --web.console.templates=consoles --web.console.libraries=console_libraries
6.查看Prometheus监控数据
curl http://localhost:9090/metrics
7.查看Prometheus监控图表
http://localhost:9090/graph