IoTDB + Grafana 实现数据可视化(2)

IoTDB + Grafana 实现数据可视化(2)



前言

在实现历史数据可视化之后,见[IoTDB + Grafana 实现数据可视化(1)],自动生成数据,达到实时监控的目的

提示:以下是本篇文章正文内容,下面案例可供参考

一、自动生成数据

使用Random 方法,以之前实际数据的平均值为基础,自动生成数据

在这里插入代码片
private static DataEntity AutoGetDAta(){
        DataEntity dataEntity = new DataEntity();
        Random random = new Random();

        dataEntity.setId(random.nextInt(1024));
        //dataEntity.setDatetime(datetime);
        dataEntity.setInitialSulfurContent(random.nextDouble()+120);
        dataEntity.setInitialOctaneNumber(random.nextDouble()+88);
        dataEntity.setSulfurContentOfTheProduct(random.nextDouble()+88);
        dataEntity.setProductOctaneNumber(random.nextDouble()+3);
        dataEntity.setLossOfOctaneNumber(random.nextDouble()+1);
        dataEntity.setV1(random.nextDouble()+160);
        dataEntity.setV2(random.nextDouble());
        dataEntity.setV3(random.nextDouble()+2);
        dataEntity.setV4(random.nextDouble());
        dataEntity.setV5(random.nextDouble()+60);
        dataEntity.setV6(random.nextDouble()+410);
        dataEntity.setV7(random.nextDouble()+70);
        dataEntity.setV8(random.nextDouble());
        dataEntity.setV9(random.nextDouble()+28);
        dataEntity.setV10(random.nextDouble()+83);
        dataEntity.setV11(random.nextDouble()+ random.nextInt(300)+600);
        dataEntity.setV12(random.nextDouble()+230);
        dataEntity.setV13(random.nextDouble()+200);
        dataEntity.setV14(random.nextInt()+520222);
        dataEntity.setV16(random.nextDouble()+50);

        return dataEntity;
    }

二、设置间隔时间,并上传数据

int count = 0;
        while(count<1000) {
            try {
                Thread.sleep(5 * 1000); //设置暂停的时间 5 秒
                count ++ ;

                Date date = new Date();

                Timestamp nowdate = new Timestamp(date.getTime());
                //   String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(timestamp);
                String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(nowdate);
                DataEntity dataEntity1 = AutomaticallyGenerateData.AutoGetDAta();

                /*
                            假设只有一个存储组 1 Storage Group
            有三台设备       Device1 Device2 Device3
            Device1 包含了 initialSulfurContent,InitialOctaneNumber 初始值
            Device2 SulfurContentOfTheProduct,ProductOctaneNumber,LossOfOctaneNumber 结果值
            Device3 v1,v2,v3,v4,v5,v6,v7,v8,v9,v10,v11,v12,v13,v14,v15,v16 几个设备的值
                 */
//d1
                //Drvice1.initialSulfurContent
                statement.addBatch("insert into root.Drvice1(timestamp,initialSulfurContent) values("+time+","+dataEntity1.getInitialSulfurContent()+");");
//                Drvice1.InitialOctaneNumber
                statement.addBatch("insert into root.Drvice1(timestamp,InitialOctaneNumber) values("+time+","+dataEntity1.getInitialOctaneNumber()+");");

                //d2
                //                LossOfOctaneNumber
                statement.addBatch("insert into root.Drvice2(timestamp,LossOfOctaneNumber) values("+time+","+dataEntity1.getLossOfOctaneNumber()+");");
//                ProductOctaneNumber
                statement.addBatch("insert into root.Drvice2(timestamp,ProductOctaneNumber) values("+time+","+dataEntity1.getProductOctaneNumber()+");");
//                SulfurContentOfTheProduct
                statement.addBatch("insert into root.Drvice2(timestamp,SulfurContentOfTheProduct) values("+time+","+dataEntity1.getSulfurContentOfTheProduct()+");");
                //d3
                statement.addBatch("insert into root.Drvice3(timestamp,V1) values("+time+","+dataEntity1.getV1()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V2) values("+time+","+dataEntity1.getV2()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V3) values("+time+","+dataEntity1.getV3()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V4) values("+time+","+dataEntity1.getV4()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V5) values("+time+","+dataEntity1.getV5()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V6) values("+time+","+dataEntity1.getV6()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V7) values("+time+","+dataEntity1.getV7()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V8) values("+time+","+dataEntity1.getV8()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V9) values("+time+","+dataEntity1.getV9()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V10) values("+time+","+dataEntity1.getV10()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V11) values("+time+","+dataEntity1.getV11()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V12) values("+time+","+dataEntity1.getV12()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V13) values("+time+","+dataEntity1.getV13()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V14) values("+time+","+dataEntity1.getV14()+");");
                statement.addBatch("insert into root.Drvice3(timestamp,V16) values("+time+","+dataEntity1.getV16()+");");

                statement.executeBatch();
//                statement.executeQuery("select * from root.Drvice3");
                outputResult(statement.getResultSet());
                statement.clearBatch();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

三、在Grafana设置刷新时间

在这里插入图片描述启动自动刷新
在这里插入图片描述

四、最后的效果

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jupyter Aaron

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值