Compare commits
1 Commits
weather-st
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
265e30ea7d |
7
README.md
Normal file
7
README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Host visability
|
||||||
|
I would recommend using [this dashboard](https://grafana.com/grafana/dashboards/1860-node-exporter-full/).
|
||||||
|
|
||||||
|
Use `docker compose -f node.yml up` on the devices you are monitoring
|
||||||
|
|
||||||
|
Use `docker compose up` for the server that's collecting all the logs.
|
||||||
|
|
||||||
15
client/alloy-config.alloy
Normal file
15
client/alloy-config.alloy
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
local.file_match "caddy" {
|
||||||
|
path_targets = [{"__path__" = "/tmp/app-logs/debug.log"}]
|
||||||
|
sync_period = "5s"
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.write "remote_loki" {
|
||||||
|
endpoint {
|
||||||
|
url = "http://10.50.50.x/loki/api/v1/push"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.source.file "local_files" {
|
||||||
|
targets = local.file_match.caddy.targets
|
||||||
|
forward_to = [loki.write.local.loki.reciever]
|
||||||
|
}
|
||||||
20
client/compose.yml
Normal file
20
client/compose.yml
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
services:
|
||||||
|
# monitor the host
|
||||||
|
node_exporter:
|
||||||
|
image: quay.io/prometheus/node-exporter:latest
|
||||||
|
command:
|
||||||
|
- '--path.rootfs=/host'
|
||||||
|
network_mode: host
|
||||||
|
# uses port 9100
|
||||||
|
pid: host
|
||||||
|
restart: unless-stopped
|
||||||
|
volumes:
|
||||||
|
- '/:/host:ro'
|
||||||
|
alloy:
|
||||||
|
image: grafana/alloy:latest
|
||||||
|
ports:
|
||||||
|
- 12345:12345
|
||||||
|
volumes:
|
||||||
|
- ./alloy-config.alloy:/etc/alloy/config.alloy
|
||||||
|
- ./logs:/tmp/app-logs/
|
||||||
|
command: run --server.http.listen-addr=0.0.0.0:12345 --storage.path=/var/lib/alloy/data /etc/alloy/config.alloy
|
||||||
3
deploy-node.sh
Executable file
3
deploy-node.sh
Executable file
@@ -0,0 +1,3 @@
|
|||||||
|
wget https://git.oliveratkinson.net/Oliver/linux-node-visability/raw/branch/master/compose-node.yml
|
||||||
|
sudo ufw allow from 10.50.50.0/24 to any port 9100
|
||||||
|
docker compose -f compose-node.yml up -d
|
||||||
46
main.py
46
main.py
@@ -1,46 +0,0 @@
|
|||||||
import time
|
|
||||||
import board
|
|
||||||
import adafruit_dht
|
|
||||||
from http.server import BaseHTTPRequestHandler, HTTPServer
|
|
||||||
|
|
||||||
sensor = adafruit_dht.DHT22(board.D21)
|
|
||||||
|
|
||||||
hostName = "0.0.0.0"
|
|
||||||
serverPort = 7070
|
|
||||||
|
|
||||||
class MyServer(BaseHTTPRequestHandler):
|
|
||||||
def do_GET(self):
|
|
||||||
try:
|
|
||||||
# Print the values to the serial port
|
|
||||||
temperature_c = sensor.temperature
|
|
||||||
temperature_f = temperature_c * (9 / 5) + 32
|
|
||||||
humidity = sensor.humidity
|
|
||||||
self.send_response(200)
|
|
||||||
self.send_header("Content-type", "text/plain")
|
|
||||||
self.end_headers()
|
|
||||||
self.wfile.write(bytes("# TYPE target_info gauge\n", "utf-8"))
|
|
||||||
self.wfile.write(bytes("humidity{{location=\"beddroom\"}} {}\n".format(humidity), "utf-8"))
|
|
||||||
|
|
||||||
self.wfile.write(bytes("# TYPE temperature gauge\n", "utf-8"))
|
|
||||||
self.wfile.write(bytes("temperature{{location=\"beddroom\"}} {}\n".format(temperature_f), "utf-8"))
|
|
||||||
|
|
||||||
except RuntimeError as error:
|
|
||||||
# Errors happen fairly often, DHT's are hard to read, just keep going
|
|
||||||
self.send_response(500)
|
|
||||||
print(error.args[0])
|
|
||||||
except Exception as error:
|
|
||||||
self.send_response(500)
|
|
||||||
sensor.exit()
|
|
||||||
raise error
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
webServer = HTTPServer((hostName, serverPort), MyServer)
|
|
||||||
print("Server started http://%s:%s" % (hostName, serverPort))
|
|
||||||
|
|
||||||
try:
|
|
||||||
webServer.serve_forever()
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
pass
|
|
||||||
|
|
||||||
webServer.server_close()
|
|
||||||
print("Server stopped.")
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
global:
|
|
||||||
scrape_interval: 15s
|
|
||||||
query_log_file: /etc/prometheus/query.log
|
|
||||||
|
|
||||||
scrape_configs:
|
|
||||||
- job_name: bedroom
|
|
||||||
static_configs:
|
|
||||||
- targets: ['192.168.8.79:7070']
|
|
||||||
|
|
||||||
26
server/Caddyfile
Normal file
26
server/Caddyfile
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
admin :2019
|
||||||
|
|
||||||
|
servers :3000 {
|
||||||
|
name grafana
|
||||||
|
metrics
|
||||||
|
}
|
||||||
|
|
||||||
|
servers :3001 {
|
||||||
|
name loki
|
||||||
|
metrics
|
||||||
|
}
|
||||||
|
|
||||||
|
log debug {
|
||||||
|
level debug
|
||||||
|
output file /var/log/caddy/debug.log
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:3000 {
|
||||||
|
reverse_proxy grafana:3000
|
||||||
|
}
|
||||||
|
|
||||||
|
:3100 {
|
||||||
|
reverse_proxy loki:3100
|
||||||
|
}
|
||||||
@@ -1,4 +1,20 @@
|
|||||||
services:
|
services:
|
||||||
|
# r-proxy
|
||||||
|
caddy:
|
||||||
|
image: caddy:latest
|
||||||
|
restart: unless-stopped
|
||||||
|
ports:
|
||||||
|
# HTTP
|
||||||
|
- 80:80
|
||||||
|
- 443:443
|
||||||
|
- '443:443/udp'
|
||||||
|
# Grafana
|
||||||
|
- 3000:3000
|
||||||
|
# Loki
|
||||||
|
- 3100:3100
|
||||||
|
volumes:
|
||||||
|
- ./Caddyfile:/etc/caddy/Caddyfile
|
||||||
|
|
||||||
# Metrics collector
|
# Metrics collector
|
||||||
prometheus:
|
prometheus:
|
||||||
image: prom/prometheus:latest
|
image: prom/prometheus:latest
|
||||||
@@ -8,9 +24,20 @@ services:
|
|||||||
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
|
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
|
||||||
# persist data
|
# persist data
|
||||||
- prometheus_storage:/prometheus
|
- prometheus_storage:/prometheus
|
||||||
|
depends_on:
|
||||||
|
- caddy
|
||||||
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml
|
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml
|
||||||
|
|
||||||
# log viewer
|
# Logs
|
||||||
|
loki:
|
||||||
|
image: grafana/loki:2.9.2
|
||||||
|
expose:
|
||||||
|
- 3100
|
||||||
|
command: -config.file=/etc/loki/local-config.yaml
|
||||||
|
volumes:
|
||||||
|
- ./loki.yaml:/etc/loki/local-config.yaml
|
||||||
|
|
||||||
|
# Everything viewer
|
||||||
grafana:
|
grafana:
|
||||||
image: grafana/grafana:latest
|
image: grafana/grafana:latest
|
||||||
volumes:
|
volumes:
|
||||||
@@ -21,8 +48,8 @@ services:
|
|||||||
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
|
||||||
- GF_AUTH_DISABLE_LOGIN_FORM=true
|
- GF_AUTH_DISABLE_LOGIN_FORM=true
|
||||||
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
|
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
|
||||||
ports:
|
expose:
|
||||||
- 3000:3000
|
- 3000
|
||||||
depends_on:
|
depends_on:
|
||||||
- prometheus
|
- prometheus
|
||||||
|
|
||||||
@@ -13,3 +13,12 @@ datasources:
|
|||||||
editable: false
|
editable: false
|
||||||
jsonData:
|
jsonData:
|
||||||
httpMethod: GET
|
httpMethod: GET
|
||||||
|
- name: Loki
|
||||||
|
type: loki
|
||||||
|
access: proxy
|
||||||
|
orgId: 1
|
||||||
|
url: http://loki:3100
|
||||||
|
basicAuth: false
|
||||||
|
isDefault: false
|
||||||
|
version: 1
|
||||||
|
editable: false
|
||||||
15
server/prometheus.yaml
Normal file
15
server/prometheus.yaml
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
global:
|
||||||
|
scrape_interval: 15s
|
||||||
|
query_log_file: /etc/prometheus/query.log
|
||||||
|
|
||||||
|
scrape_configs:
|
||||||
|
- job_name: caddy
|
||||||
|
static_configs:
|
||||||
|
- targets: ['caddy:2019']
|
||||||
|
- job_name: node
|
||||||
|
static_configs:
|
||||||
|
# put a list of all the nodes you are monitoring
|
||||||
|
- targets: ['10.0.0.92:9100']
|
||||||
|
- job_name: prometheus
|
||||||
|
static_configs:
|
||||||
|
- targets: ['localhost:9090']
|
||||||
Reference in New Issue
Block a user