美文网首页
prometheus+grafana(一)

prometheus+grafana(一)

作者: __Avicii | 来源:发表于2020-07-22 16:34 被阅读0次

    prometheus+grafana部署

    prometheus部署

    • OS: Ubuntu 20.04 LTS x86_64

    下载地址

    下载安装

    tar zxvf prometheus-2.6.1.linux-amd64.tar.gz
    cd prometheus-*
    # 配置文件
    cp prometheus.yml prometheus.yml_bak
    # 模块说明:global、rule_files、scrape_configs
        global: 全局配置
            - scrape_interval: 默认抓取周期,可用单位ms,默认15s
            - scrape_timeout: 默认抓取超时
            - evaluation_interval: 计算规则周期,默认15s
            - external_labels: 和外部系统通信时为时间序列或者alert强制添加的标签列表
        rule_files: 规则文件列表
        scrape_configs: 抓取配置列表
    

    启动

    ./prometheus --config.file=prometheus.yml
    
    • 启动脚本(根据环境自行修改)
    #!/bin/bash
    prefix=/usr/local/prometheus/prometheus
    exec_prefix=${prefix}
    prometheus_BIN=${exec_prefix}/prometheus
    prometheus_LOG=${exec_prefix}/log/prometheus.log
    prometheus_PID=${exec_prefix}/pid
    case "$1" in
            start)
                    if [[ -f $prometheus_PID ]]
                    then
                            if [[ ! -z `cat $prometheus_PID` ]]
                            then
                                    echo -n "prometheus is running"
                                    exit 0
                            fi
                    fi
                    echo -e "starting prometheus \n"
    # --web.enable-lifecycle:远程热加载配置文件
                    /usr/bin/nohup $prometheus_BIN --config.file="$exec_prefix/prometheus.yml" --web.listen-address="0.0.0.0:9090" --storage.tsdb.path="$exec_prefix/data/" --storage.tsdb.retention=365d --web.enable-lifecycle > $prometheus_LOG 2>&1 &
                    echo $! > $prometheus_PID
                    ;;
            stop)
                    if [[ ! -z `cat $prometheus_PID` ]]
                    then
                            echo -e "Stop prometheus \n"
                            cat $prometheus_PID | xargs kill -9
                    else
                            echo -n "prometheus not running"
                    fi
                    echo > $prometheus_PID
                    ;;
            status)
                    if [[ -z `cat $prometheus_PID` ]]
                    then
                            echo "prometheus is stopped"
                    else
                            echo "prometheus is running"
                    fi
                    ;;
            reload)
                    if [[ -f $prometheus_PID ]]
                    then
                            kill `cat $prometheus_PID`
                    fi
                    ;;
            restart)
                    $0 stop
                    $0 start
                    ;;
            *)
                    echo "Usage: $0 {start|stop|status|reload|restart}"
                    exit 1
                    ;;
    esac
    

    访问

    表达式文档

    添加节点

    node_exporter相关文档

    cd /usr/local/prometheus/node_exporter
    wget https://github.com/prometheus/node_exporter/releases/download/v*/node_exporter-*.*-amd64.tar.gz
    tar xvfz node_exporter-*.*-amd64.tar.gz
    cd node_exporter-*.*-amd64
    # 运行
    ./node_exporter
    netstat -ntlp | grep 9100
        tcp6       0      0 :::9100                 :::*                    LISTEN      13848/./node_export
    # 在prometheus添加target
    cat prometheus.yml -n
            21  scrape_configs:
            22    # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
            23    - job_name: 'prometheus'
            24      static_configs:
            25        - targets: ['localhost:9090']
            26  
            27    - job_name: 'node_exporter'
            28      static_configs:
            29        - targets: ['localhost:9100']
    
    • 查看配置结果:添加成功

      ! prometheus添加节点结果图.png

    grafana部署

    grafana配置prometheus文档

    下载安装

    下载地址

    wget https://dl.grafana.com/oss/release/grafana_7.1.0_amd64.deb
    dpkg -i grafana_7.1.0_amd64.deb
    cd /etc/grafana
    cp grafana.ini grafana.ini_bak
    

    启动

    systemctl start grafana-server
    

    访问

    http://localhost:3000
    

    参考:
    https://prometheus.io/docs/introduction/first_steps/
    https://www.jianshu.com/p/8d2c020313f0

    相关文章

      网友评论

          本文标题:prometheus+grafana(一)

          本文链接:https://www.haomeiwen.com/subject/trrtlktx.html