zoukankan      html  css  js  c++  java
  • Prometheus安装(采用 influxdb)

    一、安装Prometheus

    # 获取软件
    $ wget https://github.com/prometheus/prometheus/releases/download/v2.20.1/prometheus-2.20.1.linux-amd64.tar.gz
    $ groupadd prometheus
    $ useradd -g prometheus -m -d /usr/local/prometheus -s /sbin/nologin prometheus
    $ tar zxf prometheus-2.24.1.linux-amd64.tar.gz
    $ mv prometheus-2.24.1.linux-amd64/* /usr/local/prometheus
    $ sed -i 's/localhost/10.4.7.100/g' /usr/local/prometheus/prometheus.yml 
    
    # 创建systemd服务
    $ cat <<EOF > /usr/lib/systemd/system/prometheus.service
    [Unit]
    Description=prometheus
    After=network.target
    [Service]
    Type=simple
    User=prometheus
    WorkingDirectory=/usr/local/prometheus          # 如果添加这一行,可以不指定配置文件(--config.file=/usr/local/prometheus/prometheus.yml)
    ExecStart=/usr/local/prometheus/prometheus   --web.enable-lifecycle 
    Restart=on-failure
    [Install]
    WantedBy=multi-user.target
    EOF
    # --web.enable-lifecycle: 支持通过http请求重载配置
    # 启动服务
    $ systemctl daemon-reload
    $ systemctl start prometheus
    $ systemctl status prometheus && systemctl enable prometheus
    
    # 确认端口已经被监听
    $ ss -lnput | grep 9090
    tcp    LISTEN     0      1024     :::9090                 :::*                   users:(("prometheus",pid=8257,fd=7))
    

    二、后端存储配置

    默认情况下prometheus会将采集的数据防止到本机的data目录的, 存储数据的大小受限和扩展不便,这是使用influxdb作为后端的数据库来存储数据。

    三、 influxdb安装配置

    influxdb的官方文档地址为: https://docs.influxdata.com/influxdb/v1.7/introduction/downloading/ 根据不同系统进行下载,这里使用官方提供的rpm进行安装。

    # 获取软件包
    $ wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.8.x86_64.rpm
    # 本地安装
    $ yum localinstall influxdb-1.7.8.x86_64.rpm
    
    # 备份默认的默认的配置文件,这里可以对influxdb的数据存放位置做些设置
    $ cp /etc/influxdb/influxdb.conf  /etc/influxdb/influxdb.conf.default
    
    # 启动
    $ systemctl start influxdb && systemctl enable influxdb
    # 查看状态
    $ systemctl status influxdb
    # 查看端口是否监听
    $ ss -lnput | grep 8086
    tcp    LISTEN     0      1024     :::8086                 :::*                   users:(("influxd",pid=9405,fd=5))
    

    创建一个Prometheus数据库

    $ influx                                     # 登录influxdb数据库
    > create database prometheus;                # 创建prometheus数据库
    > show databases;                            # 查看数据库
    name: databases 
    name
    ----
    _internal
    prometheus                        
    > exit                                          # 退出
    

    四、 配置prometheus集成infludb

    官方的帮助文档在这里: https://docs.influxdata.com/influxdb/v1.7/supported_protocols/prometheus/

    $ vim /usr/local/prometheus/prometheus.yml
    # 添加如下几行
    remote_write:
      - url: "http://10.4.7.100:8086/api/v1/prom/write?db=prometheus"
    
    remote_read:
      - url: "http://10.4.7.100:8086/api/v1/prom/read?db=prometheus"
    
    $ systemctl restart prometheus 
    $ systemctl status prometheus
    

    注意: 如果influxdb配置有密码, 请参考上面的官方文档地址进行配置。

    五、测试数据是否存储到influxdb中

    $ influx
    > show databases;
    name: databases
    name
    ----
    _internal
    prometheus
    > use prometheus
    Using database prometheus
    > show measures;
    ERR: error parsing query: found measures, expected CONTINUOUS, DATABASES, DIAGNOSTICS, FIELD, GRANTS, MEASUREMENT, MEASUREMENTS, QUERIES, RETENTION, SERIES, SHARD, SHARDS, STATS, SUBSCRIPTIONS, TAG, USERS at line 1, char 6
    > show MEASUREMENTS;
    name: measurements
    name
    ----
    go_gc_duration_seconds
    go_gc_duration_seconds_count
    go_gc_duration_seconds_sum
    go_goroutines
    go_info
    go_memstats_alloc_bytes
    # 后面还是有很多,这里不粘贴了。
    
    # 做个简单查询
    > select * from prometheus_http_requests_total limit 10 ; 
    name: prometheus_http_requests_total
    time                __name__                       code handler  instance       job        value
    ----                --------                       ---- -------  --------       ---        -----
    1568975686217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 1
    1568975701216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 2
    1568975716218000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 3
    1568975731217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 4
    1568975746216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 5
    1568975761217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 6
    1568975776217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 7
    1568975791217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 8
    1568975806217000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 9
    1568975821216000000 prometheus_http_requests_total 200  /metrics localhost:9090 prometheus 10
    
    *************** 当你发现自己的才华撑不起野心时,就请安静下来学习吧!***************
  • 相关阅读:
    整数因子分解问题(递归分治法、动态规划)
    背包问题(动态规划 C/C++)
    划分问题(Java 动态规划)
    算法:Common Subsequence(动态规划 Java 最长子序列)
    算法:矩阵连乘(Java)动态规划
    Frogs‘ Neighborhood(POJ 1659 C/C++)
    算法:线性时间选择(C/C++)
    sort(hdu oj 1425)计数排序和快速排序
    快速排序(递归和分治)
    a^b(取模运算)
  • 原文地址:https://www.cnblogs.com/lvzhenjiang/p/14378534.html
Copyright © 2011-2022 走看看