项目作者: afghanistanyn

项目描述 :
prometheus nacos discovery
高级语言: Go
项目地址: git://github.com/afghanistanyn/prometheus-nacos-sd.git
创建时间: 2020-08-21T09:09:41Z
项目社区:https://github.com/afghanistanyn/prometheus-nacos-sd

开源协议:

下载


prometheus-nacos-sd

Prometheus service discovery using nacos and file_sd_config.


Install

Precompiled binaries

Download from https://github.com/afghanistanyn/prometheus-nacos-sd/releases

manual build

  1. git clone https://github.com/afghanistanyn/prometheus-nacos-sd
  2. cd prometheus-nacos-sd
  3. make buildx

Docker

  1. docker pull afghanistanyn/prometheus-nacos-sd:v1.0
  2. docker run -it -d -v /tmp:/tmp afghanistanyn/prometheus-nacos-sd --nacos.address=192.168.1.1:8848 --nacos.namespace=dev --output.file=/tmp/nacos_sd_dev.json
  3. ls /tmp/nacos_sd_dev.json

Usage

  • run

    1. ./prometheus-nacos-sd --nacos.address=192.168.1.1:8848 --nacos.namespace=dev nacos.group=DEFAULT_GROUP --output.file=nacos_sd_dev.json --refresh.interval=30
  • default parameters
    ```
    nasos.address=localhost:8848
    nacos.namespace=public
    nacos.group=DEFAULT_GROUP
    refresh.interval=60

  1. ----
  2. ## Generated json format
  3. generated json should be follow prometheus `file_sd_config` format like below:
  4. ```json
  5. [
  6. {
  7. "targets": [
  8. "192.168.1.1:5066"
  9. ],
  10. "labels": {
  11. "__meta_context_path": "/miniapp-gateway",
  12. "__meta_nacos_group": "DEFAULT_GROUP",
  13. "__meta_nacos_namespace": "dev",
  14. "__meta_preserved_register_source": "SPRING_CLOUD",
  15. "__metrics_path__": "/miniapp-gateway/actuator/prometheus",
  16. "job": "miniapp-gateway"
  17. }
  18. },
  19. {
  20. "targets": [
  21. "192.168.1.1:5064"
  22. ],
  23. "labels": {
  24. "__meta_context_path": "/",
  25. "__meta_nacos_group": "DEFAULT_GROUP",
  26. "__meta_nacos_namespace": "dev",
  27. "__meta_preserved_register_source": "SPRING_CLOUD",
  28. "__metrics_path__": "/actuator/prometheus",
  29. "job": "web-gateway"
  30. }
  31. }
  32. ]

about prometheus metric path

  1. we set __metrics_path__ to "/actuator/prometheus" by default.
  2. but if you set metadata with key 'context_path' in your application metadata like below , we will rewrite it to "content_path/actuator/prometheus"
  1. spring:
  2. cloud:
  3. nacos:
  4. discovery:
  5. server-addr: 192.168.1.1:8848
  6. namespace: dev
  7. metadata:
  8. context_path: ${server.servlet.context-path:/}

Example prometheus settings

The part of your prometheus.yml is probably as follows.

  1. scrape_configs:
  2. - job_name: 'nacos-discorvery'
  3. file_sd_configs:
  4. - files:
  5. - /apps/prometheus/conf/nacos_sd_dev.json
  6. - /apps/prometheus/conf/nacos_sd_test.json
  7. refresh_interval: 1m
  8. relabel_configs:
  9. - regex: 'preserved_register_source'
  10. action: labeldrop