Chilkat Online Tools

DataFlex / Datadog API Collection / Tag Configuration Cardinality Estimator

Back to Collection Items

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoHttp
    Boolean iSuccess
    Variant vQueryParams
    Handle hoQueryParams
    Variant vResp
    Handle hoResp
    Variant vSbResponseBody
    Handle hoSbResponseBody
    Handle hoJResp
    Integer iRespStatusCode
    String sEstimate_type
    String sEstimated_at
    String sEstimated_output_series
    String sId
    String sV_Type
    String sTemp1
    Boolean bTemp1

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoQueryParams
    If (Not(IsComObjectCreated(hoQueryParams))) Begin
        Send CreateComObject of hoQueryParams
    End
    Get ComUpdateString Of hoQueryParams "filter[groups]" "<string>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[hours_ago]" "<integer>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[num_aggregations]" "<integer>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[pct]" "<boolean>" To iSuccess
    Get ComUpdateString Of hoQueryParams "filter[timespan_h]" "<integer>" To iSuccess

    Send ComSetRequestHeader To hoHttp "Accept" "application/json"

    Get pvComObject of hoQueryParams to vQueryParams
    Get ComQuickRequestParams Of hoHttp "GET" "https://api.app.ddog-gov.com/api/v2/metrics/:metric_name/estimate" vQueryParams To vResp
    If (IsComObject(vResp)) Begin
        Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
        Set pvComObject Of hoResp To vResp
    End
    Get ComLastMethodSuccess Of hoHttp To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoHttp To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
    If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
        Send CreateComObject of hoSbResponseBody
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess

    Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
    If (Not(IsComObjectCreated(hoJResp))) Begin
        Send CreateComObject of hoJResp
    End
    Get pvComObject of hoSbResponseBody to vSbResponseBody
    Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
    Set ComEmitCompact Of hoJResp To False

    Showln "Response Body:"
    Get ComEmit Of hoJResp To sTemp1
    Showln sTemp1

    Get ComStatusCode Of hoResp To iRespStatusCode
    Showln "Response Status Code = " iRespStatusCode
    If (iRespStatusCode >= 400) Begin
        Showln "Response Header:"
        Get ComHeader Of hoResp To sTemp1
        Showln sTemp1
        Showln "Failed."
        Send Destroy of hoResp
        Procedure_Return
    End

    Send Destroy of hoResp

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "data": {
    //     "attributes": {
    //       "estimate_type": "count_or_gauge",
    //       "estimated_at": "<dateTime>",
    //       "estimated_output_series": "<long>"
    //     },
    //     "id": "<string>",
    //     "type": "metric_cardinality_estimate"
    //   }
    // }

    // Sample code for parsing the JSON response...
    // Use this online tool to generate parsing code from sample JSON: Generate JSON Parsing Code

    Get ComStringOf Of hoJResp "data.attributes.estimate_type" To sEstimate_type
    Get ComStringOf Of hoJResp "data.attributes.estimated_at" To sEstimated_at
    Get ComStringOf Of hoJResp "data.attributes.estimated_output_series" To sEstimated_output_series
    Get ComStringOf Of hoJResp "data.id" To sId
    Get ComStringOf Of hoJResp "data.type" To sV_Type


End_Procedure

Curl Command

curl -G -d "filter[groups]=%3Cstring%3E"
	-d "filter[hours_ago]=%3Cinteger%3E"
	-d "filter[num_aggregations]=%3Cinteger%3E"
	-d "filter[pct]=%3Cboolean%3E"
	-d "filter[timespan_h]=%3Cinteger%3E"
	-H "Accept: application/json"
https://api.app.ddog-gov.com/api/v2/metrics/:metric_name/estimate

Postman Collection Item JSON

{
  "name": "Tag Configuration Cardinality Estimator",
  "request": {
    "method": "GET",
    "header": [
      {
        "key": "Accept",
        "value": "application/json"
      }
    ],
    "url": {
      "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
      "host": [
        "{{baseUrl}}"
      ],
      "path": [
        "api",
        "v2",
        "metrics",
        ":metric_name",
        "estimate"
      ],
      "query": [
        {
          "key": "filter[groups]",
          "value": "<string>",
          "description": "Filtered tag keys that the metric is configured to query with."
        },
        {
          "key": "filter[hours_ago]",
          "value": "<integer>",
          "description": "The number of hours of look back (from now) to estimate cardinality with."
        },
        {
          "key": "filter[num_aggregations]",
          "value": "<integer>",
          "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
        },
        {
          "key": "filter[pct]",
          "value": "<boolean>",
          "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
        },
        {
          "key": "filter[timespan_h]",
          "value": "<integer>",
          "description": "A window, in hours, from the look back to estimate cardinality with."
        }
      ],
      "variable": [
        {
          "key": "metric_name",
          "value": "<string>"
        }
      ]
    },
    "description": "Returns the estimated cardinality for a metric with a given tag, percentile and number of aggregations configuration using Metrics without Limits&trade;."
  },
  "response": [
    {
      "name": "Success",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "metrics",
            ":metric_name",
            "estimate"
          ],
          "query": [
            {
              "key": "filter[groups]",
              "value": "<string>",
              "description": "Filtered tag keys that the metric is configured to query with."
            },
            {
              "key": "filter[hours_ago]",
              "value": "<integer>",
              "description": "The number of hours of look back (from now) to estimate cardinality with."
            },
            {
              "key": "filter[num_aggregations]",
              "value": "<integer>",
              "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
            },
            {
              "key": "filter[pct]",
              "value": "<boolean>",
              "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
            },
            {
              "key": "filter[timespan_h]",
              "value": "<integer>",
              "description": "A window, in hours, from the look back to estimate cardinality with."
            }
          ],
          "variable": [
            {
              "key": "metric_name"
            }
          ]
        }
      },
      "status": "OK",
      "code": 200,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"data\": {\n    \"attributes\": {\n      \"estimate_type\": \"count_or_gauge\",\n      \"estimated_at\": \"<dateTime>\",\n      \"estimated_output_series\": \"<long>\"\n    },\n    \"id\": \"<string>\",\n    \"type\": \"metric_cardinality_estimate\"\n  }\n}"
    },
    {
      "name": "API error response.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "metrics",
            ":metric_name",
            "estimate"
          ],
          "query": [
            {
              "key": "filter[groups]",
              "value": "<string>",
              "description": "Filtered tag keys that the metric is configured to query with."
            },
            {
              "key": "filter[hours_ago]",
              "value": "<integer>",
              "description": "The number of hours of look back (from now) to estimate cardinality with."
            },
            {
              "key": "filter[num_aggregations]",
              "value": "<integer>",
              "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
            },
            {
              "key": "filter[pct]",
              "value": "<boolean>",
              "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
            },
            {
              "key": "filter[timespan_h]",
              "value": "<integer>",
              "description": "A window, in hours, from the look back to estimate cardinality with."
            }
          ],
          "variable": [
            {
              "key": "metric_name"
            }
          ]
        }
      },
      "status": "Bad Request",
      "code": 400,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "API error response.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "metrics",
            ":metric_name",
            "estimate"
          ],
          "query": [
            {
              "key": "filter[groups]",
              "value": "<string>",
              "description": "Filtered tag keys that the metric is configured to query with."
            },
            {
              "key": "filter[hours_ago]",
              "value": "<integer>",
              "description": "The number of hours of look back (from now) to estimate cardinality with."
            },
            {
              "key": "filter[num_aggregations]",
              "value": "<integer>",
              "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
            },
            {
              "key": "filter[pct]",
              "value": "<boolean>",
              "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
            },
            {
              "key": "filter[timespan_h]",
              "value": "<integer>",
              "description": "A window, in hours, from the look back to estimate cardinality with."
            }
          ],
          "variable": [
            {
              "key": "metric_name"
            }
          ]
        }
      },
      "status": "Forbidden",
      "code": 403,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "API error response.",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "metrics",
            ":metric_name",
            "estimate"
          ],
          "query": [
            {
              "key": "filter[groups]",
              "value": "<string>",
              "description": "Filtered tag keys that the metric is configured to query with."
            },
            {
              "key": "filter[hours_ago]",
              "value": "<integer>",
              "description": "The number of hours of look back (from now) to estimate cardinality with."
            },
            {
              "key": "filter[num_aggregations]",
              "value": "<integer>",
              "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
            },
            {
              "key": "filter[pct]",
              "value": "<boolean>",
              "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
            },
            {
              "key": "filter[timespan_h]",
              "value": "<integer>",
              "description": "A window, in hours, from the look back to estimate cardinality with."
            }
          ],
          "variable": [
            {
              "key": "metric_name"
            }
          ]
        }
      },
      "status": "Not Found",
      "code": 404,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    },
    {
      "name": "Too Many Requests",
      "originalRequest": {
        "method": "GET",
        "header": [
          {
            "key": "Accept",
            "value": "application/json"
          },
          {
            "description": "Added as a part of security scheme: apikey",
            "key": "DD-API-KEY",
            "value": "<API Key>"
          }
        ],
        "url": {
          "raw": "{{baseUrl}}/api/v2/metrics/:metric_name/estimate?filter[groups]=<string>&filter[hours_ago]=<integer>&filter[num_aggregations]=<integer>&filter[pct]=<boolean>&filter[timespan_h]=<integer>",
          "host": [
            "{{baseUrl}}"
          ],
          "path": [
            "api",
            "v2",
            "metrics",
            ":metric_name",
            "estimate"
          ],
          "query": [
            {
              "key": "filter[groups]",
              "value": "<string>",
              "description": "Filtered tag keys that the metric is configured to query with."
            },
            {
              "key": "filter[hours_ago]",
              "value": "<integer>",
              "description": "The number of hours of look back (from now) to estimate cardinality with."
            },
            {
              "key": "filter[num_aggregations]",
              "value": "<integer>",
              "description": "The number of aggregations that a `count`, `rate`, or `gauge` metric is configured to use. Max number of aggregation combos is 9."
            },
            {
              "key": "filter[pct]",
              "value": "<boolean>",
              "description": "A boolean, for distribution metrics only, to estimate cardinality if the metric includes additional percentile aggregators."
            },
            {
              "key": "filter[timespan_h]",
              "value": "<integer>",
              "description": "A window, in hours, from the look back to estimate cardinality with."
            }
          ],
          "variable": [
            {
              "key": "metric_name"
            }
          ]
        }
      },
      "status": "Too Many Requests",
      "code": 429,
      "_postman_previewlanguage": "json",
      "header": [
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "cookie": [
      ],
      "body": "{\n  \"errors\": [\n    \"<string>\",\n    \"<string>\"\n  ]\n}"
    }
  ]
}