首页 > 其他分享 >influxdb

influxdb

时间:2024-05-28 16:34:10浏览次数:21  
标签:String private static influxdb valueList InfluxDBInfoStatic public

InfluxDB

  1. influxdb 时序性数据库
    时序数据是描述一个实体在不同时间所处的不同状态。一般用于指标监控场景。

  2. influxdb连接

    @Component
    @ConfigurationProperties(prefix = "influxdb")
    public class InfluxDBInfoStatic {
    	private static String url;
    	private static String port;
    	private static String database;
    	private static String measurement;
    	private static String user;
    	private static String password;
    	private static String retentionPolicy="hour";
    	//okhttpclient连接池最大空闲数量
    	private static Integer idleConnectionCount=100;
    	//okhttpclient连接池最大空闲保持时间
    	private static Integer keepAliveDuration=10;
    }
    @Slf4j
    public class InfluxDBConnectionUtil {
    	private static final InfluxDB INFLUXDB;
    	private final static ConnectionPool connectionPool=new ConnectionPool(InfluxDBInfoStatic.getIdleConnectionCount(),InfluxDBInfoStatic.getKeepAliveDuration(), TimeUnit.SECONDS);
    	static{
    		OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient().newBuilder()
    				.connectTimeout(30, TimeUnit.SECONDS)
    				.writeTimeout(30, TimeUnit.SECONDS)
    				.retryOnConnectionFailure(true)
    				.readTimeout(30, TimeUnit.SECONDS);
    		okHttpClientBuilder.connectionPool(connectionPool);
    		INFLUXDB = InfluxDBFactory.connect(
    				"http://" + InfluxDBInfoStatic.getUrl() + ":" + InfluxDBInfoStatic.getPort()
    				, InfluxDBInfoStatic.getUser(), InfluxDBInfoStatic.getPassword(),okHttpClientBuilder);
    	} 
        /**
         * 获取对象句柄
         */
        public static InfluxDBConnectionUtil getInstance() {
            return SingletonInstance.INSTANCE;
        }
      
    	/**
    	 * 创建自定义保留策略 policyName-策略名;days-保存天数;replication-保存副本数量;isDefault-是否设为默认保留策略          
    	 */
    	public void createRetentionPolicy(String dataBaseName, String policyName, int days, int replication, Boolean isDefault) {
    		String sql = String.format("CREATE RETENTION POLICY \"%s\" ON \"%s\" DURATION %sd REPLICATION %s ", policyName, dataBaseName, days, replication);
    		if (isDefault) {
    			sql = sql + " DEFAULT";
    		}
    		query(sql);
    	}
    
    	/**
    	 * 创建默认的保留策略 策略名:hour,保存天数:30天,保存副本数量:1,设为默认保留策略
    	 * 
    	 */
    	public void createDefaultRetentionPolicy() {
    		String command = String.format("CREATE RETENTION POLICY \"%s\" ON \"%s\" DURATION %s REPLICATION %s DEFAULT", "hour", InfluxDBInfoStatic.getDatabase(), "30d", 1);
    		this.query(command);
    	}
    
    	/**
    	 * 查询 
    	 */
    	public QueryResult query(String command) {
    		return INFLUXDB.query(new Query(command, InfluxDBInfoStatic.getDatabase()));
    	}
    
    	/**
    	 * 插入 measurement-表;tags-标签;fields-字段
    	 */
    	public void insert(String measurement, Map<String, String> tags, Map<String, Object> fields, long time, TimeUnit timeUnit) {
    		Builder builder = Point.measurement(measurement);
    		builder.tag(tags);
    		builder.fields(fields);
    		if (0 != time) {
    			builder.time(time, timeUnit);
    		}
    		INFLUXDB.write(InfluxDBInfoStatic.getDatabase(), InfluxDBInfoStatic.getRetentionPolicy() == null || InfluxDBInfoStatic.getRetentionPolicy().equals("") ? "autogen" : InfluxDBInfoStatic.getRetentionPolicy(), builder.build());
    	} 
    	public static void main(String[] args) {
    		QueryResult results = InfluxDBConnectionUtil.getInstance()
    				.query("select time, application, avg, count, countError, max, min, \"pct90.0\", \"pct95.0\", \"pct99.0\", rb, sb, transaction from jmeter where application = '16'");
    		QueryResult.Result oneResult = results.getResults().get(0);
    		if (oneResult.getSeries() != null) {
    			List<List<Object>> valueList = oneResult.getSeries().stream().map(QueryResult.Series::getValues).collect(Collectors.toList()).get(0);
    			if (valueList != null && valueList.size() > 0) {
    				System.out.println("valueList ===> " + JSONUtil.toJsonStr(valueList));
    				for (List<Object> value : valueList) {
    					System.out.println("value ===> " + JSONUtil.toJsonStr(value)); 
    				}
    			}
    		}
    	}
    }
    

标签:String,private,static,influxdb,valueList,InfluxDBInfoStatic,public
From: https://www.cnblogs.com/zrx1/p/18218335

相关文章

  • JMeter+InfluxDB+Grafana性能监控最快搭建方法
    一、部署influxdb服务参考官网:https://www.influxdata.com/downloads/安装命令(centos系统)wgethttps://dl.influxdata.com/influxdb/releases/influxdb-1.8.10.x86_64.rpmsudoyumlocalinstallinfluxdb-1.8.10.x86_64.rpm进入配置文件修改配置vim/etc/influxdb/influ......
  • docker快速部署 influxdb+telegraf+grafana 推送主机及docker容器监控数据 并展示图
    简述1、InfluxDBInfluxDB是用Go语言编写的一个开源分布式时序、事件和指标数据库,无需外部依赖。 2、TelegrafTelegraf是一个插件驱动的服务器代理,用于收集和报告指标,并且是TICKStack的第一部分。Telegraf插件可以直接从它运行的系统中获取各种指标,从第三方API中提取指标,甚......
  • windows中启动多个influxdb操作指南
    一:下载和安装:从InfluxData的官方网站 https://repos.influxdata.com/rhel/7/x86_64/stable/下载需要的版本,我是用的1.7.7-1解压安装包到您选择的目录,我这边是E:\influxdb\influxdb-1.7.7_windows_amd64\influxdb-1.7.7-1\。二:配置多个实例:增加实例,复制解压后的文件夹到一......
  • InfluxDB 客户端基础操作2
    InfluxDB提供了客户端influx用于管理数据库。自2.1版本,客户端influx就和服务端influxd分离开了,需要单独安装。安装方法非常检查,解压缩复制到到/user/bin下面即可。在1.x版本中客户端支持SQL语句,但在2.x版本中,已经不支持SQL语法了。这对熟悉关系型数据库的人来说不太友好。官......
  • influxdb 使用Influx CLI 命令操作数据
    一、安装并使用influxCLI客户端下载地址:https://docs.influxdata.com/influxdb/v2/tools/influx-cli/二、需要下载influx服务器端和CLI工具influxd:influx数据库的服务端。下载地址:https://dl.influxdata.com/influxdb/releases/influxdb2-2.7.5-windows.zipinflux:连接influ......
  • telegraph + influxdb + grafana 实现交换机流量展示
    实验环境influxdb2:2.7.5telegraf:1.30.1grafana:10.4.2influxdb官方文档见https://docs.influxdata.com/influxdb/v2/,网络上很多文档比较老,可能是v1版本的influxdb。部署方法1:二进制从https://www.influxdata.com/downloads/可以查看不同版本的下载地址下载压缩包并解压、复......
  • influxdb内存占用剖析
    目标本文将讲述influxdb内存中都存了哪些数据?什么情况下会导致内存占用暴增?以及内存相关的配置。我的influxdb配置我的influxdb配置如下:/etc/influxdb/config.tomlbolt-path="/var/lib/influxdb/influxd.bolt"engine-path="/var/lib/influxdb/engine"storage-cache-m......
  • influxdb field type冲突问题
    问题描述2024-04-14T14:59:51ZE![outputs.influxdb_v2]Failedtowritemetrictoiot(willbedropped:422UnprocessableEntity):unprocessableentity:failurewritingpointstodatabase:partialwrite:fieldtypeconflict:inputfield"longitude"......
  • InfluxDB时序数据库图形用户界面可视化工具(influxdb-gui)
    说明之前开发了一款TDengine的GUI程序,出于兴趣,简单搞个InfluxDB的复制版,类似Navicat,目前基础操作功能已满足,后续看情况,可以继续扩展功能。介绍InfluxDB-GUI是一款功能全面、操作简便的influxdb时序数据库图形界面工具,V1.0.0目前支持influxdb版本列表如下:influxdb1.8.10版本......
  • CIG容器重量级 监控系统介绍: CAdvisor+InfluxDB+Granfana
       Docker重量级容器监控:CAdvisor+InfluxDB+Granfana查看docker宿主机的所有容器的cpu内存以及网络等数据:dockerstatus CAdivisor介绍-收集数据: InfluxDB--存储数据: Granfana可视化平台展示:  ......