Skip to content
This repository was archived by the owner on Dec 14, 2022. It is now read-only.

Commit 9bd150a

Browse files
author
Chris Wiechmann
committed
Added first changes for APM-Support
1 parent 8b1ca2f commit 9bd150a

File tree

5 files changed

+201
-0
lines changed

5 files changed

+201
-0
lines changed

apibuilder4elastic/app.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
const APIBuilder = require('@axway/api-builder-runtime');
2+
3+
const apm = require('elastic-apm-node').start({
4+
serviceName: 'APIBuilder4Elastic',
5+
serverUrl: 'http://api-env.demo.axway.com:8200'
6+
});
7+
28
const server = new APIBuilder();
39

410
// lifecycle examples

apibuilder4elastic/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"@axway/api-builder-plugin-ft-timer": "^1.0.2",
4141
"@axway/api-builder-plugin-invoke-flow": "^1.1.1",
4242
"@axway/api-builder-runtime": "^4.68.0",
43+
"elastic-apm-node": "^3.25.0",
4344
"api-builder-plugin-api-management-kpis": "file:custom_flow_nodes/api-builder-plugin-api-management-kpis",
4445
"api-builder-plugin-authorization": "file:custom_flow_nodes/api-builder-plugin-authorization",
4546
"api-builder-plugin-axway-api-management": "file:custom_flow_nodes/api-builder-plugin-axway-api-management",

apm/docker-compose.apm-server.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.7'
2+
services:
3+
# APM-Service
4+
metricbeat:
5+
image: docker.elastic.co/apm/apm-server:${ELASTIC_VERSION}
6+
restart: on-failure:10
7+
entrypoint: /usr/local/scripts/apm-server-entrypoint.sh
8+
container_name: apm-server
9+
environment:
10+
- ELASTICSEARCH_HOSTS=${ELASTICSEARCH_HOSTS}
11+
- ELASTICSEARCH_CA=${ELASTICSEARCH_CA}
12+
- SELF_MONITORING_ENABLED=${SELF_MONITORING_ENABLED}
13+
ports:
14+
- 8200:8200
15+
volumes:
16+
- ./apm-server.yml:/usr/share/apm-server/apm-server.yml:ro
17+
- ../config/certificates:/usr/share/apm-server/config/certificates
18+
networks:
19+
- elastic
20+
logging:
21+
options:
22+
max-file: "3"
23+
max-size: "10m"
24+
25+
volumes:
26+
logs:
27+
metricbeatdata:
28+
29+
networks:
30+
elastic:
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
#!/bin/bash -e
2+
3+
# Each Metricbeat requires access to Elasticsearch to send Metric information and optionally (but at least one times)
4+
# access to Kibana in order to load the Metricbeat Dashboards into Kibana.
5+
# This script adjusts the configured list of Elasticsearch hosts as required by Metricbeat. In addition it is
6+
# using the first Elasticsearch host as the Kibana-Host if not given externally with KIBANA_HOST
7+
8+
# Save the originally given parameters as they are forwarded to the original docker-entrypoint script
9+
params=$@
10+
11+
export METRICBEAT_KIBANA_ENABLED=false
12+
export METRICBEAT_ELASTICSEARCH_ENABLED=false
13+
export METRICBEAT_LOGSTASH_ENABLED=false
14+
export METRICBEAT_BEAT_ENABLED=false
15+
export METRICBEAT_MEMCACHED_ENABLED=false
16+
export METRICBEAT_SYSTEM_ENABLED=false
17+
export METRICBEAT_DOCKER_ENABLED=false
18+
19+
# Don't start if the node-name is not set
20+
if [ -z "${METRICBEAT_NODE_NAME}" ];then
21+
echo "METRICBEAT_NODE_NAME is missing";
22+
exit 55;
23+
fi
24+
25+
if [ -z "${METRICBEAT_MODULES}" ];then
26+
echo "METRICBEAT_MODULES is missing";
27+
exit 77;
28+
else
29+
# Parse the comma separated list
30+
IFS=', ' read -r -a array <<< "${METRICBEAT_MODULES}"
31+
for module in "${array[@]}"
32+
do
33+
if [ "${module}" = "kibana" ]; then
34+
echo "Enable metricbeat Kibana module"
35+
export METRICBEAT_KIBANA_ENABLED=true
36+
continue;
37+
fi
38+
if [ "${module}" = "elasticsearch" ]; then
39+
echo "Enable metricbeat Elasticsearch module"
40+
export METRICBEAT_ELASTICSEARCH_ENABLED=true
41+
continue;
42+
fi
43+
if [ "${module}" = "logstash" ]; then
44+
echo "Enable metricbeat Logstash module"
45+
export METRICBEAT_LOGSTASH_ENABLED=true
46+
continue;
47+
fi
48+
if [ "${module}" = "filebeat" ]; then
49+
echo "Enable metricbeat Beat module"
50+
export METRICBEAT_BEAT_ENABLED=true
51+
continue;
52+
fi
53+
if [ "${module}" = "memcached" ]; then
54+
echo "Enable metricbeat Memcached module"
55+
export METRICBEAT_MEMCACHED_ENABLED=true
56+
continue;
57+
fi
58+
if [ "${module}" = "system" ]; then
59+
echo "Enable metricbeat System module"
60+
export METRICBEAT_SYSTEM_ENABLED=true
61+
continue;
62+
fi
63+
if [ "${module}" = "docker" ]; then
64+
echo "Enable metricbeat Docker module"
65+
export METRICBEAT_DOCKER_ENABLED=true
66+
continue;
67+
fi
68+
done
69+
fi
70+
71+
if [ "${METRICBEAT_ENABLED}" = "false" ];then
72+
echo "Metricbeat is disabled as parameter METRICBEAT_ENABLED is set to false";
73+
exit 88;
74+
fi
75+
76+
if [ -z "${METRICBEAT_USERNAME}" ] || [ -z "${METRICBEAT_PASSWORD}" ];then
77+
if [ "${ELASTICSEARCH_ANONYMOUS_ENABLED}" = "false" ];then
78+
echo "ELASTICSEARCH_ANONYMOUS_ENABLED is false, but parameter: METRICBEAT_USERNAME or METRICBEAT_PASSWORD is missing";
79+
exit 98;
80+
fi
81+
fi
82+
83+
if [ -z "${ELASTICSEARCH_HOSTS}" ];then
84+
echo "Parameter: ELASTICSEARCH_HOSTS is missing";
85+
exit 99;
86+
fi
87+
88+
if [ -z "${KIBANA_HOST}" ];then
89+
echo "Parameter KIBANA_HOST not given, using https://kibana:5601 as default";
90+
kibanaHost="https://kibana:5601" # This is the default as given by Docker-Compose
91+
export KIBANA_HOST=$kibanaHost
92+
echo "KIBANA_HOST set to $kibanaHost"
93+
fi
94+
95+
# All Elasticsearch hosts should be monitored by one Metricbeat
96+
# Therefore the list format of the given Elasticsearch hosts must be adjusted for Metricbeat
97+
elasticHosts=`echo ${ELASTICSEARCH_HOSTS} | awk '
98+
function ltrim(s) { sub(/^[ \t\r\n]+/, "", s); return s }
99+
function rtrim(s) { sub(/[ \t\r\n]+$/, "", s); return s }
100+
function trim(s) { return rtrim(ltrim(s)); }
101+
{
102+
split($0, va, /,/); vl=""; for (v in va) {
103+
if (vl =="" )
104+
vl = sprintf("\"%s\"", trim(va[v]));
105+
else
106+
vl = vl sprintf(",\"%s\"", trim(va[v]));
107+
}
108+
printf("'[%s]'", vl)
109+
}'
110+
`
111+
112+
echo "Elasticsearch hosts: ${elasticHosts} will be monitored by Metricbeat"
113+
# Check if Kibana-Host is reachable and if not, disable Kibana-Monitoring
114+
curl -skf ${KIBANA_HOST} || rc=$?
115+
if [ \( "$rc" != "0" -a "$rc" != "" \) ] && [ "${SKIP_VALIDATION}" != true ]; then
116+
echo "KIBANA_HOST: ${KIBANA_HOST} is not reachable. Got negative returncode for command: curl -kv ${KIBANA_HOST}";
117+
echo "Metricbeat Kibana monitoring will be disabled on this host.";
118+
export METRICBEAT_KIBANA_ENABLED=false;
119+
else
120+
# Only if Kibana is reachable, try to load Dashboards is enabled
121+
echo "Successfully connected to Kibana-Host: ${KIBANA_HOST}."
122+
if [ "${METRICBEAT_SETUP_DASHBOARDS}" != "false" ];then
123+
echo "Loading Metricbeat Dashboards into Kibana";
124+
# Get the config file required to load Kibana-Dashboards
125+
for i in "$@"
126+
do
127+
case $i in
128+
-c)
129+
shift
130+
configFile="$1"
131+
break
132+
;;
133+
*)
134+
shift
135+
;;
136+
esac
137+
done
138+
echo "Calling metricbeat setup with config file: ${configFile}"
139+
if [ "${BATS_TEST}" != true ]; then
140+
metricbeat setup --strict.perms=false -e -c ${configFile}
141+
fi
142+
fi
143+
fi
144+
145+
export ELASTICSEARCH_HOSTS=$elasticHosts
146+
147+
# Skip, if running in a test
148+
if [ "${BATS_TEST}" != true ]; then
149+
# Finally call the original Docker-Entrypoint
150+
/usr/local/bin/docker-entrypoint $params
151+
fi

env-sample

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,19 @@ ELASTIC_VERSION=7.15.2
492492
# Defaults to https://kibana:5601
493493
#KIBANA_HOST=https://my.kibanahost.net:5601
494494

495+
################################################################################################
496+
# APM
497+
################################################################################################
498+
# The solution can use APM from Elastic to monitor the behavior of the API builder process.
499+
500+
# ----------------------------------------------------------------------------------------------
501+
# This is where Elastic-APM is enabled, which is an additional service before Elasticsearch. It
502+
# is used by API Builder to pass application performance management data from the
503+
# API Builder process.
504+
# Used-By: Elastic-APM
505+
# Defaults to true
506+
#APM_ENABLED=false
507+
495508
################################################################################################
496509
# Certificates and Certificate authorities
497510
################################################################################################

0 commit comments

Comments
 (0)