本文整理汇总了Java中com.mysql.jdbc.JDBC4Connection类的典型用法代码示例。如果您正苦于以下问题:Java JDBC4Connection类的具体用法?Java JDBC4Connection怎么用?Java JDBC4Connection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDBC4Connection类属于com.mysql.jdbc包,在下文中一共展示了JDBC4Connection类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDBFilesSize
import com.mysql.jdbc.JDBC4Connection; //导入依赖的package包/类
/**
* 获取宿主机对应连接的数据库文件大小信息的采集
* @return
* @throws SQLException
* @throws SocketException
* @throws UnknownHostException
*/
private Collection<FalconReportObject> getDBFilesSize() throws Exception {
Set<FalconReportObject> reportObjectSet = new HashSet<>();
//jdbc:mysql://10.250.140.104:3306
String url = ((JDBC4Connection) connection).getURL();
List<String> ips = HostUtil.getHostIps();
ips.add("127.0.0.1");
ips.add("localhost");
ips.add("0.0.0.0");
for (String ip : ips) {
url = url.replace(String.format("jdbc:mysql://%s:",ip),"");
}
if (NumberUtils.isNumber(url)){ //若有得到该连接下本机有效的端口地址
String dataDir = getDataDirByPort(url);
if (dataDir != null){
List<String> filter = Arrays.asList("mysql","performance_schema","temp","information_schema");
File dataDirFile = new File(dataDir);
String[] dirList = dataDirFile.list();
if (dirList != null){
for (String dbName : dirList) {
if (!filter.contains(dbName)){
try {
Path path = Paths.get(dataDir + File.separator + dbName);
if (path.toFile().isDirectory()){
Files.walkFileTree(path,new SimpleFileVisitor<Path>(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String fileName = file.getFileName().toString();
String fileNameLower = fileName.toLowerCase();
if(fileNameLower.endsWith(".myi") || fileNameLower.endsWith(".ibd")){
FalconReportObject falconReportObject = new FalconReportObject();
MetricsCommon.setReportCommonValue(falconReportObject,plugin.step());
falconReportObject.setCounterType(CounterType.GAUGE);
//时间戳会统一上报
// falconReportObject.setTimestamp(System.currentTimeMillis() / 1000);
falconReportObject.setMetric("mysql-file-size");
falconReportObject.setValue(String.valueOf(file.toFile().length()));
falconReportObject.appendTags("database=" + dbName);
falconReportObject.appendTags("table=" + fileName.split("\\.")[0]);
falconReportObject.appendTags("type=" + fileName.split("\\.")[1].toUpperCase());
falconReportObject.appendTags(MetricsCommon.getTags(plugin.agentSignName(),plugin,plugin.serverName()));
reportObjectSet.add(falconReportObject);
}
return super.visitFile(file, attrs);
}
});
}
} catch (IOException e) {
log.error("遍历目录 {} 发生异常",dbName,e);
}
}
}
}
}
}
return reportObjectSet;
}