安装Prometheus

安装Prometheus仅需在server1上安装。

  1. 进入Prometheus目录。

    1
    cd /opt/prometheus/prometheus-2.45.4.linux-arm64/
    

  2. 配置prometheus.yml。

    1. 打开文件。
      1
      vi prometheus.yml
      
    2. “i”进入编辑模式,配置为如下内容。
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      # my global config
      global:
        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).
      # Alertmanager configuration
      alerting:
        alertmanagers:
          - static_configs:
              - targets:
                # - alertmanager:9093
      # Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
      rule_files:
        # - "first_rules.yml"
        # - "second_rules.yml"
      # 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:9060"]
        - job_name: node_exporter
          honor_timestamps: true
          scrape_interval: 1s
          scrape_timeout: 1s
          metrics_path: /metrics
          scheme: http
          follow_redirects: true
          static_configs:
            - targets: ["agent1:9100","agent2:9100","agent3:9100"]
        - job_name: 'loads_metric'
          static_configs:
            - targets: ['server1:9090']
          metrics_path: '/loadIndicator/get/byCurrTimeForPrometheus'
          scheme: 'http'
          honor_labels: true
          scrape_interval: 1s
        - job_name: 'loads_metric_detail'
          static_configs:
            - targets: ['server1:9090']
          metrics_path: '/loadStatus/get/byCurrTimeForPrometheus'
          scheme: 'http'
          honor_labels: true
          scrape_interval: 1s
      

      若计算节点不为agent1/agent2/agent3,请按照实际集群规划修改如下行。

      1
      - targets: ["agent1:9100","agent2:9100","agent3:9100"]
      
    3. “Esc”键,输入:wq!,按“Enter”保存并退出编辑。

  3. 启动Prometheus。

    1
    nohup ./prometheus --web.listen-address="0.0.0.0:9060" &
    

  4. 验证部署是否成功。

    1
    2
    # 调用接口
    http://server1:9060/targets
    

    显示界面如上,loads_metric、loads_metric_detail以及node_exporter均为UP状态。

    在server1的LoadsMetricApplication进程和计算节点Node Exporter已启动的情况下,Prometheus界面如上接口应均为UP状态。

  5. 停止Prometheus服务。

    1. 找到Prometheus服务进程ID。
      ps -aux | grep prometheus
    2. 使用Kill命令停止Prometheus。
      kill ID