Logic to find the target server is up/down

Not applicable

Hi, I'm looking for a logic to find the target server is up or down. Is there any sample proxy or code for that? Suggestions please.

Thanks in advance.

0 13 867
13 REPLIES 13

@Swapna ,

Please take a look at Apigee's API Test & Monitoring tool, Apigee Test. It helps you track your target server uptime & alert you based on probe settings. Keep us posted if you have any queries using same.

@Anil Sagar I knew it about Apigee health check and we already have probe for it. But I wanted to do this through Apigee edge proxy, we have a requirement like that. Any idea? Thank you!

@Swapna , You mean implement some logic in proxy code based on target server is up / down ? Generally, you will use response code to classify it's up / down.

yeah. I was wondering is there anything else we have it apigee edge. Thanks!

@Swapna , Is "response.status.code" flow variable not sufficient to determine target server status ? Am i missing something here ? What do you mean "Is there anything else" ?

i think he is trying to figure this out so he can route to a different location maybe? this way he doesnt have to code the client as defensively?

@Anil Sagar and @Benjamin Goldman Thanks for the response.

Yes you are correct. I would like to route traffic to some other location when the existing server is down. I'm routing the traffic but problem here is I'm not getting all the existing user headers for the new location server. Not sure whether I'm doing anything wrong or not. I'm using the below service callout for routing to different location. Is there anything else required here to pass the user header variables to new location? I'm also not seeing the below X-Async header in new location server. Please advice.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ServiceCallout async="false" continueOnError="false" enabled="true" name="MaintenancePolicy">

<DisplayName>MaintenancePolicy</DisplayName>

<Properties/>

<!--<Request clearPayload="true" variable="myRequest"> <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> </Request>-->

<Response>calloutResponse</Response>

<HTTPTargetConnection>

<Properties>

<Property name="request.header.X-Async">true</Property>

</Properties>

<URL>http://xxx-test.apigee.net/</URL> </HTTPTargetConnection>

</ServiceCallout>

so my approach would be to use the load balancing target server construction and have the "second" or "failover" server be flagged as "IsFallback"

I dont know if this will solve your header problems though... http://docs.apigee.com/api-services/content/load-balancing-across-backend-servers

<TargetEndpoint name="default">
  <HTTPTargetConnection>
      <LoadBalancer>
        <Algorithm>RoundRobin</Algorithm>
        <Server name="primary_server" />
        <Server name="secondary_server">
          <IsFallback>true</IsFallback>
        </Server>
      </LoadBalancer>
      <Path>/test</Path>
  </HTTPTargetConnection>
</TargetEndpoint>

@Anil Sagar and @Benjamin Goldman Looks like both are different.

Not applicable

@Swapna, if you are looking at trying to monitor if the target server is running or not from within an API Proxy you can use the HealthMonitor with a TCP or a HTTP monitor defined within the TargetServer.

<HealthMonitor>
    <IsEnabled>true</IsEnabled>
    <IntervalInSec>5</IntervalInSec>
    <TCPMonitor>
        <ConnectTimeoutInSec>10</ConnectTimeoutInSec>
        <Port>80</Port>
    </TCPMonitor>
</HealthMonitor>

@Rakshith Thanks for the response. This will be good if we are monitoring target server. But we have a requirement to route the traffic to different location if current target location is down. So, we are routing the traffic but issue here is I'm not getting all the request headers (User request headers) to the new location.

Is there any way that we can achieve this? or do we have any option to retrieve all headers from the request to pass it. Thanks!

If you requirement is just to route traffic to a fallback server then you can use the IsFallback tag to ensure it gets routed to right service.

<TargetEndpoint name="default">
  <HTTPTargetConnection>
      <LoadBalancer>
        <Algorithm>RoundRobin</Algorithm>
        <Server name="target1" />
        <Server name="target2">
          <IsFallback>true</IsFallback>
        </Server>
      </LoadBalancer>
      <Path>/test</Path>
  </HTTPTargetConnection>
</TargetEndpoint>

WRT the header by default headers are copied unless request.retain.headers.enabled property is overridden under TargetEndpoint properties. If you want to manually change then you can get all the request headers names with the variable request.headers.names and then the values for each of the headers.