OpenTSDB millisecond query and write data

Since OpenTSDB not support Java SDK call, so the call based on Java development OpenTSDB will have to rely on HTTP requests were.

1. millisecond data write

/ Api / put: inserting a POST JSON format data, the time stamp assigned to a millisecond timestamp parameter can, JSON format:

{
    "metric":"self.test", 
    "timestamp":1567675709879, 
    "value":20, 
    "tags":{
        "host":"web1"
    }
}

In Java millisecond timestamp Access:

// get the current time stamp Unix 
Long millisecond = System.currentTimeMillis ();
 Long millisecond2 = DateTimeUtil.stringLongToMillisecond ( "2019/09/05. 17: 28: 29: 879" ); 

// date time format string into a (Unix timestamp) long integer type 
public  static  long stringLongToMillisecond (string string) throws Exception {
     return stringLongToDate (string) .getTime (); 
} 

// convert date format string type date time 
public  static date stringLongToDate (string string) throws Exception {
     return sdfLong.parse (String); 
} 

Private  static SimpleDateFormat sdfLong = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss:SSS");

2. millisecond data query

MsResolution mainly set this parameter, if the field is false, then the same point in the second polymerization aggregator according to the second specified manner to give the final value of

( When the query returns the default second data level (in a manner specified in the query polymerization time series data sampled in 1 second polymerized to form the final result) )

/ Api / query: Get, or may be selected in two ways Post, Post recommended embodiment, the request JSON format:

{
     "Start": 1456123705,         // start time for the query 
    "End": 1,456,124,985,           // end time for the query 
    "globalAnnotation": false ,   // query results Annotation whether to return, Ltd. Free Join 
    "noAnnotations": false ,      / / query results whether to return Annotation 
    " msResolution ": to true ,        // precision whether the return point millisecond, if the field is to false,
                                 // polymerization aggregator according to the specified points within the same manner to obtain the second seconds the final value 
    "showTSUIDs": to true ,          // query results whether it carries tsuid 
    "showQuery":true,           // query results whether to return the corresponding sub-query 
    "showSummary": false ,        // query of some summary information about the results of the query whether it carries the time 
    "showStats": false ,          // query whether it carries the results of the query time some details 
    "the delete": false ,             // Note: If the value is set to true, all in line with the query criteria point will be deleted 
    "queries" : [
        // sub-queries, as an array, you can specify more than Article subquery independent 
    ] 
}

Subquery format:

{
     "Metric": "JVM_Heap_Memory_Usage_MB",     // query metric used 
    "Aggregator": "SUM",                      // polymerization function used 
    "Downsample": " 1ms ",                      // sampling interval and the sampling function 
    "tags": {                                 // tag combination, in OpenTSDB 2.0 have been marked as obsolete
                                              // recommended to use the following filters field 
        "Host": "Server01" 
    },
     "filters": [],                             // tagFilter, will be described below in detail Filter related content 
    " explicitTags ": false ,                    // query results contain only a tag filter appear in
    "rate": to false ,                             // whether to convert the query results to rate 
    "rateOption": {}                           // record rate parameters related to specific parameters are described later 
}

3. Test Results

1ms difference data to insert two time OpenTSDB

Respectively second and millisecond level query, the results for the period:

秒级查询结果:[{"metric":"metric1","tags":{"tag1":"test","tag2":"mort"},"aggregateTags":[],"dps":{"1567675709":43.0}}]
毫秒级查询结果:[{"metric":"metric1","tags":{"tag1":"test","tag2":"mort"},"aggregateTags":[],"dps":{"1567675709879":21.0,"1567675709880":22.0}}]

The query returns a second data level (the two polymerizing code zimsum, the return 21 + 22)

Milliseconds query returns all data, no polymerization, taken down

Renderings:

 

reference:

https://blog.csdn.net/zx711166/article/details/80913861

https://github.com/shifeng258/opentsdb-client

Guess you like

Origin www.cnblogs.com/MWCloud/p/11468826.html