Home

Awesome

Medium Datadog Utils

A Go library for Devops to retrieve important information from Datadog components

Moving Parts & Functions

Files:


Helper Functions:


Non-Helper Functions:


Example Usage

❯ go run datadog_utils --help
Usage of /var/folders/9d/w68r5sdd787gg_1djyk7jmkm0000gp/T/go-build1368975407/b001/exe/datadog_utils:
  -dash-details string
    	String: Get details for a specific dashboard by ID
  -dash-list
    	Bool: will list all DataDog dashboard IDs
  -find-metric string
    	String: Search our DataDog dashboards for the provided metric name to see if it is in use
  1. --find-metric -- go run datadog_utils --find-metric="server.response.sent" Example output looks like this:
{
  "abc-n3k-26j": [
    "sum:server.response.sent{route:paymentwebhook.handlebraintreeevent,status-code:200,$env}.as_count()",
    "sum:server.response.sent{route:paymentwebhook.handlebraintreeevent,status-code:401,$env}.as_count()",
    "sum:server.response.sent{route:paymentwebhook.handlebraintreeevent,status-code:500,$env}.as_count()"
  ],
  "fzi-6va-aag": [
    "sum:server.response.sent{env:prod,route:mediummembership.addmembership,$provider,$environment} by {status-code}.as_count()",
    "sum:server.response.sent{env:prod,route:mediummembership.addmembership,status-code:200,$provider,$environment}.as_count()/sum:server.response.sent{env:prod,route:mediummembership.addmembership,$provider,$environment}.as_count()*100"
  ],
  "n43-std-5sh": [
    "sum:server.response.sent{service:medium-legacy,$env,$controller,$route,status-category:2xx,$status}.as_count()",
    "sum:server.response.sent{service:medium-legacy,$env,$controller,$route,status-category:3xx,$status}.as_count()",
    "sum:server.response.sent{service:medium-legacy,$env,$controller,$route,status-category:4xx,$status}.as_count()",
    "sum:server.response.sent{service:medium-legacy,$env,$controller,$route,status-category:5xx,$status}.as_count()"
  ]
}
{
  "Author": "adrian@medium.com",
  "ID": "abc-n3k-26j",
  "URL": "/dashboard/abc-n3k-26j/braintree",
  "Widgets": "14"
}
{
  "Author": "fiona@medium.com",
  "ID": "fzi-6va-aag",
  "URL": "/dashboard/fzi-6va-aag/trial-purchase-real-time-monitoring",
  "Widgets": "6"
}
{
  "Author": "lyra@medium.com",
  "ID": "n43-std-5sh",
  "URL": "/dashboard/n43-std-5sh/medium2",
  "Widgets": "25"
}
  1. --dash-details -- `go run datadog_utils --dash-details="abc-n3k-26j"
Here are the high-level details: 
{
  "Author": "adrian@medium.com",
  "ID": "abc-n3k-26j",
  "URL": "/dashboard/abc-n3k-26j/braintree",
  "Widgets": "14"
}`
  1. --dash-list -- go run datadog_utils --dash-list

Additional References & Documentation


Hierarchy of Datadog Dashboard (As Related to Fetching Expressions in Widgets)

Note: WidgetDefinition actually is a struct that contains every definition type. Datadog just adds nil to the ones not applicable to a specific widget. You can see all of them here, but ultimately this implementation is what necessitated the need for the CheckIgnoredWidgetDefs helper function. Each widget definition has its own Request Type. You can see GetWidgetExpressions() how we fetch the various parts of the Widget & nested info.

graph TD
    A[Dashboard]-->B[Widgets]
    B-->C[WidgetDefinition]
    C-->D[SpecificDefinitionType]
    D-->E[Requests Array]
    E-->F[SpecificRequestType]
    F-->G[Q]

Changelog

2021 - May 19 -- Initial Completion outside of Medium repo, for personal convenience / use