Skip to content

Commit

Permalink
Refresh dependencies, ci pipeline etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomplus committed Feb 15, 2024
1 parent 5f562d7 commit ada50f3
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 45 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Upload Go test results

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.22
- name: Install dependencies
run: go mod download
- name: Build
run: |
go build
./airly-exporter -h
- name: Test
run: go test
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
FROM golang:1.10-alpine
FROM golang:1.22-alpine

RUN apk add --no-cache git

WORKDIR /go/src/airly-exporter
COPY *.go /go/src/airly-exporter/
WORKDIR /app
COPY *.go .
COPY go.mod .
COPY go.sum .

RUN go get -d -v ./...
RUN go install -v ./...
RUN go mod download
RUN go build

FROM alpine

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*

WORKDIR /go/bin/
COPY --from=0 /go/bin/airly-exporter /go/bin/airly-exporter
WORKDIR /app
COPY --from=0 /app/airly-exporter /app/airly-exporter

EXPOSE 8080

Expand Down
44 changes: 22 additions & 22 deletions airly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,71 +166,71 @@ func TestSensorMeasurements(t *testing.T) {
FromDateTime: "2018-01-01T21:46:25.476Z",
TillDateTime: "2018-01-01T22:46:25.476Z",
Values: []MeasuredValue{
MeasuredValue{Name: "PM1", Value: 17.01},
MeasuredValue{Name: "PM25", Value: 25.69},
MeasuredValue{Name: "PM10", Value: 49.7},
MeasuredValue{Name: "PRESSURE", Value: 1025.82},
MeasuredValue{Name: "HUMIDITY", Value: 82.91},
MeasuredValue{Name: "TEMPERATURE", Value: 7.64}},
{Name: "PM1", Value: 17.01},
{Name: "PM25", Value: 25.69},
{Name: "PM10", Value: 49.7},
{Name: "PRESSURE", Value: 1025.82},
{Name: "HUMIDITY", Value: 82.91},
{Name: "TEMPERATURE", Value: 7.64}},
Indexes: []MeasuredIndex{
MeasuredIndex{
{
Name: "AIRLY_CAQI",
Value: 49.7,
Level: "LOW",
Description: "Air is quite good.",
Advice: "How about going for a walk?",
Color: "#D1CF1E"}},
Standards: []MeasuredStandard{
MeasuredStandard{
{
Name: "WHO",
Pollutant: "PM25",
Limit: 25,
Percent: 102.77}},
},
History: []MeasurementsTimeFramed{
MeasurementsTimeFramed{
{
FromDateTime: "2018-10-19T22:00:00Z",
TillDateTime: "2018-10-19T23:00:00Z",
Values: []MeasuredValue{
MeasuredValue{Name: "PM1", Value: 26.66},
MeasuredValue{Name: "PM25", Value: 42.97},
MeasuredValue{Name: "PM10", Value: 79.19},
MeasuredValue{Name: "PRESSURE", Value: 1025.44},
MeasuredValue{Name: "HUMIDITY", Value: 92.64},
MeasuredValue{Name: "TEMPERATURE", Value: 10.22}},
{Name: "PM1", Value: 26.66},
{Name: "PM25", Value: 42.97},
{Name: "PM10", Value: 79.19},
{Name: "PRESSURE", Value: 1025.44},
{Name: "HUMIDITY", Value: 92.64},
{Name: "TEMPERATURE", Value: 10.22}},
Indexes: []MeasuredIndex{
MeasuredIndex{
{
Name: "AIRLY_CAQI",
Value: 68.24,
Level: "MEDIUM",
Description: "Well... It's been better.",
Advice: "Neither good nor bad. Think before leaving the house.",
Color: "#EFBB0F"}},
Standards: []MeasuredStandard{
MeasuredStandard{
{
Name: "WHO",
Pollutant: "PM25",
Limit: 25,
Percent: 171.88}},
},
},
Forecast: []MeasurementsTimeFramed{
MeasurementsTimeFramed{
{
FromDateTime: "2018-01-01T22:00:00Z",
TillDateTime: "2018-01-01T23:00:00Z",
Values: []MeasuredValue{
MeasuredValue{Name: "PM25", Value: 27.48},
MeasuredValue{Name: "PM10", Value: 53.29}},
{Name: "PM25", Value: 27.48},
{Name: "PM10", Value: 53.29}},
Indexes: []MeasuredIndex{
MeasuredIndex{
{
Name: "AIRLY_CAQI",
Value: 52.06,
Level: "MEDIUM",
Description: "Well... It's been better.",
Advice: "Protect your lungs!",
Color: "#EFBB0F"}},
Standards: []MeasuredStandard{
MeasuredStandard{
{
Name: "WHO",
Pollutant: "PM25",
Limit: 25,
Expand Down
19 changes: 19 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module airly-exporter

go 1.22.0

require (
github.com/fsnotify/fsnotify v1.7.0
github.com/prometheus/client_golang v1.18.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
28 changes: 28 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
github.com/prometheus/client_golang v1.18.0 h1:HzFfmkOzH5Q8L8G+kSJKUx5dtG87sewO+FoDDqP5Tbk=
github.com/prometheus/client_golang v1.18.0/go.mod h1:T+GXkCk5wSJyOqMIzVgvvjFDlkOQntgjkJWKrN5txjA=
github.com/prometheus/client_model v0.5.0 h1:VQw1hfvPvk3Uv6Qf29VrPF32JB6rtbgI6cYPYQjL0Qw=
github.com/prometheus/client_model v0.5.0/go.mod h1:dTiFglRmd66nLR9Pv9f0mZi7B7fk5Pm3gvsjB5tr+kI=
github.com/prometheus/common v0.45.0 h1:2BGz0eBc2hdMDLnO/8n0jeB3oPrt2D08CekT0lneoxM=
github.com/prometheus/common v0.45.0/go.mod h1:YJmSTw9BoKxJplESWWxlbyttQR4uaEcGyv9MZjVOJsY=
github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k6Bo=
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
15 changes: 7 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// Copyright 2018 Airly-exporter Authors

package main

import (
"bufio"
"flag"
"fmt"
"github.com/fsnotify/fsnotify"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"os"
"strconv"
"strings"
"time"

"github.com/fsnotify/fsnotify"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// AirlyExporter contains parameters for Airly-exporter
Expand Down Expand Up @@ -136,8 +135,8 @@ func (airlyExporter *AirlyExporter) flagParse() {
airlyExporter.listenAddress = flagStringWithDefaultFromEnv("listen-address", ":8080", "the address to listen on for http requests.")
airlyExporter.apiKey = flagStringWithDefaultFromEnv("api-key", "", "Your key for Airly API")
airlyExporter.apiURL = flagStringWithDefaultFromEnv("api-url", "https://airapi.airly.eu", "Airly API endpoint")
airlyExporter.refreshInterval = flagStringWithDefaultFromEnv("refresh-interval", "5m", "Refresh sensor interval with units")
airlyExporter.sensors = flagStringWithDefaultFromEnv("sensors", "204,822", "Comma separated sensors/installations IDs")
airlyExporter.refreshInterval = flagStringWithDefaultFromEnv("refresh-interval", "60m", "Refresh sensor interval with units")
airlyExporter.sensors = flagStringWithDefaultFromEnv("sensors", "17,97128", "Comma separated sensors/installations IDs (default Krakow, Warszawa)")
flag.Parse()
}

Expand All @@ -157,7 +156,7 @@ func main() {

go airlyExporter.watchSensors()

http.Handle("/", http.RedirectHandler("/metrics", 302))
http.Handle("/", http.RedirectHandler("/metrics", http.StatusFound))
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(*airlyExporter.listenAddress, nil))
}

0 comments on commit ada50f3

Please sign in to comment.