关于监控这方面zabbix和nagios大家并不陌生,但是最近prometheus确实很火热,趁着这段时间,我也试了一试。 在我目前的认知里,我觉得prometheus也是C/S架构的东西,只是数据变
关于监控这方面zabbix和nagios大家并不陌生,但是最近prometheus确实很火热,趁着这段时间,我也试了一试。
在我目前的认知里,我觉得prometheus也是C/S架构的东西,只是数据变成了以时间为序列的方式。
准备工作
环境ubuntu16.04 lts
prometheus-2.0.0-beta.0.linux-amd64.tar.gz
node_exporter-0.14.0.linux-amd64.tar.gz
grafana_4.4.2_amd64.deb
安装就不多说了,官网都有。直接解压启动即可,grafana这个包,需要先dpkg -i grafana_4.4.2_amd64.deb 然后apt-get -f install一下就好了
root@ansible:/opt# lltotal 68556drwxr-xr-x 5 root root 4096 Aug 4 14:07 ./drwxr-xr-x 23 root root 4096 Aug 4 07:28 ../-rw-r--r-- 1 root root 47468006 Aug 1 15:31 grafana_4.4.2_amd64.debdrwxrwxr-x 2 jastme jastme 4096 Aug 3 09:59 node_exporter/-rw-r--r-- 1 root root 4019675 May 26 01:01 node_exporter-0.14.0.linux-amd64.tar.gzdrwxrwxr-x 5 jastme jastme 4096 Aug 3 10:38 prometheus/-rw-r--r-- 1 root root 18687961 Jul 12 21:08 prometheus-2.0.0-beta.0.linux-amd64.tar.gzdrwxr-xr-x 2 root root 4096 Aug 4 10:11 study_go/
root@ansible:/opt/prometheus# more prometheus.yml # my global configglobal: 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. # scrape_timeout is set to the global default (10s). # Attach these labels to any time series or alerts when communicating with # external systems (federation, remote storage, Alertmanager). external_labels: monitor: 'codelab-monitor'# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.rule_files: # - "first.rules" # - "second.rules"# 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' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['localhost:9090'] - job_name: 'node_exporter' static_configs: - targets: ['192.168.126.130:9100']
我们在这里新增了一个配置,因为我们需要使用node_exporter来提取客户机的需要监控的数据
root@ansible:/opt/prometheus# netstat -ntplActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program nametcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 33619/sshd tcp6 0 0 :::9100 :::* LISTEN 62034/node_exportertcp6 0 0 :::22 :::* LISTEN 33619/sshd tcp6 0 0 :::3000 :::* LISTEN 62661/grafana-servetcp6 0 0 :::9090 :::* LISTEN 62221/prometheus
分别启动组件
访问promethues
在导航栏点击status--》target 可以看见
我们的node_exporter已经正常工作,点击进去即可看见详细的数据
好了,现在我们使用grafana来出图
grafana的基本操作我就不多说了
生成一个新的datasource
然后开始在dashbord里面生成图片
搜索下你需要的metric就可以了,很简单
我们按照node_exporter给出的数据处理 样图
如果这不是你需要的。那么你就需要自己写一个exporter来生成数据,然后利用promethues来获取
下次我们就尝试下如何自己写一个exporter来提取我们自己需要的监控数据吧。