diff --git a/Dockerfile b/Dockerfile index 11d4fed..91391cb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,8 +62,10 @@ COPY --from=build-image /opt /opt ENV PATH="/virtualenv/bin:$PATH" ENV VIRTUAL_ENV="/virtualenv" ENV LD_LIBRARY_PATH="/opt/oracle/instantclient" +# IPv6 support is not enabled by default, only bind IPv4 +ENV QE_HOST="0.0.0.0" EXPOSE 9560/tcp VOLUME /config -# IPv6 support is not enabled by default, only bind IPv4 -ENTRYPOINT ["query-exporter", "/config/config.yaml", "-H", "0.0.0.0"] +WORKDIR /config +ENTRYPOINT ["query-exporter"] diff --git a/README.rst b/README.rst index 91092f2..43fff69 100644 --- a/README.rst +++ b/README.rst @@ -15,10 +15,13 @@ Each query can be run on multiple databases, and update multiple metrics. The application is simply run as:: - query-exporter config.yaml + query-exporter -where the passed configuration file contains the definitions of the databases -to connect and queries to perform to update metrics. +which will look for a ``config.yaml`` configuration file in the current +directory, containing the definitions of the databases to connect and queries +to perform to update metrics. The configuration file can be overridden by +passing the ``--config`` option, or setting the ``QE_CONFIG`` environment +variable. Configuration file format @@ -502,8 +505,9 @@ included by passing ``--process-stats`` in the command line. Debugging / Logs ---------------- -You can enable extended logging using the ``-L`` commandline switch. Possible -log levels are ``CRITICAL``, ``ERROR``, ``WARNING``, ``INFO``, ``DEBUG``. +You can enable extended logging using the ``-L`` (or ``-log-level``) command +line switch. Possible log levels are ``critical``, ``error``, ``warning``, +``info``, ``debug``. Database engines @@ -537,6 +541,8 @@ To configure the daemon: - create or edit ``/var/snap/query-exporter/current/config.yaml`` with the configuration +- optionally, create a ``/var/snap/query-exporter/current/.env`` file with + environment variables definitions for additional config options - run ``sudo snap restart query-exporter`` The snap has support for connecting the following databases: @@ -561,12 +567,10 @@ where ``$CONFIG_DIR`` is the absolute path of a directory containing a ``config.yaml`` file, the configuration file to use. Alternatively, a volume name can be specified. - -A different ODBC driver version to use can be specified during image building, -by passing ``--build-arg ODBC_bVERSION_NUMBER``, e.g.:: - - docker build . --build-arg ODBC_DRIVER_VERSION=17 - +If, a ``.env`` file is present in the specified volume for ``/config``, its +content is loaded and applied to the environment for the exporter. The location +of the dotenv file can be customized by setting the ``QE_DOTENV`` environment +variable. The image has support for connecting the following databases: @@ -580,6 +584,14 @@ The image has support for connecting the following databases: A `Helm chart`_ to run the container in Kubernetes is also available. +ODBC driver version +~~~~~~~~~~~~~~~~~~~ + +A different ODBC driver version to use can be specified during image building, +by passing ``--build-arg ODBC_bVERSION_NUMBER``, e.g.:: + + docker build . --build-arg ODBC_DRIVER_VERSION=17 + .. _Prometheus: https://prometheus.io/ .. _SQLAlchemy: https://www.sqlalchemy.org/ diff --git a/snap/local/daemon.sh b/snap/local/daemon.sh index 1afb69d..8ad5767 100755 --- a/snap/local/daemon.sh +++ b/snap/local/daemon.sh @@ -1,7 +1,5 @@ #!/bin/sh -e -CONFIG_FILE="$SNAP_DATA/config.yaml" +[ -r "$SNAP_DATA/config.yaml" ] || snapctl stop "$SNAP_INSTANCE_NAME" -[ -r "$CONFIG_FILE" ] || snapctl stop "$SNAP_INSTANCE_NAME" - -exec "$SNAP/bin/query-exporter" -H 0.0.0.0 :: -- "$CONFIG_FILE" +exec env -C "$SNAP_DATA" "$SNAP/bin/query-exporter" -- diff --git a/snap/local/query-exporter.completion b/snap/local/query-exporter.completion deleted file mode 100644 index 6b5575a..0000000 --- a/snap/local/query-exporter.completion +++ /dev/null @@ -1,32 +0,0 @@ - -# Run something, muting output or redirecting it to the debug stream -# depending on the value of _ARC_DEBUG. -__python_argcomplete_run() { - if [[ -z "$_ARC_DEBUG" ]]; then - "$@" 8>&1 9>&2 1>/dev/null 2>&1 - else - "$@" 8>&1 9>&2 1>&9 2>&1 - fi -} - -_python_argcomplete() { - local IFS=$'\013' - local SUPPRESS_SPACE=0 - if compopt +o nospace 2> /dev/null; then - SUPPRESS_SPACE=1 - fi - COMPREPLY=( $(IFS="$IFS" \ - COMP_LINE="$COMP_LINE" \ - COMP_POINT="$COMP_POINT" \ - COMP_TYPE="$COMP_TYPE" \ - _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" \ - _ARGCOMPLETE=1 \ - _ARGCOMPLETE_SUPPRESS_SPACE=$SUPPRESS_SPACE \ - __python_argcomplete_run "$1") ) - if [[ $? != 0 ]]; then - unset COMPREPLY - elif [[ $SUPPRESS_SPACE == 1 ]] && [[ "$COMPREPLY" =~ [=/:]$ ]]; then - compopt -o nospace - fi -} -complete -o nospace -o default -o bashdefault -F _python_argcomplete query-exporter diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 1de6703..80b4b29 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -14,6 +14,8 @@ description: | - create or edit `/var/snap/query-exporter/current/config.yaml` with the configuration + - optionally, create a `/var/snap/query-exporter/current/.env` file with + environment variables definitions for additional config options - run `sudo snap restart query-exporter` Currently supported databases are: @@ -83,12 +85,16 @@ parts: - libodbc2 - libpq5 - libxml2 + override-build: | + craftctl default + _QUERY_EXPORTER_COMPLETE=bash_source query-exporter > "$CRAFT_PART_INSTALL/query-exporter.completion" prime: - bin/python3 - bin/query-exporter - etc - lib - pyvenv.cfg + - query-exporter.completion - usr/lib wrappers: