开始

https://p8s.io/docs/basic/install/

服务器安装:

https://prometheus.io/download/#prometheus

1
2
3
4
5
mkdir pprometheus
cd pprometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.47.1/prometheus-2.47.1.linux-amd64.tar.gz

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

.zshrc 中添加:

1
export PATH=$PATH:/home/ubuntu/pprometheus/prometheus-2.47.1.linux-amd64
1
2
3
4
5
6
7
8
source .zshrc
(base) ➜  ~ prometheus --version
prometheus, version 2.47.1 (branch: HEAD, revision: c4d1a8beff37cc004f1dc4ab9d2e73193f51aaeb)
  build user:       root@4829330363be
  build date:       20231004-10:31:16
  go version:       go1.21.1
  platform:         linux/amd64
  tags:             netgo,builtinassets,stringlabels

默认的 prometheus.yaml:

 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
# 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:9090"]

修改端口为应用程序的端口,例如 5000

配置文件路径: /home/ubuntu/pprometheus/prometheus-2.47.1.linux-amd64/prometheus.yml

1
2
tmux new -s prometheus
prometheus --config.file=/home/ubuntu/pprometheus/prometheus-2.47.1.linux-amd64/prometheus.yml