GithubHelp home page GithubHelp logo

metrics-monitor's Introduction

Metrics-monitor是将埋点信息推送至prometheus的pushGateway组件的插件

prometheus会定时从pushGateway组件中拉取信息,所以此处将埋点信息推送至PushGateway看起来类似于将埋点信息推送至prometheus

如何使用?

  1. 引入插件
<dependency>
	<groupId>pers.hyx</groupId>
	<artifactId>metrics-monitor</artifactId>
	<version>0.0.1-beta</version>
</dependency>
  1. 配置metrics-monitor 在application.properties中配置metrics-monitor相关配置
// pushGateway地址
metrics.config.push-gateway=xxx:xxx:xxx:9091
// server名称,标识具体服务,建议为服务名(或其他辨识度高的标识)
metrics.config.server=test
// 推送间隔,即产生埋点后多久进行推送,若不配置默认为1分钟
metrics.config.push-rate=5000
  1. 启用metrics-monitor 在启动类或者配置类中加载注解 @EnableMetricsMonitor
@SpringBootApplication
@EnableMetricsMonitor
public class DemoApplication {
		public static void main(String[] args) {
			SpringApplication.run(DemoApplication.class, args);
		}
}
  1. 注解使用metrics-monitor 可在相关方法中加载注解**@MetricsMonitor**
@Service
public class DemoService {

		@MetricsMonitor(type = MonitorType.OTHER, 
				remark = "test remark", 
				 monitorFor = {NullPointerException.class, ServerErrorException.class},
				 noMonitorFor = {IllegalArgumentException.class, NumberFormatException.class})
		public void demo() throws Exception {
			//do something
		}
}

注解参数说明 - type : metrics类型,可选RPCSERVERCUSTOMOTHER - remark : 备注标识(可选) - monitorFor : 需埋点异常类型(可选,可多选) - noMonitorFor : 不需要埋点异常类型(可选,可多选)

  1. 代码块使用metrics-monitor 使用MonitorBlock类进行生成局部代码块的方式进行埋点
    public void block() {
        new MonitorBlock().block(new MonitorBlock.Runnable() {
            @Override
            public void run() {
                //do something
            }
        }, MonitorType.RPC, "method or identification", "params like json", "remark");
    }

!! 此处代码块中抛出任意异常,均会被捕获并进行埋点

  1. 手动添加metrics-monitor Monitor中metrics类型默认为SERVER
    public void monitor() throws IOException {
        //method 1
        Monitor.build("method or identification", "params like json", "remark").push();

        //method 2
        TagProduction production = SpringUtil.getBean(TagProduction.class);
        Monitor.build().setTag(production.structureTag("method or identification", "params like json", "remark")).setGraph(MonitorType.RPC).push();

        //method 3
        MonitorTag monitorTag = new MonitorTag();
        monitorTag.setIp("host address");
        monitorTag.setServer("server information");
        monitorTag.setMethod("method or identification");
        monitorTag.setData("params like json");
        monitorTag.setRemark("remark");
        Monitor.build().setTag(monitorTag).setGraph(MonitorType.RPC).push();
    }

###如何查看?

  • 埋点成功后可打开配置的pushGateway地址,找到job-name = exception_alert相关数据,打开即可看到埋点信息

metrics-monitor's People

Contributors

loveowie avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

chinaboy007

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.