|
1 | 1 | # API-Management Traffic-Monitor based ELK stack |
2 | 2 |
|
| 3 | +When having many API-Gateway instances with millions of requests the API-Gateway Traffic Monitor can become slow. The purpose of this project is to solve that performance issue and get other benefits by using a standard external datastore: Elasticsearch. |
| 4 | + |
| 5 | +The overall architecture this project provides looks like this: |
| 6 | +![Architecture][img1] |
| 7 | + |
| 8 | +### How it works |
| 9 | +Each API-Gateway instance is writing, [if configured](#enable-open-traffic-event-log), Open-Traffic Event-Log-Files, which are streamed by [Filebeat](https://www.elastic.co/beats/filebeat) into a Logstash-Instance. [Logstash](https://www.elastic.co/logstash) performs data pre-processing, combines different events and finally forwards the document into an [Elasticsearch](https://www.elastic.co/elasticsearch) cluster. |
| 10 | + |
| 11 | +Once the data is indexed by Elasticsearch it can be used by different clients. This process allows almost realtime monitoring of incoming requests. It takes around 5 seconds until a request is available in Elasticsearch. |
| 12 | + |
| 13 | +## Option 1 - Using the existing Traffic-Monitor |
| 14 | +One option is to use the existing API-Gateway Traffic-Monitor. That means, you use the same tooling as of today, but the underlying implementation of the Traffic-Monitor API is now pointing to Elasticsearch instead of the internal OPSDB hosted by each API-Gateway instance. This improves performance damatically, as Elasticsearch can scale across multiple machines if required and other dashboards can be created for instance with Kibana. |
| 15 | +The glue between Elasticsearch and the API-Gateway Traffic-Monitor is an API-Builder project, that is exposing the same Traffic-Monitor API, but it is implemented using Elasticsearch instead of the OPSDB. The API-Builder is available as a ready to use Docker-Image and preconfigured in the docker-compose file. |
| 16 | +Finally, the Admin-Node-Manager has to be configured to use the API-Builder API instead of the internal implementation. |
| 17 | + |
| 18 | +API-Builder status: |
| 19 | + |
| 20 | + |
| 21 | +## Option 2 - Logspector |
| 22 | +The Logspecotr is a new separated user-interface with very basic set of functionilties. As part of the project the Logspector is activated by default when using `docker-compose up -d`. If you don't wanna use it, it can be disabled by commenting out the following lines in the docker-compose.yml file: |
| 23 | +```yaml |
| 24 | + nginx: |
| 25 | + image: nginx:1.17.6 |
| 26 | + ports: |
| 27 | + - 8888:90 |
| 28 | + volumes: |
| 29 | + - ${PWD}/nginx/www:/usr/share/nginx/html |
| 30 | + - ${PWD}/nginx/conf:/etc/nginx |
| 31 | + depends_on: |
| 32 | + - elasticsearch1 |
| 33 | + networks: |
| 34 | + - elastic |
| 35 | + - ingress |
| 36 | +``` |
| 37 | +The Log-Inspector is accessible on the following URL: `http://hostname-to-your-docker-machine:8888/logspector.html` |
| 38 | + |
| 39 | +![Log-Spector][img5] |
| 40 | + |
| 41 | + |
3 | 42 | ## Prerequisites |
| 43 | +For a simple deployment the prerequisites are very simple as all services can be started as a Docker-Container. In order to start all components in PoC-Like-Mode you just need: |
| 44 | + |
| 45 | +1. A Docker engine |
| 46 | +2. docker-compose installed |
| 47 | +3. An API-Management Version >7.7-20200130 |
| 48 | + - Versin 7.7-20200130 is required due to some Dateform changes in the Open-Traffic-Format. With older versions of the API-Gateway you will get an error in Logstash processing. |
4 | 49 |
|
5 | | -1. docker |
6 | | -2. docker-compose |
7 | | -3. API-Management Version >7.7-20200130 |
| 50 | +Using the provided docker-compose is good to play with, however this approach is not recommended for production environments. Depending the load a dedicated machine (node) for Elasticsearch is recommended. The default configuration is prepared to scale up to five Elasticsearch nodes, which can handle millions of requests. To run Logstash and the API-Builder service a Docker-Orchestration framework is recommended as you get monitoring, self-healing, elasticity. |
| 51 | + |
| 52 | +## Installation / Configuration |
| 53 | +To run the components in a PoC-Like mode, the recommended way is to clone this project onto a machine having docker and docker-compose installed. Also this machine must have file-based access to the running API-Gateway instance, as the Filebeat docker container will mount the open-traffic folder into the docker-container. |
| 54 | + |
| 55 | +`git clone https://github.com/Axway-API-Management-Plus/apigateway-openlogging-elk.git` |
| 56 | + |
| 57 | +This creates a local copy of the repository and you can start from there. |
| 58 | + |
| 59 | +### Enable Open-Traffic Event Log |
| 60 | +Obviously you have to enable Open-Traffic-Event log for your API-Gateway instances. [Read here][1] how to enable the Open-Traffic Event-Log. |
| 61 | +After this configuration has been done, Open-Traffic log-files will created by default in this location: `apigateway/logs/opentraffic`. This location becomes relevant in the next step, when configuring Filebeat. |
| 62 | + |
| 63 | +### Configure the Admin-Node-Manager |
| 64 | +This step is required if you would like to use the existing Traffic-Monitor in combination Elasticsearch. |
| 65 | +The Admin-Node-Manager (listening by default on port 8090) is responsible to server the API-Manager Traffic-Monitor and needs to be configured to use the API-Builder API instead. |
| 66 | +For the following steps, please open the Admin-Node-Manager configuration in Policy-Studio. You can [here](https://docs.axway.com/bundle/axway-open-docs/page/docs/apim_administration/apigtw_admin/general_rbac_ad_ldap/index.html#use-the-ldap-policy-to-protect-management-services) how to do that. |
| 67 | +- Create a new policy called: `Use Elasticsearch API` |
| 68 | +- Configure this policy like so: |
| 69 | + ![use ES API][img3] |
| 70 | + - The `Compare Attribute` filter checks if the requested API is already handled by the API-Builder project. |
| 71 | + _As of today, only the Traffic-Overview is handled by the API-Builder. This will be changed soon._ |
| 72 | + - Add the following: `http.request.path` is `/api/router/service/instance-1/ops/search` |
| 73 | + _The list of requests will be extended once the API-Builder project can serve more (e.g. the Request-Detail view)_ |
| 74 | + ![Is API Managed][img6] |
| 75 | + - Adjust the URL of the Connect to URL filter to your running API-Builder docker container and port (default is 8889). |
| 76 | + ![Connect to ES API][img7] |
| 77 | +- Insert the created policy as a callback policy into the main policy: `Protect Management Interfaces` like so: |
| 78 | + ![Use Callback][img4] |
| 79 | + |
| 80 | +After you have saved back the configuration to the Admin-Node-Manager and restarted it, the Admin-Node-Manager will use the API-Builder API (Elasticsearch) to serve the specified request-types. |
| 81 | + |
| 82 | +### Setup filebeat |
| 83 | +:exclamation: __This is an important step, as otherwise Filebeat will not see and send any Open-Traffic Event data!__ |
| 84 | +Before starting the container using docker-compose, make sure to setup the paths in the .env file to your running API-Gateway instance. This configuration is used to mount the Open-Traffic-Folder into Filebeat container. |
| 85 | +``` |
| 86 | +APIGATEWAY_LOGS_FOLDER=/home/localuser/Axway-x.y.z/apigateway/logs/opentraffic |
| 87 | +APIGATEWAY_TRACES_FOLDER=/home/localuser/Axway-x.y.z/apigateway/groups/group-1/instance-1/trace |
| 88 | +``` |
| 89 | +
|
| 90 | +### Setup API-Builder |
| 91 | +As the API-Builder container needs to communicate with Elasticsearch it needs to know where Elasticsearch is running. Use this environment variable to configure it: |
| 92 | +``` |
| 93 | +ELASTIC_NODE=http://elasticsearch1:9200 |
| 94 | +``` |
| 95 | +Please note, when using the default docker-compose.yaml the default setting is sufficient, as it's using the internal Docker-Network `elastic`. |
8 | 96 |
|
9 | 97 | ### Update vm.max_map_count kernel setting to at least 262144 |
10 | 98 |
|
11 | 99 | See https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-prod-prerequisites |
12 | 100 |
|
13 | | -## Start local elasticsearch cluster |
14 | | - |
15 | | -1. Edit the .env file and configure both APIGATEWAY_LOGS_FOLDER and APIGATEWAY_TRACES_FOLDER environment variables to point to your open traffic and trace folders respectively. |
16 | | -2. Bring the cluster up using docker-compose: |
| 101 | +### Start local elasticsearch cluster |
| 102 | +Bring the cluster up using docker-compose: |
17 | 103 | ```` |
18 | 104 | docker-compose up -d |
19 | 105 | ```` |
| 106 | +Of course, the components can also run on different machines or on a Docker-Orchestration framework such as Kubernetes. |
20 | 107 |
|
21 | 108 | ## Stop cluster |
22 | 109 | ```` |
23 | 110 | docker-compose down |
24 | 111 | ```` |
25 | 112 |
|
| 113 | +[img1]: imgs/component-overview.png |
| 114 | +[img2]: imgs/node-manager-policies.png |
| 115 | +[img3]: imgs/node-manager-use-es-api.png |
| 116 | +[img4]: imgs/node-manager-policies-use-elasticsearch-api.png |
| 117 | +[img5]: imgs/Logspector.png |
| 118 | +[img6]: imgs/IsmanagedbyElasticsearchAPI.png |
| 119 | +[img7]: imgs/connect-to-elasticsearch-api.png |
| 120 | +
|
| 121 | +[1]: https://docs.axway.com/bundle/axway-open-docs/page/docs/apim_administration/apigtw_admin/admin_open_logging/index.html#configure-open-traffic-event-logging |
0 commit comments