Giter Site home page Giter Site logo

spring-boot-metrics-collector's Introduction

spring-boot-metrics-collector

spring-boot-metrics-collector 是一个 Spring Boot 指标收集器,可以从 /metrics 端口收集数据,存储到 Elasticsearch,实现指标统计。收集目标:

  • Spring Boot 1.x 原生指标端口: /metrics ;
  • Spring Boot 2.x Prometheus 指标端口: /actuator/prometheus ;
  • 从 Eureka 发现端口,自动识别端口类型。

这里是一些资料,Spring Boot 指标端口和集成开发方式介绍:

spring-boot-metrics-collector 打包运行:

mvn package

创建配置文件 metrics-collector.yaml

############################# beat ######################################
beat:
  # Defines how often an event is sent to the output
  period: 10

  # Managment Adress
  hosts:
    - "http://localhost:8080/metrics
    - "http://localhost:28000/actuator/prometheus"
  
  # List of Metrics that shall be excluded from the collection
  excludes:
    - "system.load.average.1m"
    - "tomcat.global.error"

#================================ General ======================================

# Internal queue configuration for buffering events to be published.
queue:
# Queue type by name (default 'mem')
  # The memory queue will present all available events (up to the outputs
  # bulk_max_size) to the output, the moment the output is ready to server
  # another batch of events.
  mem:
    # Max number of events the queue can buffer.
    events: 4096

#-------------------------- Elasticsearch output -------------------------------
output.elasticsearch:

  # Boolean flag to enable or disable the output module.
  enabled: true
  
  # Array of hosts to connect to.
  # Scheme and port can be left out and will be set to the default (http and 9200)
  # In case you specify and additional path, the scheme is required: http://localhost:9200/path
  # IPv6 addresses should always be defined as: https://[2001:db8::1]:9200
  hosts: ["localhost:9200"]
  
  # Number of workers per Elasticsearch host.
  worker: 1
  
  # Optional index name. The default is "metrics-collector-" plus date
  # and generates [metrics-collector-]YYYY-MM-DD keys.
  # In case you modify this pattern you must update setup.template.name 
  # and setup.template.pattern accordingly.
  index: "'metrics-collector-'yyyy-MM-dd"
  
  # The number of times a particular Elasticsearch index operation is attempted. If
  # the indexing operation doesn't succeed after this many retries, the events are
  # dropped. The default is 3.
  max_retries: 3
  
  # The maximum number of events to bulk in a single Elasticsearch bulk API index request.
  # The default is 50.
  bulk_max_size: 50
  
  # Boolean flag to omit zero value.
  omit_zero: true

#-------------------------- File output -------------------------------
output.file:
  # Boolean flag to enable or disable the output module.
  enabled: true
  
  # Log file path & name
  name: metrics.log
  
  # Time pattern of rolling policy
  file_name_pattern: yyyy-MM-dd
  
  # max file count, 0 as default
  max_history: 30

启动:

java -jar spring-boot-metrics-collector-1.0.0-SNAPSHOT.jar

可以使用 Eureka 自动发现服务位置,在启动命令中设置 beat.eureka 参数:

java -jar spring-boot-metrics-collector-1.0.0-SNAPSHOT.jar \
  --beat.eureka=http://localhost:8761/eureka/apps \
  --output.elasticsearch.hosts[0]=localhost:9200

Elasticsearch 集群地址也可以用启动参数指定:output.elasticsearch.hosts.

spring-boot-metrics-collector's People

Contributors

rm-vrf avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.