$ docker run -d --name prometheus -p 9090:9090 prom/prometheus:v2.48.0 $ docker exec -it prometheus sh /prometheus $ ps aux PID USER TIME COMMAND 1 nobody 0:00 /bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/prometheus --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheu 26 nobody 0:00 sh 32 nobody 0:00 ps aux
#/ cat /etc/prometheus/prometheus.yml # 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).
# 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'.
# 配置文件,使用configmap的形式保存,覆盖默认的配置文件 $ cat prometheus-cm.yml # my global config global: scrape_interval: 30s evaluation_interval: 30s # scrape_timeout is set to the global default (10s).
# 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: - job_name: 'prometheus' static_configs: - targets: ['localhost:9090']
$ curl http://prometheus.test.com/metrics ...... # HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code. # TYPE promhttp_metric_handler_requests_total counter promhttp_metric_handler_requests_total{code="200"} 152 promhttp_metric_handler_requests_total{code="500"} 0 promhttp_metric_handler_requests_total{code="503"} 0 ......
# http://prometheus.test.com/metrics 是通过ingress访问,接下来我们直接使用pod的ip访问9090端口获取信息 $ kubectl -n monitor get po -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES prometheus-5bc5966ff8-f84vx 1/1 Running 0 129m 10.244.0.26 k8s-master <none> <none>
$ $ curl http://10.244.0.26:9090/metrics ...... # HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code. # TYPE promhttp_metric_handler_requests_total counter promhttp_metric_handler_requests_total{code="200"} 258 promhttp_metric_handler_requests_total{code="500"} 0 promhttp_metric_handler_requests_total{code="503"} 0 ......