Skip to content

Commit 0cbee6c

Browse files
committed
Add and move around build scripts
1 parent a188ba9 commit 0cbee6c

File tree

17 files changed

+263
-33
lines changed

17 files changed

+263
-33
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
Newest updates are at the top of this file.
33

4+
### Aug 10 2020
5+
* Update to use v5.1.1 of the mq-golang repository
6+
* Moved build shell commands to `scripts` subdirectory and added README there
7+
* Add a Windows batch file as example of building locally
8+
49
### Jul 23 2020
510
* Update to use v5.1.0 of the mq-golang repository
611
* Update to use MQ 9.2.0

Dockerfile renamed to Dockerfile.build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ RUN cd /opt/mqm \
6161
&& rm -f ./*.tar.gz
6262

6363
# Insert the script that will do the build
64-
COPY buildInDocker.sh $GOPATH
64+
COPY scripts/buildInDocker.sh $GOPATH
6565
RUN chmod 777 $GOPATH/buildInDocker.sh
6666

6767
WORKDIR $GOPATH/src/$ORG/$REPO
68-
COPY go.mod .
69-
COPY go.sum .
68+
COPY go.mod .
69+
COPY go.sum .
7070
RUN chmod 777 go.*
7171

7272
COPY config.common.yaml .

Dockerfile.run

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# © Copyright IBM Corporation 2020
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
ARG BASE_IMAGE=ubuntu:19.10
16+
FROM $BASE_IMAGE
17+
18+
# Create location for the git clone and MQ installation
19+
RUN mkdir -p /opt/bin \
20+
&& chmod -R 777 /opt/bin \
21+
&& mkdir -p /opt/mqm \
22+
&& chmod a+rx /opt/mqm \
23+
&& mkdir -p /opt/config \
24+
&& chmod a+rx /opt/config
25+
26+
# Install curl
27+
RUN apt-get update \
28+
&& apt-get install -y curl bash ca-certificates \
29+
&& rm -rf /var/lib/apt/lists/*
30+
31+
# Location of the downloadable MQ client package \
32+
ENV RDURL="https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/messaging/mqdev/redist" \
33+
RDTAR="IBM-MQC-Redist-LinuxX64.tar.gz" \
34+
VRMF=9.2.0.0
35+
36+
# Install the MQ client from the Redistributable package. This also contains the
37+
# header files we need to compile against.
38+
RUN cd /opt/mqm \
39+
&& curl -LO "$RDURL/$VRMF-$RDTAR" \
40+
&& tar -zxf ./*.tar.gz \
41+
&& rm -f ./*.tar.gz
42+
43+
ENV LD_LIBRARY_PATH="/opt/mqm/lib64:/usr/lib64" \
44+
MQ_CONNECT_TYPE=CLIENT
45+
46+
ARG MONITOR_ARG="mq_prometheus"
47+
ENV MONITOR=$MONITOR_ARG
48+
RUN echo "Building container for $MONITOR"
49+
50+
# Copy over the binary file, which is in the same directory as this one
51+
COPY $MONITOR /opt/bin/$MONITOR
52+
53+
# The configuration file should be mounted from the host into the /opt/config directory.
54+
CMD /opt/bin/$MONITOR -f /opt/config/$MONITOR.yaml -log.level=info

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ file if you wish to reload all of the dependencies by running `go mod vendor`.
2424

2525
You will require the following programs:
2626

27-
* Go compiler. This should be at least version 12. If you see an error similar to "ld: NULL not defined"
28-
then it is likely you need to upgrade your compiler.
27+
* Go compiler. This should be at least version 13.
2928

3029
To build the programs on Linux and MacOS, you may set an environment variable to permit some compile/link flags.
3130
This is due to security controls in the compiler.
@@ -69,11 +68,16 @@ monitor agent directory also has sample scripts, configuration files etc to help
6968
with getting the agent running in your specific environment.
7069

7170
## Using a Docker container to build the programs
72-
You can use the `buildMonitors.sh` script in this directory to build a Docker container that
71+
You can use the `buildMonitors.sh` script in the `scripts` subdirectory to build a Docker container that
7372
in turn will build all the binary programs and copy them to a local directory. That script also
7473
sets some extra version-related flags that will be shown when the program starts. The container will
7574
automatically download and install the MQ client runtime files needed for compilation.
7675

76+
## Building on Windows
77+
There is a `buildMonitors.bat` file that may help with building on Windows. It assumes you have
78+
the [tdm-gcc-64](https://jmeubank.github.io/tdm-gcc/download/) 64-bit compiler suite installed. It
79+
builds all the collectors and corresponding YAML configuration files into %GOPATH%/bin
80+
7781
## Monitor configuration
7882
The monitors always collect all of the available queue manager-wide metrics.
7983
They can also be configured to collect statistics for specific sets of queues where
@@ -154,7 +158,7 @@ table combines multiple metrics on the same line now.
154158

155159
Information about channels comes from the DISPLAY CHSTATUS CURRENT command. That
156160
only shows channels with a known state and does not report on inactive channels.
157-
To also see the inactive channels, then set the showInactiveChannels
161+
To also see the inactive channels, then set the showInactiveChannels
158162
configuration attribute to true.
159163

160164
### z/OS Support
@@ -203,7 +207,7 @@ point at the file.
203207
All of the exporters support
204208
the same configuration options for how to connect to MQ and which objects are monitored. There is
205209
then an exporter-specific section for additional configuration such as how to contact the back-end
206-
database.
210+
database.
207211
The common options are shown in a template in this directory; the exporter-specific options are in individual files in each directory. Combine the two pieces into a single file to get a complete deployable configuration.
208212

209213
Unlike the command line flags, lists are provided in a more natural format instead of comma-separated

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.13
44

55
require (
66
github.com/aws/aws-sdk-go v1.30.18
7-
github.com/ibm-messaging/mq-golang/v5 v5.1.0
7+
github.com/ibm-messaging/mq-golang/v5 v5.1.1
88
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d
99
github.com/prometheus/client_golang v1.6.0
1010
github.com/sirupsen/logrus v1.5.0

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ github.com/ibm-messaging/mq-golang/v5 v5.0.0 h1:9J8bsDoCo60rbSgB7ZAURPG3L5Kpr+F8
4242
github.com/ibm-messaging/mq-golang/v5 v5.0.0/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
4343
github.com/ibm-messaging/mq-golang/v5 v5.1.0 h1:fWTWSV9uBv847rVQqGPRGGCQr61FJR7eSxM5RJMa3NQ=
4444
github.com/ibm-messaging/mq-golang/v5 v5.1.0/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
45+
github.com/ibm-messaging/mq-golang/v5 v5.1.1 h1:rXlyYWyG4paNImj7cDXJsxJHONcI1nhD6XBiebDsoeQ=
46+
github.com/ibm-messaging/mq-golang/v5 v5.1.1/go.mod h1:ywCwmYbJOU/E0rl+z4GiNoxVMty68O+LVO39a1VMXrE=
4547
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d h1:/WZQPMZNsjZ7IlCpsLGdQBINg5bxKQ1K1sh6awxLtkA=
4648
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo=
4749
github.com/jmespath/go-jmespath v0.3.0 h1:OS12ieG61fsCg5+qLJ+SsW9NicxNkg3b25OyT2yCeUc=

scripts/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This directory contains scripts as examples of building and running
2+
the various collector programs. The files are:
3+
4+
* `buildMonitors.sh`: Creates a container and uses it as the build environment
5+
to build all the collectors. Output goes to a real local directory, `$HOME/tmp/mq-metric-samples`
6+
which holds the binaries, the default YAML configuration files and MQSC scripts that can be
7+
used to run the collectors as MQ Services.
8+
9+
* `buildInDocker.sh`: Used inside the container created by the previous script. It downloads the
10+
MQ Redistributable Client needed for compiling the packages, and then does the `go build`
11+
operations.
12+
13+
* `buildRuntime.sh`: Create a container that holds the runtime for a particular collector. By
14+
default, build containers for all collectors, but can give a command line list to explicitly ask
15+
for a subset. For example, `buildRuntime.sh mq_prometheus mq_json`. The container is tagged, ready to run.
16+
17+
* `runMonitor.sh`: Execute one of the containers build in the previous step. The configuration file
18+
is mounted from the host image. This is the file you'll most likely want to change, to match your
19+
own setup. But it's a useful model to show how parameters can be passed.
20+
21+
* `buildMonitors.bat`: Example of building on Windows. It assumes you
22+
already have the MQ client package installed, and have a suitable `gcc`
23+
compiler available under c:\TDM-GCC-64. Output of the binaries and
24+
YAML files go into `%GOPATH%\bin`.
25+
26+
* `docker-compose.yaml`: A fragment of what might go into a larger composition file. In its current
27+
state it tries to pull an image from a repository even though it has been built and exists locally.
File renamed without changes.

scripts/buildMonitors.bat

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@echo off
2+
3+
rem Don't affect parent environment
4+
setlocal
5+
6+
rem Set a PATH to include a suitable gcc build
7+
set PATH=c:\tdm-gcc-64\bin;%PATH%
8+
9+
rem Go to the root of my Go tree
10+
rem Usually something like c:\Gowork
11+
cd %GOPATH%
12+
13+
rem And set references to the commands that have been git cloned under it
14+
set R=src\github.com\ibm-messaging\mq-metric-samples
15+
set D=%R%\cmd
16+
17+
rem Make sure the correct size is going to be used - The invoked gcc may not set it
18+
set CGO_CFLAGS=-D_WIN64
19+
20+
rem Do the builds - since we can't always use *.go, then name the files explicitly
21+
rem Some have slightly different sets of files
22+
for %%M in (mq_prometheus mq_json mq_coll mq_influx) do (
23+
echo Building %%M
24+
go build -o bin/%%M.exe %D%\%%M\config.go %D%\%%M\main.go %D%\%%M\exporter.go
25+
type %R%\config.common.yaml %D%\%%M\config.collector.yaml > bin\%%M.yaml 2>NUL:
26+
)
27+
28+
for %%M in (mq_aws mq_opentsdb) do (
29+
echo Building %%M
30+
go build -o bin/%%M.exe %D%\%%M\config.go %D%\%%M\main.go %D%\%%M\exporter.go %D%\%%M\points.go
31+
type %R%\config.common.yaml %D%\%%M\config.collector.yaml > bin\%%M.yaml 2>NUL:
32+
)
33+
34+
endlocal

buildMonitors.sh renamed to scripts/buildMonitors.sh

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,25 @@
1717
# to compile the binary components of the monitoring programs, and then to copy those
1818
# programs to a local temporary directory.
1919

20-
function latestSemVer {
21-
(for x in $*
22-
do
23-
echo $x | sed "s/^v//g"
24-
done) | sort -n | tail -1
25-
}
20+
. ./common.sh
2621

2722
GOPATH="/go"
28-
2923
TAG="mq-metric-samples-gobuild"
30-
# Assume repo tags have been created in a sensible order. Find the mq-golang
31-
# version in the dep file (it's the only dependency explicitly listed for now)
32-
# and the current Git tag for this repo. Then pick the latest version to create
33-
# the Docker tag
34-
VERDEP=`cat go.mod | awk '/mq-golang/ {print $2}' `
35-
VERREPO=`git tag -l | sort | tail -1 `
3624

37-
VER=`latestSemVer $VERDEP $VERREPO`
38-
if [ -z "$VER" ]
39-
then
40-
VER="latest"
41-
fi
42-
# echo "VERDEP=$VERDEP VERREPO=$VERREPO"
4325
echo "Building container $TAG:$VER"
4426

4527
# Set the userid we will run the container as
4628
uid=`id -u`
4729
gid=`id -g`
4830

4931
# Build a container that has all the pieces needed to compile the Go programs for MQ
50-
docker build --build-arg GOPATH_ARG=$GOPATH -t $TAG:$VER .
32+
docker build --build-arg GOPATH_ARG=$GOPATH -f Dockerfile.build -t $TAG:$VER .
5133
rc=$?
5234

5335
if [ $rc -eq 0 ]
5436
then
5537
# Run the image to do the compilation and extract the files
5638
# from it into a local directory mounted into the container.
57-
OUTDIR=$HOME/tmp/mq-metric-samples/bin
5839
rm -rf $OUTDIR
5940
mkdir -p $OUTDIR
6041

0 commit comments

Comments
 (0)