working :)

This commit is contained in:
Oliver 2025-02-24 01:03:33 -07:00
parent cd4854f2c6
commit addd3f4e52
4 changed files with 80 additions and 18 deletions

31
compose.yml Normal file
View File

@ -0,0 +1,31 @@
services:
# Metrics collector
prometheus:
image: prom/prometheus:latest
expose:
- 9090
volumes:
- ./prometheus.yaml:/etc/prometheus/prometheus.yml
# persist data
- prometheus_storage:/prometheus
command: --web.enable-lifecycle --config.file=/etc/prometheus/prometheus.yml
# log viewer
grafana:
image: grafana/grafana:latest
volumes:
- ./grafana.yaml:/etc/grafana/provisioning/datasources/datasources.yaml
- grafana_storage:/var/lib/grafana
environment:
- GF_AUTH_ANONYMOUS_ENABLED=true
- GF_AUTH_ANONYMOUS_ORG_ROLE=Admin
- GF_AUTH_DISABLE_LOGIN_FORM=true
- GF_FEATURE_TOGGLES_ENABLE=traceqlEditor
ports:
- 3000:3000
depends_on:
- prometheus
volumes:
prometheus_storage:
grafana_storage:

View File

@ -13,12 +13,3 @@ datasources:
editable: false
jsonData:
httpMethod: GET
- name: Loki
type: loki
access: proxy
orgId: 1
url: http://loki:3100
basicAuth: false
isDefault: false
version: 1
editable: false

46
main.py Normal file
View File

@ -0,0 +1,46 @@
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.")

View File

@ -3,13 +3,7 @@ global:
query_log_file: /etc/prometheus/query.log
scrape_configs:
- job_name: caddy
- job_name: bedroom
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']
- targets: ['192.168.8.79:7070']