Skip to content

Commit

Permalink
first try (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvek authored Aug 15, 2023
1 parent aafeda7 commit d9a33ad
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/create-docker-exporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: create docker exporter
on:
workflow_dispatch:
branches:
- master
jobs:
create-docker-bridge:
name: create docker Domotik Exporter
runs-on: ubuntu-latest
steps:
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v2
with:
context: '{{defaultContext}}:exporter'
push: true
platforms: linux/amd64,linux/arm64
tags: ghcr.io/sylvek/domotik-exporter:latest
4 changes: 4 additions & 0 deletions exporter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM ruby:slim
RUN gem install sqlite3 httparty
COPY main.rb /main.rb
CMD ["ruby", "main.rb"]
11 changes: 11 additions & 0 deletions exporter/main.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'sqlite3'
require 'httparty'

entrypoint = ENV['ENTRYPOINT']
db = SQLite3::Database.new ENV['DATABASE']

db.execute("SELECT ts,value FROM data WHERE name='daily_power_consumption' ORDER BY ts DESC LIMIT 1") do |row|
title = "#{row[1].to_i/1000.0} kW.h"
response = HTTParty.get("#{entrypoint}?title=#{title}&timestamp=#{row[0]}")
puts response.body
end

0 comments on commit d9a33ad

Please sign in to comment.