Prometheus入门+grafana集成

开始使用Prometheus

$ 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左右的时间)

使用内置表达式查看数据

地址:http://ip:9090/graph

Prometheus内置监控项 prometheus_target_interval_length_seconds ,将该监控项直接输入console查询,可获取数据:

![image-20190322132500188](/Users/adai/Library/Application Support/typora-user-images/image-20190322132500188.png)

使用prometheus监控服务器

上面用Prometheus本身的数据简单演示了监控数据的查询,这里我们用一个监控服务器状态的例子来更加直观说明。

为监控服务器CPU、内存、磁盘、I/O等信息,首先需要安装node_exporter。node_exporter的作用是用于机器系统数据收集。

安装node_exporter

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服务

    $ 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)

      - 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使用情况 ![image-20190322134529082](/Users/adai/Library/Application Support/typora-user-images/image-20190322134529082.png)

Prometheus Web界面自带的图表是非常基础的,比较适合用来做测试。如果要构建强大的Dashboard,还是需要更加专业的工具才行。接下来我们将使用Grafana来对Prometheus采集到的数据进行可视化展示。

prometheus集成grafana

在Grafana中添加Prometheus数据源:Configuration——DataSource——"add new DataSource"——Prometheus

  • http

  • 上述配置完成后需要导入node-exporter-server-metrics 的数据模板到grafana,两种导入方法:

    • 通过url导入:grafana——菜单栏加号➕——import—— 输入URL https://grafana.com/dashboards/405 —— 导入——Options (Name、Folder、Prometheus) —— import
    • 下载后导入:grafana——菜单栏加号➕——import—— 输入 下载 好的json文件 ——import

    完成上述操作后即可看到node-exporter采集的数据。

  • 在Dashboards上选Node Exporter Server Metrics模板,就可以看到被监控服务器的CPU, 内存, 磁盘等统计信息。

  • 在Dashboards上选Prometheus Status模板,查看Prometheus各项指标数据。

转载于:https://my.oschina.net/adailinux/blog/3026302

一、prometheus简介 Prometheus是一个开源的系统监控和告警系统,现在已经加入到CNCF基金会,成为继k8s之后第二个在CNCF维护管理的项目,在kubernetes容器管理系统中,通常会搭配prometheus进行监控,prometheus支持多种exporter采集数据,还支持通过pushgateway进行数据上报,Prometheus再性能上可支撑上万台规模的集群。 二、prometheus架构图 三、prometheus组件介绍 1.Prometheus Server: 用于收集和存储时间序列数据。 2.Client Library: 客户端库,检测应用程序代码,当Prometheus抓取实例的HTTP端点时,客户端库会将所有跟踪的metrics指标的当前状态发送到prometheus server端。 3.Exporters: prometheus支持多种exporter,通过exporter可以采集metrics数据,然后发送到prometheus server端 4.Alertmanager: 从 Prometheus server 端接收到 alerts 后,会进行去重,分组,并路由到相应的接收方,发出报警,常见的接收方式有:电子邮件,微信,钉钉, slack等。 5.Grafana:监控仪表盘 6.pushgateway: 各个目标主机可上报数据到pushgatewy,然后prometheus server统一从pushgateway拉取数据。 四、课程亮点 五、效果图展示 六、讲师简介 先超(lucky):高级运维工程师、资深DevOps工程师,在互联网上市公司拥有多年一线运维经验,主导过亿级pv项目的架构设计和运维工作 主要研究方向: 1.云计算方向:容器 (kubernetes、docker),虚拟化(kvm、Vmware vSphere),微服务(istio),PaaS(openshift),IaaS(openstack)等2.系统/运维方向:linux系统下的常用组件(nginx,tomcat,elasticsearch,zookeeper,kafka等),DevOps(Jenkins+gitlab+sonarqube+nexus+k8s),CI/CD,监控(zabbix、prometheus、falcon)等 七、课程大纲
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值