linux搭建prometheus对外部接口进行监控

Scroll Down

官网:https://prometheus.io/

wget下载

wget https://github.com/prometheus/prometheus/releases/download/v2.18.1/prometheus-2.18.1.linux-amd64.tar.gz

安装部署

解压

tar -xvf prometheus-2.18.1.linux-amd64.tar.gz

修改prometheus.yml配置文件

注意:yml文件严格按照空格来区分层级,不能多或少空格。

# my global config
global:
  scrape_interval:     60s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  scrape_timeout:      10s # scrape_timeout is set to the global default (10s).
  evaluation_interval: 60s # Evaluate rules every 15 seconds. The default is every 1 minute.

# 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: 'myJob'

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    #static_configs:
    #- targets: ['localhost:9090']

    metrics_path: /xxxAPIPath
    scheme: https
    tls_config:
      key_file: key_file.pem
      cert_file: crt_file.pem
      insecure_skip_verify: true
    static_configs:
    - targets:
      - '192.168.xxx.xxx:xxxx'
    metric_relabel_configs:
    - regex: xxxreg
      target_label: targetLabelName

启动

后台启动

nohup ./prometheus &

web访问:192.168.xxx.xxx:9090
status-Targets中可以看到接口的联通状态