adding node exporter, loki, and promtail

This commit is contained in:
ai-dev
2024-10-30 20:26:28 +01:00
parent b1dbbe1a8b
commit b840c65795
87 changed files with 2372 additions and 2366 deletions

View File

@ -0,0 +1,52 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Loki
# This file configures nginx
# ==============================================================================
readonly NGINX_SERVERS=/etc/nginx/servers
readonly NGINX_CONF="${NGINX_SERVERS}/direct.conf"
declare certfile
declare keyfile
bashio::config.require.ssl
if bashio::config.true 'ssl'; then
bashio::log.info 'Setting up SSL...'
certfile=$(bashio::config 'certfile')
keyfile=$(bashio::config 'keyfile')
if ! bashio::config.is_empty 'cafile'; then
bashio::log.info 'Setting up mTLS...'
cafile=$(bashio::config 'cafile')
# Absolute path support deprecated 4/21 for release 1.5.0.
# Wait until at least 5/21 to remove
if [[ $cafile =~ ^\/ ]]; then
bashio::log.warning "Providing an absolute path for 'cafile' is deprecated."
bashio::log.warning "Support for absolute paths will be removed in a future release."
bashio::log.warning "Please put your CA file in /ssl and provide a relative path."
else
cafile="/ssl/${cafile}"
fi
if ! bashio::fs.file_exists "${cafile}"; then
bashio::log.fatal
bashio::log.fatal "The file specified for 'cafile' does not exist!"
bashio::log.fatal "Ensure the CA certificate file exists and full path is provided"
bashio::log.fatal
bashio::exit.nok
fi
mv "${NGINX_SERVERS}/direct-mtls.disabled" "${NGINX_CONF}"
sed -i "s#%%cafile%%#${cafile}#g" "${NGINX_CONF}"
else
mv "${NGINX_SERVERS}/direct-ssl.disabled" "${NGINX_CONF}"
fi
sed -i "s#%%certfile%%#${certfile}#g" "${NGINX_CONF}"
sed -i "s#%%keyfile%%#${keyfile}#g" "${NGINX_CONF}"
else
mv "${NGINX_SERVERS}/direct.disabled" "${NGINX_CONF}"
fi

View File

@ -0,0 +1,52 @@
---
auth_enabled: false
server: {}
ingester:
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 1h
max_chunk_age: 1h
chunk_target_size: 1048576
chunk_retain_period: 30s
max_transfer_retries: 0
wal:
dir: /data/loki/wal
schema_config:
configs:
- from: 2020-10-24
store: boltdb-shipper
object_store: filesystem
schema: v11
index:
prefix: index_
period: 24h
storage_config:
boltdb_shipper:
active_index_directory: /data/loki/boltdb-shipper-active
cache_location: /data/loki/boltdb-shipper-cache
cache_ttl: 24h
shared_store: filesystem
filesystem:
directory: /data/loki/chunks
compactor:
working_directory: /data/loki/boltdb-shipper-compactor
shared_store: filesystem
retention_enabled: true
limits_config:
reject_old_samples: true
reject_old_samples_max_age: 168h
retention_period: ${RETENTION_PERIOD:29d}
chunk_store_config:
max_look_back_period: 0s

View File

@ -0,0 +1,96 @@
types {
text/html html htm shtml;
text/css css;
text/xml xml;
image/gif gif;
image/jpeg jpeg jpg;
application/javascript js;
application/atom+xml atom;
application/rss+xml rss;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/x-component htc;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico;
image/x-jng jng;
image/x-ms-bmp bmp;
font/woff woff;
font/woff2 woff2;
application/java-archive jar war ear;
application/json json;
application/mac-binhex40 hqx;
application/msword doc;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.apple.mpegurl m3u8;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/vnd.ms-excel xls;
application/vnd.ms-fontobject eot;
application/vnd.ms-powerpoint ppt;
application/vnd.oasis.opendocument.graphics odg;
application/vnd.oasis.opendocument.presentation odp;
application/vnd.oasis.opendocument.spreadsheet ods;
application/vnd.oasis.opendocument.text odt;
application/vnd.openxmlformats-officedocument.presentationml.presentation
pptx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
xlsx;
application/vnd.openxmlformats-officedocument.wordprocessingml.document
docx;
application/vnd.wap.wmlc wmlc;
application/x-7z-compressed 7z;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-xpinstall xpi;
application/xhtml+xml xhtml;
application/xspf+xml xspf;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
audio/midi mid midi kar;
audio/mpeg mp3;
audio/ogg ogg;
audio/x-m4a m4a;
audio/x-realaudio ra;
video/3gpp 3gpp 3gp;
video/mp2t ts;
video/mp4 mp4;
video/mpeg mpeg mpg;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-m4v m4v;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
}

View File

@ -0,0 +1,15 @@
proxy_http_version 1.1;
proxy_ignore_client_abort off;
proxy_read_timeout 86400s;
proxy_redirect off;
proxy_send_timeout 86400s;
proxy_max_temp_file_size 0;
proxy_set_header Accept-Encoding "";
proxy_set_header Connection $connection_upgrade;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header X-Real-IP $remote_addr;

View File

@ -0,0 +1,6 @@
root /dev/null;
server_name $hostname;
add_header X-Content-Type-Options nosniff;
add_header X-XSS-Protection "1; mode=block";
add_header X-Robots-Tag none;

View File

@ -0,0 +1,8 @@
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_session_timeout 10m;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;

View File

@ -0,0 +1,3 @@
upstream backend {
server 127.0.0.1:8080;
}

View File

@ -0,0 +1,52 @@
# Run nginx in foreground.
daemon off;
# Set user
user abc;
# Pid storage location.
pid /var/run/nginx.pid;
# Set number of worker processes.
worker_processes 1;
# Enables the use of JIT for regular expressions to speed-up their processing.
pcre_jit on;
# Write error log to the add-on log.
error_log /proc/1/fd/1 error;
# Load dynamic modules.
include /etc/nginx/modules/*.conf;
# Max num of simultaneous connections by a worker process.
events {
worker_connections 512;
}
http {
include /etc/nginx/includes/mime.types;
log_format homeassistant '[$time_local] $status '
'$http_x_forwarded_for($remote_addr) '
'$request ($http_user_agent)';
access_log off;
client_max_body_size 4G;
default_type application/octet-stream;
gzip on;
keepalive_timeout 65;
sendfile on;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
include /etc/nginx/includes/upstream.conf;
include /etc/nginx/servers/*.conf;
}

View File

@ -0,0 +1,17 @@
server {
listen 3100 default_server ssl;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/ssl_params.conf;
include /etc/nginx/includes/proxy_params.conf;
ssl_certificate /ssl/%%certfile%%;
ssl_certificate_key /ssl/%%keyfile%%;
ssl_client_certificate %%cafile%%;
ssl_verify_client on;
location / {
proxy_pass http://backend;
}
}

View File

@ -0,0 +1,14 @@
server {
listen 3100 default_server ssl;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/ssl_params.conf;
include /etc/nginx/includes/proxy_params.conf;
ssl_certificate /ssl/%%certfile%%;
ssl_certificate_key /ssl/%%keyfile%%;
location / {
proxy_pass http://backend;
}
}

View File

@ -0,0 +1,10 @@
server {
listen 3100 default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
location / {
proxy_pass http://backend;
}
}

View File

@ -0,0 +1,14 @@
server {
listen 3101 default_server;
include /etc/nginx/includes/server_params.conf;
include /etc/nginx/includes/proxy_params.conf;
location = /ready {
proxy_pass http://backend;
}
location / {
return 444;
}
}

View File

@ -0,0 +1,14 @@
#!/usr/bin/env bashio
# ==============================================================================
# Home Assistant Add-on: Loki
# Take down the S6 supervision tree when Loki fails
# ==============================================================================
declare APP_EXIT_CODE=${1}
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt
fi

View File

@ -0,0 +1,51 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Loki
# Runs Loki
# ==============================================================================
readonly BIND_ADDR=127.0.0.1
readonly HTTP_PORT=8080
declare log_level
loki_config='/etc/loki/default-config.yaml'
bashio::log.info 'Starting Loki...'
if bashio::config.exists 'config_path'; then
loki_config=$(bashio::config 'config_path')
bashio::log.info "Using config at ${loki_config}"
else
bashio::log.info "Using default config"
fi
retention_period="$(bashio::config 'days_to_keep' 1)d"
bashio::log.info "Retention period set to ${retention_period}"
export "RETENTION_PERIOD=${retention_period}"
case "$(bashio::config 'log_level')" in \
trace) ;& \
debug) log_level='debug' ;; \
notice) ;& \
warning) log_level='warn' ;; \
error) ;& \
fatal) log_level='error' ;; \
*) log_level='info' ;; \
esac;
bashio::log.info "Loki log level set to ${log_level}"
loki_args=(
"-config.expand-env=true"
"-config.file=${loki_config}"
"-server.http-listen-address=${BIND_ADDR}"
"-server.http-listen-port=${HTTP_PORT}"
"-log.level=${log_level}"
)
if [ "${log_level}" == "debug" ]; then
bashio::log.debug "Logging full config on startup for debugging..."
loki_args+=("-print-config-stderr=true")
fi
bashio::log.info "Handing over control to Loki..."
exec s6-setuidgid abc \
/usr/bin/loki "${loki_args[@]}"

View File

@ -0,0 +1,13 @@
#!/usr/bin/env bashio
# ==============================================================================
# Home Assistant Add-on: Loki
# Take down the S6 supervision tree when Nginx fails
# ==============================================================================
declare APP_EXIT_CODE=${1}
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt
fi

View File

@ -0,0 +1,10 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Loki
# Runs the Nginx daemon
# ==============================================================================
bashio::net.wait_for 8080
bashio::log.info "Starting NGinx..."
exec /usr/sbin/nginx