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": "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"
    }
View Code

        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

          

        如果一切正常,將會受到 received 3 send 3

   4.c# 代碼進行json數據的發送 --post json 
       

 1 /// <summary>
 2         /// 插入數據,基於服務端已經有的一個表pageviews
 3         /// </summary>
 4         [TestMethod]
 5         public void InsertData()
 6         {
 7             string url = "http://*.*.*.*:8200/v1/post/pageviews"; //發送數據
 8             string data = PostHttp(url, GetData());
 9             DruiExecuteResult result = JsonConvert.DeserializeObject<DruiExecuteResult>(data);
10 
11             Assert.IsTrue(result.result.received == "100");
12             Assert.IsTrue(result.result.received == "100");
13         }
14          public string GetData()
15         {
16             StringBuilder sb = new StringBuilder();
17             string temp = string.Empty;
18             string ISO8601time = string.Empty;
19             for (int i = 0; i < 100; i++)
20             {
21                 ISO8601time = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:sszzzz", DateTimeFormatInfo.InvariantInfo);
22                 temp = "{\"time\":\"" + ISO8601time + "\",\"url\":\"test" + i.ToString() + "\",\"user\":\"hello" + i.ToString() + "\",\"latencyMs\":" + i.ToString() + "}";
23                 sb.AppendLine(temp);
24             }
25 
26             string result = sb.ToString();
27 
28             return result;
29         }
30           private static string PostHttp(string url, string body)
31         {
32             HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
33             httpWebRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
34             httpWebRequest.ContentType = "application/json";
35             //httpWebRequest.ContentType = "text/plain";
36 
37             httpWebRequest.Method = "POST";
38             httpWebRequest.Timeout = 30000;
39             httpWebRequest.KeepAlive = false;
40             byte[] btBodys = Encoding.UTF8.GetBytes(body);
41             httpWebRequest.ContentLength = btBodys.Length;
42             string responseContent = string.Empty;
43             HttpWebResponse httpWebResponse = null;
44             StreamReader streamReader = null;
45             try
46             {
47                 httpWebRequest.GetRequestStream().Write(btBodys, 0, btBodys.Length);
48                 httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
49                 streamReader = new StreamReader(httpWebResponse.GetResponseStream());
50                 responseContent = streamReader.ReadToEnd();
51             }
52             catch (Exception er)
53             {
54                 throw new Exception("執行出現異常:" + "數據:" + body, er);
55             }
56             finally
57             {
58                 if (httpWebResponse != null)
59                 {
60                     httpWebResponse.Close();
61                 }
62                 if (streamReader != null)
63                 {
64                     streamReader.Close();
65                 }
66                 httpWebRequest.Abort();
67             }
68 
69             return responseContent;
70         }
View Code

 

  
 

   

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM