Skip to content

Commit

Permalink
Merge pull request #96 from ccremer/systemd
Browse files Browse the repository at this point in the history
Add Systemd unit file to deb/rpm packages
  • Loading branch information
ccremer authored Oct 31, 2022
2 parents 3ec2d7a + 728af9b commit 336af85
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 64 deletions.
114 changes: 60 additions & 54 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
builds:
- env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
- amd64
- arm64
- arm
goos:
- linux
goarm:
- 7
- env:
- CGO_ENABLED=0 # this is needed otherwise the Docker image build is faulty
goarch:
- amd64
- arm64
- arm
goos:
- linux
goarm:
- 7

archives:
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
- format: binary
name_template: "{{ .Binary }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"

checksum:
name_template: 'checksums.txt'
Expand All @@ -23,57 +23,63 @@ snapshot:
name_template: "{{ .Tag }}-snapshot"

signs:
- artifacts: checksum
args: ["-u", "3E0B9A63FF344E7CB445BD84ED35499391B64DB4", "--output", "${signature}", "--detach-sign", "${artifact}"]
- artifacts: checksum
args: ["-u", "3E0B9A63FF344E7CB445BD84ED35499391B64DB4", "--output", "${signature}", "--detach-sign", "${artifact}"]

dockers:
- goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"
- goarch: amd64
use: buildx
build_flag_templates:
- "--platform=linux/amd64"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"

- goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64/v8"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"
- goarch: arm64
use: buildx
build_flag_templates:
- "--platform=linux/arm64/v8"
image_templates:
- " ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"

- goarch: arm
goarm: "7"
use: buildx
build_flag_templates:
- "--platform=linux/arm/v7"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"
- goarch: arm
goarm: "7"
use: buildx
build_flag_templates:
- "--platform=linux/arm/v7"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"

docker_manifests:
# For prereleases, updating `latest` does not make sense.
# Only the image for the exact version should be pushed.
- name_template: "{{ if not .Prerelease }}ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:latest{{ end }}"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"
# For prereleases, updating `latest` does not make sense.
# Only the image for the exact version should be pushed.
- name_template: "{{ if not .Prerelease }}ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:latest{{ end }}"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"

- name_template: "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"
- name_template: "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}"
image_templates:
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-amd64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-arm64"
- "ghcr.io/{{ .Env.IMAGE_REPOSITORY }}:v{{ .Version }}-armv7"

nfpms:
- vendor: ccremer
homepage: https://github.com/ccremer/fronius-exporter
maintainer: ccremer
description: Prometheus Exporter for Fronius Symo Photovoltaics
license: Apache 2.0
file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
formats:
- deb
- rpm
- vendor: ccremer
homepage: https://github.com/ccremer/fronius-exporter
maintainer: ccremer
description: Prometheus Exporter for Fronius Symo Photovoltaics
license: Apache 2.0
file_name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}"
formats:
- deb
- rpm
contents:
- src: examples/systemd.service
dst: /lib/systemd/system/fronius-exporter.service
- src: examples/systemd.env
dst: /etc/default/fronius-exporter
type: config

release:
prerelease: auto
19 changes: 14 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@ image::examples/grafana.png[Grafana]

== Installing

=== Binary

=== Traditional packages or binary

. Download latest binary or package from the https://github.com/ccremer/fronius-exporter/releases[Releases page]
. `dpkg -i fronius-exporter_linux_amd64.deb` (Debian/Ubuntu)
. `rpm -i fronius-exporter_linux_amd64.rpm` (CentOS)
. Download latest binary from the https://github.com/ccremer/fronius-exporter/releases[Releases page]
. `chmod +x fronius-exporter && mv fronius-exporter /usr/local/bin/`

=== Package

Comes with systemd unit file.

. Download latest package from the https://github.com/ccremer/fronius-exporter/releases[Releases page]
. `sudo dpkg -i fronius-exporter_linux_amd64.deb` (Debian/Ubuntu)
. `sudo rpm -i fronius-exporter_linux_amd64.rpm` (CentOS)
. `sudo systemctl daemon-reload`
. Edit the settings in `/etc/default/fronius-exporter`
. `sudo systemctl enable fronius-exporter`
. `sudo systemctl restart fronius-exporter`

=== Docker

. `docker run -d --name fronius-exporter -p "8080:8080" ghcr.io/ccremer/fronius-exporter --help`
Expand Down
2 changes: 1 addition & 1 deletion cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func setupCliFlags(version string, fs *flag.FlagSet, config *Configuration) {
fs.BoolP("log.verbose", "v", config.Log.Verbose, "Shortcut for --log.level=debug.")
fs.StringSlice("symo.header", config.Symo.Headers,
"List of \"key: value\" headers to append to the requests going to Fronius Symo. Example: --symo.header \"authorization=Basic <base64>\".")
fs.StringP("symo.url", "u", config.Symo.URL, "Target URL of Fronius Symo device.")
fs.StringP("symo.url", "u", config.Symo.URL, "Target base URL of Fronius Symo device.")
fs.Int64("symo.timeout", int64(config.Symo.Timeout.Seconds()),
"Timeout in seconds when collecting metrics from Fronius Symo. Should not be larger than the scrape interval.")
fs.Bool("symo.enable-power-flow", config.Symo.PowerFlowEnabled, "Enable/disable scraping of power flow data")
Expand Down
2 changes: 1 addition & 1 deletion cfg/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func NewDefaultConfig() *Configuration {
Level: "info",
},
Symo: SymoConfig{
URL: "http://symo.ip.or.hostname/solar_api/v1/GetPowerFlowRealtimeData.fcgi",
URL: "http://symo.ip.or.hostname",
Timeout: 5 * time.Second,
Headers: []string{},
PowerFlowEnabled: true,
Expand Down
20 changes: 20 additions & 0 deletions examples/systemd.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## IP Address to bind to listen for Prometheus scrapes.
BIND_ADDR=:9089

## Target URL of Fronius Symo device.
SYMO__URL=http://symo.ip.or.hostname

## Enable/disable scraping of archive data
# SYMO__ENABLE_ARCHIVE=true

## Enable/disable scraping of power flow data
# SYMO__ENABLE_POWER_FLOW=true

## Comma-separated List of "key: value" headers to append to the requests going to Fronius Symo. Example: "authorization=Basic <base64>".
# SYMO__HEADER=

## Timeout in seconds when collecting metrics from Fronius Symo. Should not be larger than the scrape interval.
# SYMO__TIMEOUT=5

## Logging level.
# LOG__LEVEL=info
16 changes: 16 additions & 0 deletions examples/systemd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This is a systemd unit file
[Unit]
Description=Prometheus Exporter for Fronius Symo Photovoltaics
Documentation=https://github.com/ccremer/fronius-exporter
After=network-online.target
Wants=network-online.target

[Service]
EnvironmentFile=-/etc/default/fronius-exporter
User=65534
Group=0
ExecStart=/usr/bin/fronius-exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target
6 changes: 3 additions & 3 deletions pkg/fronius/symo_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fronius

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -12,7 +12,7 @@ import (

func Test_Symo_GetPowerFlowData_GivenUrl_WhenRequestData_ThenParseStruct(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
payload, err := ioutil.ReadFile("testdata/example_1.json")
payload, err := os.ReadFile("testdata/example_1.json")
require.NoError(t, err)
_, _ = rw.Write(payload)
}))
Expand All @@ -39,7 +39,7 @@ func Test_Symo_GetPowerFlowData_GivenUrl_WhenRequestData_ThenParseStruct(t *test

func Test_Symo_GetArchiveData_GivenUrl_WhenRequestData_ThenParseStruct(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
payload, err := ioutil.ReadFile("testdata/test_archive_data.json")
payload, err := os.ReadFile("testdata/test_archive_data.json")
require.NoError(t, err)
_, _ = rw.Write(payload)
}))
Expand Down

0 comments on commit 336af85

Please sign in to comment.