Skip to content
LUYONGQIANG edited this page Dec 3, 2019 · 3 revisions

/api/query
Probably the most useful endpoint in the API, /api/query enables extracting data from the storage system in various formats determined by the serializer selected. Queries can be submitted via the 1.0 query string format or body content.

C# Code

 OpenTsdbClient apiClient = new OpenTsdbClient();
 
            QueryRequest quest = new QueryRequest();
            quest.Start = ConvertDateTimeInt(DateTime.Now.AddDays(-30)).ToString();
            quest.End = ConvertDateTimeInt(DateTime.Now).ToString();
            var search = new Dictionary<string, string>()
            {
                { "host","YL-01-01"},
                {"dc","lga" }
            };
            quest.Queries = new SubQueryRequest[] {
              new SubQueryRequest()
              {
                    Metric = "bridge",
                    Rate = true,
                    Aggregator = "sum",
                    Tags = search
             }
            };
            var result = await apiClient.PostAsync<dynamic>("/api/query", quest);

            Console.WriteLine(result);

Result

[
  {
    "metric": "bridge",
    "tags": {},
    "aggregateTags": [
      "host",
      "dc"
    ],
    "dps": {
      "1573796728": 3.11,
      "1573796729": 1.46,
      "1574325428": 0.1,
      "1574325645": -0.08,
      "1574325705": -0.01,
      "1574325765": 0.61,
      "1574325825": -0.52,
    }
  }
]
Clone this wiki locally