Druid Tranquility使用(上篇)

1、Tranquility 是单独的http server服务,需要另行下载,下载地址

http://druid.io/downloads.html 

2、启动tranquilty

  nohup  bin/tranquility server -configFile ./conf/pageviews.json >start.log &

 json 文件如下:

{
  "dataSources" : {
    "pageviews" : {
      "spec" : {
        "dataSchema" : {
         
          "dataSource" : "pageviews",
          "parser" : {
            "type" : "string",
            "parseSpec" : {
             
              "timestampSpec" : {
                "column" : "time",
                "format" : "auto"
              },
              "dimensionsSpec" : {
          
                "dimensions" : ["url", "user"],
                "dimensionExclusions" : [
                  "timestamp",
                  "value"
                ]
              },
              "format" : "json"
            }
          },
          "granularitySpec" : {
            "type" : "uniform",
            "segmentGranularity" : "hour",
            "queryGranularity" : "none"
          },
        
          "metricsSpec" : [
            {
              "name": "views",
              "type": "count"
            },
            {
              "name": "latencyMs", 
              "type": "doubleSum", 
              "fieldName": "latencyMs"
            }
          ]
        },
        "ioConfig" : {
          "type" : "realtime"
        },
        "tuningConfig" : {
          "type" : "realtime",
          "maxRowsInMemory" : "100000",
          "intermediatePersistPeriod" : "PT10M",
          "windowPeriod" : "PT10M"
        }
      },
      "properties" : {
        "task.partitions" : "1",
        "task.replicants" : "1"
      }
    }
  },
  "properties" : {
    "zookeeper.connect" : "localhost",
    "druid.discovery.curator.path" : "/druid/discovery",
    "druid.selectors.indexing.serviceName" : "druid/overlord",
    "http.port" : "8200",
    "http.threads" : "8"
  }
}

3、通过http 直接发送数据 http://192.168.2.41:8200/v1/post/pageviews

{"time": 1501650962363, "url": "/foo/bar", "user": "alice", "latencyMs": 32}

163435_2XpD_3247419.png

pageviews :datasource

发送成功后 {
    "result": {
        "received": 5,
        "sent": 5
    }
}

如果 sent :0 则,数据未正常发送到druid ,未正常发送原因

1、druid 问题 检查middleManger overlord 节点配置内存

2、发送的时间戳,需要在10分钟内

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果要使用 Drui 数据源连接池,可以通过以下步骤进行整合: 1. 需要在 pom.xml 文件中添加 druid-spring-boot-starter 依赖,可以使用以下代码: ```xml <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.2.6</version> </dependency> ``` 2. 在 application.properties 文件中配置 Druid 数据库连接信息,可以使用以下代码: ```properties spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8 spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.druid.initial-size=5 spring.datasource.druid.max-active=20 spring.datasource.druid.min-idle=5 spring.datasource.druid.max-wait=60000 spring.datasource.druid.filters=stat,wall,log4j spring.datasource.druid.connection-properties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 ``` 3. 在 Spring Boot 应用程序中使用 JdbcTemplate 或者 Mybatis 等 ORM 框架进行数据库操作。 如果使用 JdbcTemplate 进行数据库操作,可以通过以下代码示例进行操作: ```java @Autowired private JdbcTemplate jdbcTemplate; public void insert(String name, Integer age) { jdbcTemplate.update("INSERT INTO user(name, age) VALUES (?, ?)", name, age); } public List<User> findAll() { return jdbcTemplate.query("SELECT * FROM user", new BeanPropertyRowMapper<>(User.class)); } ``` 如果使用 Mybatis 进行数据库操作,可以通过以下代码示例进行操作: ```java @Mapper public interface UserMapper { @Select("SELECT * FROM user WHERE id = #{id}") User findById(@Param("id") Long id); @Insert("INSERT INTO user(name, age) VALUES (#{name}, #{age})") int insert(User user); @Update("UPDATE user SET name = #{name}, age = #{age} WHERE id = #{id}") int update(User user); @Delete("DELETE FROM user WHERE id = #{id}") int deleteById(@Param("id") Long id); } ``` 需要注意的是,在 Mybatis 中,除了配置 Druid 数据库连接池信息之外,还需要在 application.properties 文件中配置 Mybatis 相关的信息,例如: ```properties mybatis.mapper-locations=classpath:mapper/*.xml mybatis.type-aliases-package=com.example.demo.model ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值