集成 prometheus


参考:https://github.com/apache/apisix/blob/master/doc/zh-cn/plugins/prometheus.md

我们使用apisix自带的接口启用插件

curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "uri": "/hello",
    "plugins": {
        "prometheus":{}
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "127.0.0.1:80": 1
        }
    }
}'

测试:输入下面的命令

curl -i http://127.0.0.1:9080/apisix/prometheus/metrics
````

![](http://img.xiaoyou66.com/images/2020/12/03/V8sYW.png)

下面安装prometheus,这里我直接用docker来安装了,官方的github:https://github.com/prometheus/prometheus

参考:http://qinghua.github.io/prometheus/

我们先新建一个配置文件:`prometheus.yml`,我们只需要修改scrape_config这里的内容

```ini
# 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:
  - job_name: 'apisix'
    metrics_path: '/apisix/prometheus/metrics'
    static_configs:
    - targets: ['192.168.123.131:9080']

然后我们启动容器并映射配置文件(-v 是文件映射,前面那个是本机的配置文件所在地)

docker run -d \
    --publish=9090:9090 \
    -v /root/app/conf-prome/prometheus.yml:/etc/prometheus/prometheus.yml \
    prom/prometheus

启动容器后,我们查看Prometheus=》status=>config,可以看到我们的配置文件生效了

我们打开主页启动一个监控

然后点击execute来显示当前的数据


文章作者: 小游
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 小游 !
  目录