Bunch of tweaks (#1)

* 🚑 Fix GitLab CI to have the right base images

* ✏️ Docs cleanup

* 👕 Dockerfile tweaks

* 🔥 Remove unused variable from proemetheus init

* 👕 Prettier on JSON & YAML files

* 👕 Other minor styling

* 🔥 Removal of disabled shellcheck rule

* 👕 Fix shellcheck linter warning

* ✏️ Small tweak to Python code

* 🔨 Reduce resulting image with 68Mb
This commit is contained in:
Franck Nijhof 2020-07-26 20:47:36 +02:00 committed by GitHub
parent 84b7286ef5
commit 5158849871
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 39 deletions

View file

@ -9,6 +9,6 @@ variables:
ADDON_ARMHF: "false"
ADDON_I386: "false"
ADDON_AARCH64_BASE: "hassioaddons/base-aarch64:3.2.1"
ADDON_AMD64_BASE: "hassioaddons/base-amd64:3.2.1"
ADDON_ARMV7_BASE: "hassioaddons/base-armv7:3.2.1"
ADDON_AARCH64_BASE: "hassioaddons/base-aarch64:8.0.1"
ADDON_AMD64_BASE: "hassioaddons/base-amd64:8.0.1"
ADDON_ARMV7_BASE: "hassioaddons/base-armv7:8.0.1"

View file

@ -104,8 +104,6 @@ SOFTWARE.
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg
[forum]: https://example.net
[mjrider]: https://github.com/mjrider
[github-sponsors-shield]: https://frenck.dev/wp-content/uploads/2019/12/github_sponsor.png
[github-sponsors]: https://github.com/sponsors/frenck
[gitlabci-shield]: https://gitlab.com/hassio-addons/addon-prometheus/badges/master/pipeline.svg
[gitlabci]: https://gitlab.com/hassio-addons/addon-prometheus/pipelines
[i386-shield]: https://img.shields.io/badge/i386-no-red.svg

View file

@ -36,17 +36,17 @@ static_configs:
**Note**: _This is just an example, don't copy and paste it! Create your own!_
The job names `home-assistant` and `prometheus` are already defined by default.
Rules can be created under /share/prometheus/rules/
Rules can be created under `/share/prometheus/rules/`
The addon will reload the configuration if a valid configuration is available. If not it will log errors in the addon log
The addon will reload the configuration if a valid configuration is available.
If not it will log errors in the addon log
## Known issues and limitations
* Job name must be unique, but this has to be enforced by the user.
* no alert manager yet
- Job name must be unique, but this has to be enforced by the user.
- no alert manager yet
## Changelog & Releases
@ -88,7 +88,7 @@ check [the contributor's page][contributors].
MIT License
Copyright (c) 2018-2020 Franck Nijhof
Copyright (c) 2020-2020 Robbert Müller
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View file

@ -16,12 +16,19 @@ RUN \
ARCH="${BUILD_ARCH}" \
&& if [ "${BUILD_ARCH}" = "aarch64" ]; then ARCH="arm64"; fi \
\
&& apk update \
&& apk --no-cache add python3 py3-idna py3-certifi py3-chardet py3-yaml py3-urllib3 py3-requests \
&& apk --no-cache add --virtual builddeps py-pip \
&& apk --no-cache add \
python3 \
py3-idna \
py3-certifi \
py3-chardet \
py3-yaml \
py3-urllib3 \
py3-requests \
&& apk --no-cache add --virtual .builddeps \
py-pip \
\
&& curl -J -L -o /tmp/prometheus.tar.gz \
https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}.tar.gz \
"https://github.com/prometheus/prometheus/releases/download/v${PROMETHEUS_VERSION}/prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}.tar.gz" \
&& adduser -s /bin/false -D -H prometheus \
&& cd /tmp \
&& tar -xvf /tmp/prometheus.tar.gz \
@ -32,8 +39,15 @@ RUN \
&& cp -R prometheus-${PROMETHEUS_VERSION}.linux-${ARCH}/consoles/ /etc/prometheus/ \
&& rm -r prometheus-${PROMETHEUS_VERSION}.linux-${ARCH} \
&& chown -R prometheus:prometheus /etc/prometheus \
&& pip3 install -r /opt/prometheus-configgen/requirements.txt \
&& apk del builddeps
&& pip3 install \
--no-cache-dir \
--prefer-binary \
--find-links "https://wheels.home-assistant.io/alpine-3.12/${BUILD_ARCH}/" \
-r /opt/prometheus-configgen/requirements.txt \
\
&& apk --no-cache del .builddeps \
&& rm -f -r \
/tmp/*
# Build arguments
ARG BUILD_DATE

View file

@ -16,14 +16,12 @@
"homeassistant_api": true,
"hassio_role": "default",
"map": ["share:rw"],
"options": {
},
"options": {},
"ports": {
"9090/tcp": null
},
"ports_description": {
"9090/tcp": "Not required for Ingress"
},
"schema": {
}
"schema": {}
}

View file

@ -3,7 +3,4 @@
# Home Assistant Community Add-on: Prometheus
# Configures Prometheus
# ==============================================================================
readonly CONFIG="/etc/prometheus/prometheus.yml"
echo "${HASSIO_TOKEN}" > '/run/home-assistant.token'

View file

@ -21,20 +21,20 @@ rule_files:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- job_name: 'home-assistant'
- targets: ["localhost:9090"]
- job_name: "home-assistant"
scrape_interval: 60s
metrics_path: /core/api/prometheus
# Long-Lived Access Token
bearer_token_file: '/run/home-assistant.token'
bearer_token_file: "/run/home-assistant.token"
scheme: http
static_configs:
- targets: ['supervisor:80']
- targets: ["supervisor:80"]

View file

@ -1,6 +1,4 @@
#!/usr/bin/with-contenv bashio
# shellcheck disable=SC2191
bashio::log.info 'Starting prometheus config generator...'
if [[ ! -d /share/promethus/targets ]] ; then
@ -8,7 +6,8 @@ if [[ ! -d /share/promethus/targets ]] ; then
chown -R prometheus:prometheus /share/prometheus/targets
fi
cd /opt/prometheus-configgen
cd /opt/prometheus-configgen || bashio::exit.nok \
"Could not change working directory for prometheus-configgen."
# Run Prometheus
exec s6-setuidgid prometheus python3 combiner

View file

@ -39,7 +39,7 @@ def testConfig(config):
except:
print("Failed to validate")
raise
if result == False:
if not result:
raise Exception("validation error")
return result
@ -51,7 +51,6 @@ def writeConfig(config, file):
r = requests.post(url="http://localhost:9090/-/reload", data={})
except:
print("Exception")
pass
loop = asyncio.get_event_loop()

View file

@ -35,4 +35,4 @@ rule_files:
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090']
- targets: ['localhost:9090']

View file

@ -1,5 +1,4 @@
PyYAML>=5.3.1
pyyaml-include>=1.2
requests>=2.23.0
aionotify
pyyaml-include>=1.2
PyYAML>=5.3.1
requests>=2.23.0