Create Alert using proxy's resource path

I have a Proxy and in that Proxy's have multiple resource path with multiple endpoints. I would like to create an Apigee ALERT to know which resource path/endpoint is failing. In Alert there is no option to set the resource path. I would be appreciate if anyone can help me on this or any best suggestion to implement .

 

Solved Solved
0 4 426
2 ACCEPTED SOLUTIONS

Hi there,

You are correct in that with Apigee's metric based alerts are unable to configure alerts at a level deeper than the proxy. Meaning that configuring alerts for specific paths and endpoints within that proxy are impossible.

You can, however, use Apigee's log based alerts in tandem with GCP log based metrics to accomplish this. Here's how I was able to get it working:

  1. Use a MessageLogging policy to log your error messages to GCP Cloud Logging. Don't forget to deploy your proxy using a service account with the Logs Writer role. My MessageLogging policy is pasted below. I put it in a DefaultFaultRule, and it's the only proxy fault rule, so it runs every time there is an error in the proxy. Also, note that I am logging a logType label and the request path as these will be referenced in the next step's metric filter.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <MessageLogging continueOnError="false" enabled="true" name="log-to-logging">
      <DisplayName>Log to Logging</DisplayName>
      <CloudLogging>
        <LogName>projects/{organization.name}/logs/{system.timestamp}</LogName>
        <Message contentType="application/json">{"reqPath": "{request.path}"}</Message>
        <Labels>
          <Label>
            <Key>logType</Key>
            <Value>apigeeError</Value>
          </Label>
        </Labels>
      </CloudLogging>
    </MessageLogging>​
  2. Configure a log based counter metric to count every time your newly created log hits Cloud Logging. In my example, I'm creating a metric for the path "path1" within the proxy "g-cloud-logging" so my filter utilizes regex and looks like this ==> labels.logType = "apigeeError" AND jsonPayload.reqPath =~ "/g-cloud-logging/path1/*". You can update the filter with your own path & proxy info.
  3. After you've created this log based metric you can configure your log based alert. The easiest way to start this process is to navigate to your log based metric and select the option to  "create alert from metric"createAlertFromMetric.png
  4. Let's configure the alert now. My alert is configured to trigger if more than 60 logs are found in a minute. To accomplish this, you'll have to update a couple of settings a.) Set the Rolling window field to 1 minute. b.) Make sure your alert trigger is based on threshold, alerts any time series violates, used a threshold position of "above threshold, and has a threshold value of 60. c.) You'll have to configure your own notification channel (mine's a simple email) d.) Finally, create your alert policy
  5. Send your proxy path traffic and force an error to trigger your MessageLogging policy. Make sure you send it enough traffic to exceed the alert threshold.

So to summarize I use an Apigee MessageLogging policy to send error logs to GCP Cloud Logging complete request path data, I then use a log-based metric to count incoming logs for any log which resided in the path "path1", I use that metric in my log-based alert to trigger an email alert any time it goes above the threshold of 60 logs per minute, and finally I send enough traffic to trigger that alert.

With this solution you can create a new metric+alert for any specific path/endpoint combination you'd like. I hope this helps!

View solution in original post

Oh, apologies then. I should have confirmed if you were on Edge or X.

In similar fashion to X, you'll have to utilize tools external to Apigee in order to accomplish this on Edge. You could bootstrap my solution from above and make it work for Edge by utilizing the Google Cloud Logging Extension. Once the data is in Logging you should be able to follow my instructions and configure a metric alert.

Alternatively you could utilize a different extension or a MessageLogging policy to log your messages to a different service. Once the needed data is in your desired logging service it'll be up to you to configure alerts.

View solution in original post

4 REPLIES 4

Hi there,

You are correct in that with Apigee's metric based alerts are unable to configure alerts at a level deeper than the proxy. Meaning that configuring alerts for specific paths and endpoints within that proxy are impossible.

You can, however, use Apigee's log based alerts in tandem with GCP log based metrics to accomplish this. Here's how I was able to get it working:

  1. Use a MessageLogging policy to log your error messages to GCP Cloud Logging. Don't forget to deploy your proxy using a service account with the Logs Writer role. My MessageLogging policy is pasted below. I put it in a DefaultFaultRule, and it's the only proxy fault rule, so it runs every time there is an error in the proxy. Also, note that I am logging a logType label and the request path as these will be referenced in the next step's metric filter.
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <MessageLogging continueOnError="false" enabled="true" name="log-to-logging">
      <DisplayName>Log to Logging</DisplayName>
      <CloudLogging>
        <LogName>projects/{organization.name}/logs/{system.timestamp}</LogName>
        <Message contentType="application/json">{"reqPath": "{request.path}"}</Message>
        <Labels>
          <Label>
            <Key>logType</Key>
            <Value>apigeeError</Value>
          </Label>
        </Labels>
      </CloudLogging>
    </MessageLogging>​
  2. Configure a log based counter metric to count every time your newly created log hits Cloud Logging. In my example, I'm creating a metric for the path "path1" within the proxy "g-cloud-logging" so my filter utilizes regex and looks like this ==> labels.logType = "apigeeError" AND jsonPayload.reqPath =~ "/g-cloud-logging/path1/*". You can update the filter with your own path & proxy info.
  3. After you've created this log based metric you can configure your log based alert. The easiest way to start this process is to navigate to your log based metric and select the option to  "create alert from metric"createAlertFromMetric.png
  4. Let's configure the alert now. My alert is configured to trigger if more than 60 logs are found in a minute. To accomplish this, you'll have to update a couple of settings a.) Set the Rolling window field to 1 minute. b.) Make sure your alert trigger is based on threshold, alerts any time series violates, used a threshold position of "above threshold, and has a threshold value of 60. c.) You'll have to configure your own notification channel (mine's a simple email) d.) Finally, create your alert policy
  5. Send your proxy path traffic and force an error to trigger your MessageLogging policy. Make sure you send it enough traffic to exceed the alert threshold.

So to summarize I use an Apigee MessageLogging policy to send error logs to GCP Cloud Logging complete request path data, I then use a log-based metric to count incoming logs for any log which resided in the path "path1", I use that metric in my log-based alert to trigger an email alert any time it goes above the threshold of 60 logs per minute, and finally I send enough traffic to trigger that alert.

With this solution you can create a new metric+alert for any specific path/endpoint combination you'd like. I hope this helps!

Thank you @ravenhedden  for your quick response. Here I am using Apigee edge not Apigee X. In Apigee edge  what's the solution for this.

Oh, apologies then. I should have confirmed if you were on Edge or X.

In similar fashion to X, you'll have to utilize tools external to Apigee in order to accomplish this on Edge. You could bootstrap my solution from above and make it work for Edge by utilizing the Google Cloud Logging Extension. Once the data is in Logging you should be able to follow my instructions and configure a metric alert.

Alternatively you could utilize a different extension or a MessageLogging policy to log your messages to a different service. Once the needed data is in your desired logging service it'll be up to you to configure alerts.

Thank you @ravenhedden