This commit is contained in:
Zakary Timson 2022-06-02 17:19:11 +00:00
commit ad9049ca18
4 changed files with 55 additions and 0 deletions

15
.gitlab/.gitlab-ci.yml Normal file
View File

@ -0,0 +1,15 @@
image: docker:latest
stages:
- publish
docker:
stage: publish
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
script:
- docker build --no-cache -t "$CI_REGISTRY_IMAGE:latest" -t ztimson/node-exporter:latest .
- docker push "$CI_REGISTRY_IMAGE:latest"
- docker push "ztimson/node-exporter:latest"
rules:
- if: $CI_COMMIT_BRANCH

7
Dockerfile Normal file
View File

@ -0,0 +1,7 @@
FROM prom/node-exporter:latest
COPY entrypoint.sh /etc/node-exporter/
RUN chmod +x /etc/node-exporter/entrypoint.sh
ENTRYPOINT [ "/etc/node-exporter/docker-entrypoint.sh" ]
CMD [ "/bin/node_exporter" ]

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Node-Exporter
This is a copy of [prom/node-exporter](https://hub.docker.com/r/prom/node-exporter) which also add's the hostname metric.
## Example
For the hostname to be detected, you must load the host filesystem into the container's `/host` directory as seen here.
```
version: '3.8'
services:
node-exporter:
image: ztimson/node-exporter:latest
command:
- --path.rootfs=/host
volumes:
- /:/host:ro,rslave
networks:
- network
deploy:
mode: global
```
Otherwise use the `$HOSTNAME` variable to specify the path to the *hostname file* & ensure it's mounted.

8
entrypoint.sh Normal file
View File

@ -0,0 +1,8 @@
#!/bin/sh
if [ -z "$HOSTNAME" ]; then $HOSTNAME="/host/hostname"; fi
NODE_NAME=$(cat "$HOSTNAME")
echo "node_meta{node_name=\"$NODE_NAME\"} 1" > /etc/node-exporter/node-meta.prom
set -- /bin/node_exporter "$@"
exec "$@"