我要评分
获取效率
正确性
完整性
易理解

Installing Prometheus

Install Prometheus only on the server1 node only.

  1. Go to the Prometheus directory.
    1
    cd /opt/prometheus/prometheus-2.45.4.linux-arm64/
    
  2. Configure the prometheus.yml file.
    1. Open the file.
      1
      vi prometheus.yml
      
    2. Press i to enter the insert mode and modify the file as follows:
       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
      

      If the compute nodes are not agent1, agent2, and agent3, modify the following lines based on the actual node names:

      1
      - targets: ["agent1:9100","agent2:9100","agent3:9100"]
      
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Start Prometheus.
    1
    nohup ./prometheus --web.listen-address="0.0.0.0:9060" &
    
  4. Check whether the deployment is successful.
    1
    2
    # Call the API.
    http://server1:9060/targets
    

    As shown in the preceding figure, loads_metric, loads_metric_detail, and node_exporter are all in the UP state.

    When the LoadsMetricApplication process is running on server1 and Node Exporter is running on the compute nodes, the preceding APIs must be in the UP state.

  5. Stops the Prometheus service.
    1. Find the process ID of the Prometheus service.
      ps -aux | grep prometheus
    2. Run the kill command to stop Prometheus.
      kill ID