概述
Exporter是Prometheus监控系统中一个重要组件,可以理解为收集监控对象各种数据的agent。Prometheus为我们提供了较多的官方及第三方export,如果想要实现用户自己应用的监控,则需自己开发exporter,常用的监控对象大致可分为数据库对象,中间件对象,主机及操作系统,以及用户应用等。其中本文主要介绍了国产数据库gbase-8a的通用模块
(1)添加依赖
首先在国产数据库项目(例如exporter-gbase-8a)下的pom.xml中添加exporter-select-sql的依赖,用于让国产数据库项目与exporter-select-sql的jar包相关联
<dependency>
<groupId>com.apusic.amp.exporter</groupId>
<artifactId>exporter-select-sql</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
(2)注册
在国产数据库项目(例如exporter-gbase-8a)下的application注册文件下(例如Gbase8aExporterApplication)注册selectSqlExporter和gbase8aExporter采集器,注册方式为
@SpringBootApplication
@EnablePrometheusEndpoint
@ComponentScan("com.apusic.amp.exporter")
public class Gbase8aExporterApplication extends WebMvcConfigurerAdapter implements CommandLineRunner {
@Autowired
private SelectSqlExporter selectSqlExporter;
@Autowired
private Gbase8aExporter gbase8aExporter;
public static void main(String[] args) {
SpringApplication.run(Gbase8aExporterApplication.class, args);
}
@Override
public void run(String... args) throws Exception {
DefaultExports.initialize();
selectSqlExporter.register();
gbase8aExporter.register();
}
}
(3)根据不同国产数据库的需求配置metrics.yml
找到国产数据库项目下的metrics.yml配置文件(例如exporter-gbase-8a项目下的metrics_select_sql.yml)
因为exporter后的metrics内容格式是由context+name+fieldForValue+help+type+fieldForLabels组成,所以通过metrics_select_sql.yml配置文件依次获取到各项指标的值,然后根据Prometheus所需的格式排列起来,例如
# HELP go_gc_duration_seconds A summary of the GC invoc