Druid 基础使用-操作篇(Imply )

一、Imply

Druid 原生的配置较麻烦,在上一篇单机版安装中有所涉及
   Imply 基于Druid 进行了一些组件的开发,提供开源社区版本和商业版,简化了部署,开发了一些应用.https://imply.io/product

二、

安装

  1. 下载nodejs 安装(http://jingyan.baidu.com/article/dca1fa6f48f478f1a5405272.html)
  2. .安装imply
    1. 下载最新版本 imply-1.3.1.tar  https://imply.io/download
    2. tar -xzf imply-1.3.1.tar
  3. 启动
     1[root@Druid imply-1.3.1]# bin/supervise -c conf/supervise/quickstart.conf  -可以nohup 后台执行

三、Imply 数据的发送
        1.修改 tranquility 组件下server.josn 中的数据相关信息 --表名称、维度列、指标列
         修改后的数据结构如下

{
"dataSources": {
"pageviews": {
"spec": {
"dataSchema": {
"dataSource": "pageviews",
"parser": {
"type": "string",
"parseSpec": {
"timestampSpec": {
"format": "auto",
"column": "time"
},
"dimensionsSpec": {
"dimensions": [
"url",
"user"
]
},
"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": "",
"intermediatePersistPeriod": "PT10M",
"windowPeriod": "PT10M"
}
},
"properties": {
"task.partitions": "",
"task.replicants": ""
}
}
},
"properties": {
"zookeeper.connect": "localhost",
"druid.discovery.curator.path": "/druid/discovery",
"druid.selectors.indexing.serviceName": "druid/overlord",
"http.port": "",
"http.threads": ""
}

2.重新启动Imply --这个地方有个疑问  如何动态的设置表的名称呢?tranquility 重启 原因在于重启的时候指定了server.json 这个配置文件?

3.在linnux系统中进行数据的发送
                curl -XPOST -H'Content-Type: application/json' --data-binary @../003.jsonhttp://*。*。*。*:8200/v1/post/pageviews  --pageviews 必须提前声明,否则回提示数据源未定义 ,如何动态增加呢

003.josn 数据源的数据,一定要注意time 数据,一是时间最好是当前时间,否则tranquility 仅能收到数据,不会想Druid进行数据的发送,比如  receive 3 send 0

Druid 基础使用-操作篇(Imply )

如果一切正常,将会受到 received 3 send 3

4.c# 代码进行json数据的发送 --post json

 /// <summary>
/// 插入数据,基于服务端已经有的一个表pageviews
/// </summary>
[TestMethod]
public void InsertData()
{
string url = "http://*.*.*.*:8200/v1/post/pageviews"; //发送数据
string data = PostHttp(url, GetData());
DruiExecuteResult result = JsonConvert.DeserializeObject<DruiExecuteResult>(data); Assert.IsTrue(result.result.received == "");
Assert.IsTrue(result.result.received == "");
}
public string GetData()
{
StringBuilder sb = new StringBuilder();
string temp = string.Empty;
string ISO8601time = string.Empty;
for (int i = ; i < ; i++)
{
ISO8601time = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz", DateTimeFormatInfo.InvariantInfo);
temp = "{\"time\":\"" + ISO8601time + "\",\"url\":\"test" + i.ToString() + "\",\"user\":\"hello" + i.ToString() + "\",\"latencyMs\":" + i.ToString() + "}";
sb.AppendLine(temp);
} string result = sb.ToString(); return result;
}
private static string PostHttp(string url, string body)
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
httpWebRequest.ContentType = "application/json";
//httpWebRequest.ContentType = "text/plain"; httpWebRequest.Method = "POST";
httpWebRequest.Timeout = ;
httpWebRequest.KeepAlive = false;
byte[] btBodys = Encoding.UTF8.GetBytes(body);
httpWebRequest.ContentLength = btBodys.Length;
string responseContent = string.Empty;
HttpWebResponse httpWebResponse = null;
StreamReader streamReader = null;
try
{
httpWebRequest.GetRequestStream().Write(btBodys, , btBodys.Length);
httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
streamReader = new StreamReader(httpWebResponse.GetResponseStream());
responseContent = streamReader.ReadToEnd();
}
catch (Exception er)
{
throw new Exception("执行出现异常:" + "数据:" + body, er);
}
finally
{
if (httpWebResponse != null)
{
httpWebResponse.Close();
}
if (streamReader != null)
{
streamReader.Close();
}
httpWebRequest.Abort();
} return responseContent;
}
上一篇:1-关于单片机通信数据传输(中断发送,大小端,IEEE754浮点型格式,共用体,空闲中断,环形队列)


下一篇:__c语言__结构体、共用体、枚举__笔记