Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOKI to grab all logs from dockers #8

Merged
merged 63 commits into from
Dec 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
d8c6473
alpha
mjendza Oct 24, 2022
92ff590
missing command
mjendza Oct 24, 2022
de6b64d
try to make build green
mjendza Oct 24, 2022
4715955
maybe folder?
mjendza Oct 24, 2022
90b0d02
doc
mjendza Oct 25, 2022
0f165ae
at first build docker
mjendza Oct 25, 2022
78cac0b
maybe location was wrong
mjendza Oct 25, 2022
89be991
share network
mjendza Oct 25, 2022
9e4ab70
added to build
mjendza Oct 25, 2022
b95d0ed
fixed network
mjendza Oct 25, 2022
a7eb973
defined network as external
mjendza Oct 25, 2022
edb56d0
direct network shell create
mjendza Oct 25, 2022
d28a8eb
fixed network name
mjendza Oct 25, 2022
565233d
run sh file
mjendza Oct 25, 2022
014220a
try to fix
mjendza Oct 25, 2022
40d7bce
in work dir
mjendza Oct 25, 2022
9998bfc
try to run
mjendza Oct 25, 2022
5c1fb46
back to first version
mjendza Oct 26, 2022
747d7cc
HA config
mjendza Oct 26, 2022
be3b0ca
config for actions
mjendza Oct 26, 2022
137946d
fixed path
mjendza Oct 26, 2022
e4bc24b
improved flow
mjendza Oct 26, 2022
9908f11
location
mjendza Oct 26, 2022
6b76875
fixed config and tested on linux
mjendza Oct 26, 2022
74880ac
hacs
mjendza Oct 26, 2022
0087a49
hacs
mjendza Oct 26, 2022
90ac0f5
use tag version
mjendza Oct 26, 2022
dc1836e
doc
mjendza Oct 27, 2022
e4f79a6
alpha version
mjendza Oct 27, 2022
3fbae00
first
mjendza Oct 28, 2022
21ad93d
Merge remote-tracking branch 'origin/feature/sso' into feature/sso
mjendza Oct 28, 2022
75511d7
alpha-works
mjendza Oct 29, 2022
8e19ef7
some changes - still can't login
mjendza Oct 30, 2022
ca0f476
azure AD app
mjendza Oct 31, 2022
06641da
facebook configuration
mjendza Nov 1, 2022
16e9eff
alpha version works!!!
mjendza Nov 1, 2022
4012766
Merge branch 'main' into feature/sso
mjendza Nov 1, 2022
5e8bbb1
first version for nginx proxy
mjendza Nov 1, 2022
e2ec1ae
Merge branch 'feature/sso' of github.com:mjendza/SmartHome into featu…
mjendza Nov 1, 2022
3b4f4d3
doens't work - ban from HA
mjendza Nov 1, 2022
a8deb3c
next not working version
mjendza Nov 4, 2022
49ca535
from doc sample
mjendza Nov 4, 2022
378da65
all in
mjendza Nov 13, 2022
46244b6
started working on oauth proxy after sandbox tests
mjendza Nov 28, 2022
69b47ee
fixed configuration
mjendza Nov 28, 2022
814ea6b
X-Forwarded-For not needed now
mjendza Nov 28, 2022
21d0118
Merge branch 'main' into feature/sso-nginx-from-doc
mjendza Nov 28, 2022
370a571
updated doc
mjendza Dec 4, 2022
ff97bb4
updated scripts
mjendza Dec 4, 2022
a9a1a45
Merge branch 'feature/sso-nginx-from-doc' of github.com:mjendza/Smart…
mjendza Dec 4, 2022
448c3b0
updated doc
mjendza Dec 4, 2022
ceaca60
fix
mjendza Dec 4, 2022
e1dfca3
Merge branch 'feature/sso-nginx-from-doc' of github.com:mjendza/Smart…
mjendza Dec 4, 2022
a44b634
this is not part of the feature
mjendza Dec 4, 2022
5f3ae3d
HA config
mjendza Dec 4, 2022
8b2a370
fixed loki + tested prometheus with HA
mjendza Dec 18, 2022
c1f1eca
Merge branch 'main' into feature/ha/monitoring
mjendza Dec 18, 2022
8656fb4
next version
mjendza Dec 18, 2022
a707eb5
fixed coping HA config to runtime
mjendza Dec 18, 2022
076f34d
fixed and last state
mjendza Dec 18, 2022
1a91bf3
documentation
mjendza Dec 18, 2022
41f8337
updated doc2
mjendza Dec 18, 2022
5c87a34
don't want to publish my dev token
mjendza Dec 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

docker/management/.env.dev

docker/home-assistant/.env.dev
*.dev
dist/
dest/
*.dev
*.pem
*.secret
.idea/workspace.xml
.idea/workspace.xml
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"*.yaml": "home-assistant"
}
}
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ A tutorial how to build smart home from scratch. Still PoC.

| Decision | Rationale | Status |
|--------------------|------------------------------------------------------------------------------------|----------------------------------------------------|
| big-picture | Want to track vision of the system with big picture. | TBD |
| hosting/deployment | Want to host applications with docker - defined with docker compose. | (PR3)[https://github.com/mjendza/SmartHome/pull/3] |
| development | Verify development first. Need to use github actions to check it can use solution. | (PR4)[https://github.com/mjendza/SmartHome/pull/4] |
| big-picture | Want to track vision of the system with big picture. | TBD |
| hosting/deployment | Want to host applications with docker - defined with docker compose. | (PR3)[https://github.com/mjendza/SmartHome/pull/3] |
| development | Verify development first. Need to use github actions to check it can use solution. | (PR4)[https://github.com/mjendza/SmartHome/pull/4] |
| SingleSingOn - homeassistant | enable SingleSingOn for HomeAssistant | (PR7)[https://github.com/mjendza/SmartHome/pull/7] |
| observability - logs | Push all logs to the one place to improve observability for the solution. | (PR8)[https://github.com/mjendza/SmartHome/pull/8] |

# requirements
- SSH development with VS Code
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## requirements
- push all logs to the one place to improve observability for the solution

### docker
Push logs via loki driver inside docker-compose
```
x-logging: &loki-logging
driver: loki
options: # note: the ip is the ip we will assign later to loki in this file
loki-url: "https://localhost:3100/loki/api/v1/push"
```
sample serivce
```
services:
homeassistant:
container_name: home-assistant
restart: always
image: homeassistant/home-assistant:2022.10.5
ports:
- 8123:8123
environment:
- TZ=${TZ}
logging: *loki-logging
```
10 changes: 8 additions & 2 deletions docker/home-assistant/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
version: '3.4'
x-logging: &loki-logging
driver: loki
options: # note: the ip is the ip we will assign later to loki in this file
loki-url: "https://localhost:3100/loki/api/v1/push"

services:
homeassistant:
Expand All @@ -15,7 +19,7 @@ services:
- 8123:8123
environment:
- TZ=${TZ}

logging: *loki-logging
auth-proxy:
# can base on https://github.com/grafana/grafana/issues/52681
# https://developer.okta.com/blog/2022/07/14/add-auth-to-any-app-with-oauth2-proxy
Expand Down Expand Up @@ -56,7 +60,7 @@ services:
- OAUTH2_PROXY_AUTH_LOGGING=true
- OAUTH2_PROXY_REQUEST_LOGGING=true
- OAUTH2_PROXY_ERRORS_TO_INFO_LOG=true
logging: *loki-logging
proxy-server:
image: nginx:1.19
container_name: proxy-server
Expand All @@ -69,13 +73,15 @@ services:
- ./nginx-config/key.pem.secret:/etc/nginx/ssl/key.pem:ro
- ./nginx-config/passw.secret:/etc/nginx/ssl/passw:ro
- ./nginx-config/nginx.conf:/etc/nginx/conf.d/default.conf
logging: *loki-logging
# certbot:
# image: certbot/certbot:latest
# volumes:
# - ${USERDIR}/certbot/www/:/var/www/certbot/:rw
# - ${USERDIR}/certbot/conf/:/etc/letsencrypt/:rw



networks:
default:
external:
Expand Down
10 changes: 5 additions & 5 deletions docker/home-assistant/home-assistant-run.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
docker-compose stop
#docker-compose stop

mkdir -p ../../dist
mkdir -p ../../dist/ha
mkdir -p ../../dist/ha/config
# mkdir -p ../../dist
# mkdir -p ../../dist/ha
# mkdir -p ../../dist/ha/config

cp -a ../../home-assistant-configuration/ ../../dist/ha/config/
# cp -a ../../home-assistant-configuration/. ../../dist/ha/config/

docker-compose -f docker-compose.yaml -f docker-compose.dev.override.yaml --env-file .env.dev up --detach --force-recreate
9 changes: 9 additions & 0 deletions docker/home-assistant/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# dev environment
## VS Code
- https://marketplace.visualstudio.com/items?itemName=keesschollaart.vscode-home-assistant
-


# setup
## publish metrics to prometheus
- https://www.home-assistant.io/docs/authentication/ generate Long-Lived Access Token - via user profile
5 changes: 5 additions & 0 deletions docker/management/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
version: '3.7'
x-logging: &loki-logging
driver: loki
options: # note: the ip is the ip we will assign later to loki in this file
loki-url: "https://localhost:3100/loki/api/v1/push"

services:
portainer:
Expand All @@ -13,6 +17,7 @@ services:
- "9000:9000"
environment:
- TZ=${TZ}
logging: *loki-logging
networks:
default:
external:
Expand Down
5 changes: 5 additions & 0 deletions docker/observability/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HA_LONGLIVED_TOKEN=JWT TOKEN
USERDIR=../../dist
HOST_PORT_PREFIX=
ENV_NAME_PREFIX=dev
ENV_NETWORK_NAME_PREFIX=iot
41 changes: 30 additions & 11 deletions docker/observability/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
version: '3.7'
version: '3.4'
x-logging: &loki-logging
driver: loki
options: # note: the ip is the ip we will assign later to loki in this file
loki-url: "https://localhost:3100/loki/api/v1/push"


networks:
default:
external:
name: iot-smart-network

name: ${ENV_NETWORK_NAME_PREFIX}-smart-network
services:
prometheus:
image: prom/prometheus:v2.36.2
container_name: prometheus
container_name: ${ENV_NAME_PREFIX}-prometheus
volumes:
- ./prometheus/:/etc/prometheus/
- ${USERDIR}/prometheus_data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--log.level=debug'
- '--storage.tsdb.path=/prometheus'
- '--web.console.libraries=/usr/share/prometheus/console_libraries'
- '--web.console.templates=/usr/share/prometheus/consoles'
Expand All @@ -25,11 +31,12 @@ services:
- alertmanager:alertmanager
depends_on:
- cadvisor
- loki
restart: always

logging: *loki-logging
node-exporter:
image: quay.io/prometheus/node-exporter:latest
container_name: node-exporter
container_name: ${ENV_NAME_PREFIX}-node-exporter
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
Expand All @@ -45,10 +52,9 @@ services:
ports:
- ${HOST_PORT_PREFIX}9100:9100
restart: always

alertmanager:
image: prom/alertmanager
container_name: alertmanager
container_name: ${ENV_NAME_PREFIX}-alertmanager
ports:
- ${HOST_PORT_PREFIX}9093:9093
volumes:
Expand All @@ -61,9 +67,10 @@ services:
# placement:
# constraints:
# - node.hostname == ${HOSTNAME}

cadvisor:
image: gcr.io/cadvisor/cadvisor
container_name: cadvisor
container_name: ${ENV_NAME_PREFIX}-cadvisor
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
Expand All @@ -72,10 +79,9 @@ services:
ports:
- ${HOST_PORT_PREFIX}8080:8080
restart: always

grafana:
image: grafana/grafana
container_name: grafana
container_name: ${ENV_NAME_PREFIX}-grafana
user: "0:0"
depends_on:
- prometheus
Expand All @@ -87,3 +93,16 @@ services:
env_file:
- ./grafana/config.monitoring
restart: always
logging: *loki-logging
loki:
container_name: ${ENV_NAME_PREFIX}-loki
image: grafana/loki:2.3.0
restart: unless-stopped
ports:
- ${HOST_PORT_PREFIX}3100:3100
volumes:
- ./loki/config/loki-config.yaml:/etc/loki/loki-config.yaml
- ${USERDIR}/loki/data:/data/loki
- ${USERDIR}/loki/data:/loki
command: -config.file=/etc/loki/loki-config.yaml

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ datasources:
# <int> org id. will default to orgId 1 if not specified
orgId: 1
# <string> url
url: https://prometheus:9090
url: https://dev-prometheus:9090
# <string> database password, if used
password:
# <string> database user, if used
Expand Down Expand Up @@ -48,3 +48,8 @@ datasources:
version: 1
# <bool> allow users to edit datasources from the UI.
editable: true

- name: Loki
type: loki
url: https://dev-loki:3100
isDefault: false
37 changes: 37 additions & 0 deletions docker/observability/loki/config/loki-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
auth_enabled: false

server:
http_listen_port: 3100

ingester:
lifecycler:
address: 127.0.0.1
ring:
kvstore:
store: inmemory
replication_factor: 1
final_sleep: 0s
chunk_idle_period: 5m
chunk_retain_period: 30s

schema_config:
configs:
- from: 2020-05-15
store: boltdb
object_store: filesystem
schema: v11
index:
prefix: index_
period: 168h

storage_config:
boltdb:
directory: /tmp/loki/index

filesystem:
directory: /tmp/loki/chunks

limits_config:
enforce_metric_name: false
reject_old_samples: true
reject_old_samples_max_age: 168h
17 changes: 12 additions & 5 deletions docker/observability/prometheus/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ alerting:
- scheme: http
static_configs:
- targets:
- "alertmanager:9093"
- "dev-alertmanager:9093"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
Expand All @@ -43,15 +43,22 @@ scrape_configs:
scrape_interval: 15s

static_configs:
- targets: ['cadvisor:8080']
- targets: ['dev-cadvisor:8080']

- job_name: 'node-exporter'

# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 15s

static_configs:
- targets: ['node-exporter:9100']
- targets: ['dev-node-exporter:9100']
# home assistant
- job_name: "hass"
scrape_interval: 15s
metrics_path: /api/prometheus
# Long-Lived Access Token
bearer_token: 'REPLACE_ME'
scheme: http
static_configs:
- targets: ['dev-home-assistant:8123']

# - job_name: 'pushgateway'
# scrape_interval: 10s
Expand Down
12 changes: 12 additions & 0 deletions docker/observability/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# troubleshooting
## docker
### loki loggs
#### don't see logs in locki
##### check if plugin to push docker instance logs to loki
```
/var/log$ tail -n 100 syslog
```

```
grep plugin= syslog
```
1 change: 1 addition & 0 deletions docker/observability/run-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose -p "dev-observability" -f docker-compose.yaml --env-file .env.dev up --detach --force-recreate
1 change: 1 addition & 0 deletions docker/observability/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docker-compose -p "test-observability" -f docker-compose.yaml --env-file .env.test.dev up --detach --force-recreate
23 changes: 23 additions & 0 deletions docker/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# requirements
## docker
### loki plugin
```
docker plugin install grafana/loki-docker-driver:latest --alias loki --grant-all-permissions
```
### shared network
```
docker network create \
--driver=bridge \
--subnet=172.23.0.0/16 \
--ip-range=172.23.0.0/16 \
--gateway=172.23.0.1 \
iot-smart-network
```
```
docker network create \
--driver=bridge \
--subnet=172.55.0.0/16 \
--ip-range=172.55.0.0/16 \
--gateway=172.55.0.1 \
test-smart-network
```
Loading