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

Commit ce6736d

Browse files
author
Chris Wiechmann
committed
Added APM-Support
1 parent 9bd150a commit ce6736d

File tree

6 files changed

+56
-147
lines changed

6 files changed

+56
-147
lines changed

apibuilder4elastic/app.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
const APIBuilder = require('@axway/api-builder-runtime');
22

3-
const apm = require('elastic-apm-node').start({
4-
serviceName: 'APIBuilder4Elastic',
5-
serverUrl: 'http://api-env.demo.axway.com:8200'
6-
});
3+
if(process.env.APM_ENABLED) {
4+
console.log(`Application performance monitoring enabled. Using APM-Server: ${process.env.APM_SERVER || 'http://apm-server:8200'}`);
5+
require('elastic-apm-node').start({
6+
serviceName: 'APIBuilder4Elastic',
7+
serverUrl: process.env.APM_SERVER || 'http://apm-server:8200'
8+
});
9+
}
710

811
const server = new APIBuilder();
912

apm/apm-server.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apm-server:
2+
host: "localhost:8200"
3+
rum:
4+
enabled: true
5+
6+
output:
7+
elasticsearch:
8+
hosts: ${ELASTICSEARCH_HOSTS}
9+
username: ${APM_USERNAME}
10+
password: ${APM_PASSWORD}
11+
ssl:
12+
certificate_authorities: ${ELASTICSEARCH_CA}
13+
14+
monitoring:
15+
enabled: true
16+
elasticsearch:
17+
username: ${APM_USERNAME}
18+
password: ${APM_PASSWORD}
19+
cluster_uuid: ${ELASTICSEARCH_CLUSTER_UUID}

apm/docker-compose.apm-server.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,28 @@ services:
55
image: docker.elastic.co/apm/apm-server:${ELASTIC_VERSION}
66
restart: on-failure:10
77
entrypoint: /usr/local/scripts/apm-server-entrypoint.sh
8+
command: -environment container
89
container_name: apm-server
910
environment:
11+
- APM_ENABLED=${APM_ENABLED:-true}
1012
- ELASTICSEARCH_HOSTS=${ELASTICSEARCH_HOSTS}
13+
- APM_USERNAME=${APM_USERNAME:-""}
14+
- APM_PASSWORD=${APM_PASSWORD:-""}
1115
- ELASTICSEARCH_CA=${ELASTICSEARCH_CA}
12-
- SELF_MONITORING_ENABLED=${SELF_MONITORING_ENABLED}
16+
- ELASTICSEARCH_ANONYMOUS_ENABLED=${ELASTICSEARCH_ANONYMOUS_ENABLED}
17+
- ELASTICSEARCH_CLUSTER_UUID=${ELASTICSEARCH_CLUSTER_UUID}
1318
ports:
1419
- 8200:8200
1520
volumes:
1621
- ./apm-server.yml:/usr/share/apm-server/apm-server.yml:ro
1722
- ../config/certificates:/usr/share/apm-server/config/certificates
23+
- ./scripts:/usr/local/scripts
1824
networks:
1925
- elastic
2026
logging:
2127
options:
2228
max-file: "3"
2329
max-size: "10m"
2430

25-
volumes:
26-
logs:
27-
metricbeatdata:
28-
2931
networks:
3032
elastic:
Lines changed: 6 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,13 @@
11
#!/bin/bash -e
22

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";
3+
if [ "${APM_ENABLED}" = "false" ];then
4+
echo "APM is disabled as parameter APM_ENABLED is set to false";
735
exit 88;
746
fi
757

76-
if [ -z "${METRICBEAT_USERNAME}" ] || [ -z "${METRICBEAT_PASSWORD}" ];then
8+
if [ -z "${APM_USERNAME}" ] || [ -z "${APM_PASSWORD}" ];then
779
if [ "${ELASTICSEARCH_ANONYMOUS_ENABLED}" = "false" ];then
78-
echo "ELASTICSEARCH_ANONYMOUS_ENABLED is false, but parameter: METRICBEAT_USERNAME or METRICBEAT_PASSWORD is missing";
10+
echo "ELASTICSEARCH_ANONYMOUS_ENABLED is false, but parameter: APM_USERNAME or APM_PASSWORD is missing";
7911
exit 98;
8012
fi
8113
fi
@@ -85,67 +17,5 @@ if [ -z "${ELASTICSEARCH_HOSTS}" ];then
8517
exit 99;
8618
fi
8719

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
20+
# Finally call the original Docker-Entrypoint
21+
/usr/local/bin/docker-entrypoint -environment container "$@"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ services:
8080
- EXT_AUTHZ_URI=${EXT_AUTHZ_URI}
8181
- MANAGEMENT_KPIS_ENABLED=${MANAGEMENT_KPIS_ENABLED}
8282
- LOG_LEVEL=${API_BUILDER_LOG_LEVEL}
83+
- APM_ENABLED=${APM_ENABLED}
84+
- APM_SERVER=${APM_SERVER}
8385
ports:
8486
- 8443:8443
8587
networks:

env-sample

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,21 @@ ELASTIC_VERSION=7.15.2
502502
# is used by API Builder to pass application performance management data from the
503503
# API Builder process.
504504
# Used-By: Elastic-APM
505-
# Defaults to true
506-
#APM_ENABLED=false
505+
# Defaults to false
506+
#APM_ENABLED=true
507+
508+
# ----------------------------------------------------------------------------------------------
509+
# This is used by the API-Builder process for the APM-Server connection. It defaults to
510+
# http://apm-server:8200 if not configured, which is the service-name when using docker-compose.
511+
# Used-By: API-Builder4Elastic
512+
# APM_SERVER=http://my-apm-server:8200
513+
514+
# ----------------------------------------------------------------------------------------------
515+
# Account used by the APM-Server for the Elasticsearch communication. For the initial setup it
516+
# must have permissions to setup index templates.
517+
# Used-By: APM-Server
518+
#APM_USERNAME=elastic
519+
#APM_PASSWORD=
507520

508521
################################################################################################
509522
# Certificates and Certificate authorities

0 commit comments

Comments
 (0)