Skip to content

Instantly share code, notes, and snippets.

@gspncr
Last active September 7, 2021 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gspncr/f46673c5d37c5e140ff8085ab725d29d to your computer and use it in GitHub Desktop.
Save gspncr/f46673c5d37c5e140ff8085ab725d29d to your computer and use it in GitHub Desktop.

remote write config example

Lines 24-27 are doing the filtering per docs

# my global config
global:
  scrape_interval:     60s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  evaluation_interval: 60s # Evaluate rules every 15 seconds. The default is every 1 minute.
  # scrape_timeout is set to the global default (10s).

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
  # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
  - job_name: 'my-local-pi'
    scrape_interval: 60s
    static_configs:
    - targets: ['localhost:9100']

remote_write:
- url: https://metric-api.newrelic.com/prometheus/v1/write?prometheus_server=raspberry-pi
  bearer_token: <redacted>
  write_relabel_configs:
    - source_labels: ['__name__', 'instance']
      regex: 'node_memory_.*'
      action: 'drop'

nerdgraph mutation to drop prometheus API metrics

mutation {
  nrqlDropRulesCreate(accountId: 1147177, rules: {action: DROP_DATA, description: "no more prometheus data", nrql: "SELECT * from Metric where newrelic.source IN ('prometheusAPI')"}) {
    failures {
      error {
        description
        reason
      }
    }
    successes {
      description
      action
    }
  }
}

returns

{
  "data": {
    "nrqlDropRulesCreate": {
      "failures": [],
      "successes": [
        {
          "description": "no more prometheus data",
          "id": "44076317"
        }
      ]
    }
  }
}

nerdgraph mutation to drop Logs

mutation {
  nrqlDropRulesCreate(accountId: 1147177, rules: {action: DROP_DATA, description: "no more judgey logs", nrql: "SELECT * FROM Log WHERE myLogJudges IS TRUE"}) {
    failures {
      error {
        description
        reason
      }
    }
    successes {
      description
      action
    }
  }
}

returns

{
  "data": {
    "nrqlDropRulesCreate": {
      "failures": [],
      "successes": [
        {
          "description": "no more judgey logs",
          "id": "382671"
        }
      ]
    }
  }
}

nerdgraph query for data drop rules

{
  actor {
    account(id: 1147177) {
      nrqlDropRules {
        list {
          rules {
            id
            description
          }
        }
      }
    }
  }
}

returns

{
  "data": {
    "actor": {
      "account": {
        "nrqlDropRules": {
          "list": {
            "rules": [
              {
                "description": "Removes datanerd@example.com",
                "id": "31065"
              },
              {
                "description": "drop data from appName is 'NR-One Production'",
                "id": "31245"
              },
              {
                "description": "no more prometheus data",
                "id": "44076317"
              }
            ]
          }
        }
      }
    }
  }
}

mutation to delete a data drop rule

remove the earlier created rule:

mutation {
  nrqlDropRulesDelete(accountId: 1147177, ruleIds: "44076317") {
    failures {
      error {
        description
        reason
      }
    }
    successes {
      description
      id
    }
  }
}

returns

{
  "data": {
    "nrqlDropRulesDelete": {
      "failures": [],
      "successes": [
        {
          "description": "no more prometheus data",
          "id": "44076317"
        }
      ]
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment