$ systemctl start prometheus $ netstat -lntp tcp6 0 0 :::9090 :::* LISTEN 19824/./prometheus
在浏览器访问:http://ip:9090/graph
。Prometheus会把自身做为一个项目进行自监控,查看收集到监控项:http://172.16.180.129:9090/metrics
(若是是首次启动,须要等待30s左右的时间)node
地址:http://ip:9090/graph
linux
Prometheus内置监控项 prometheus_target_interval_length_seconds
,将该监控项直接输入console查询,可获取数据:git
github
上面用Prometheus自己的数据简单演示了监控数据的查询,这里咱们用一个监控服务器状态的例子来更加直观说明。json
为监控服务器CPU、内存、磁盘、I/O等信息,首先须要安装node_exporter。node_exporter的做用是用于机器系统数据收集。vim
node_exporter也是用Golang实现,直接使用预编译的二进制文件部署,开箱即用。浏览器
$ cd /home/prometheus && wget https://github.com/prometheus/node_exporter/releases/download/v0.17.0/node_exporter-0.17.0.linux-amd64.tar.gz $ tar zxvf node_exporter-0.17.0.linux-amd64.tar.gz $ mv node_exporter-0.17.0.linux-amd64 /usr/local/prometheus/node_exporter
建立systemd服务bash
$ vim /usr/lib/systemd/system/node_exporter.service [Unit] Description=node_exporter After=network.target [Service] Type=simple User=prometheus ExecStart=/usr/local/prometheus/node_exporter/node_exporter Restart=on-failure [Install] WantedBy=multi-user.target
启动node_exporter服务器
$ systemctl start node_exporter $netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp6 0 0 :::9100 :::* LISTEN 24126/node_exporter
修改prometheus.yml,加入下面的监控目标(node_exporter默认的抓取地址为http://ip:9100
)tcp
- job_name: 'linux' static_configs: - targets: ['localhost:9100'] labels: instance: node1
说明:prometheus.yml中一共定义了两个监控,一个是监控prometheus自身服务,另外一个是监控Linux服务器。
这里给一个完整示例:
scrape_configs: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090'] - job_name: 'linux' static_configs: - targets: ['localhost:9100'] labels: instance: node1
重启prometheus服务
$ systemctl restart prometheus
在Prometheus Web查看监控的目标:访问Prometheus Web,在Status->Targets页面下,咱们能够看到咱们配置的两个Target(linux和prometheus),它们的State为UP。
查看memory使用状况 
Prometheus Web界面自带的图表是很是基础的,比较适合用来作测试。若是要构建强大的Dashboard,仍是须要更加专业的工具才行。接下来咱们将使用Grafana来对Prometheus采集到的数据进行可视化展现。
在Grafana中添加Prometheus数据源:Configuration——DataSource——"add new DataSource"——Prometheus
http
上述配置完成后须要导入node-exporter-server-metrics 的数据模板到grafana,两种导入方法:
https://grafana.com/dashboards/405
—— 导入——Options (Name、Folder、Prometheus) —— import完成上述操做后便可看到node-exporter采集的数据。
在Dashboards上选Node Exporter Server Metrics模板,就能够看到被监控服务器的CPU, 内存, 磁盘等统计信息。
在Dashboards上选Prometheus Status模板,查看Prometheus各项指标数据。