···
8
+
cfg = config.services.prometheus.exporters.ecoflow;
9
+
inherit (lib) mkOption types;
14
+
exporterType = mkOption {
22
+
The type of exporter you'd like to use.
23
+
Possible values: "rest" and "mqtt". Default value is "rest".
24
+
Choose "rest" for the ecoflow online cloud api use "rest" and define: accessKey, secretKey.
25
+
Choose "mqtt" for the lan realtime integration use "mqtt" and define: email, password, devices.
28
+
ecoflowAccessKeyFile = mkOption {
30
+
default = /etc/ecoflow-access-key;
32
+
Path to the file with your personal api access string from the Ecoflow development website https://developer-eu.ecoflow.com.
33
+
Do to share or commit your plaintext scecrets to a public repo use: agenix or soaps.
36
+
ecoflowSecretKeyFile = mkOption {
38
+
default = /etc/ecoflow-secret-key;
40
+
Path to the file with your personal api secret string from the Ecoflow development website https://developer-eu.ecoflow.com.
41
+
Do to share or commit your plaintext scecrets to a public repo use: agenix or soaps.
44
+
ecoflowEmailFile = mkOption {
46
+
default = /etc/ecoflow-email;
48
+
Path to the file with your personal ecoflow app login email address.
49
+
Do to share or commit your plaintext scecrets to a public repo use: agenix or soaps.
52
+
ecoflowPasswordFile = mkOption {
54
+
default = /etc/ecoflow-password;
56
+
Path to the file with your personal ecoflow app login email password.
57
+
Do to share or commit your plaintext passwords to a public repo use: agenix or soaps here!
60
+
ecoflowDevicesFile = mkOption {
62
+
default = /etc/ecoflow-devices;
64
+
File must contain one line, example: R3300000,R3400000,NC430000,....
65
+
The list of devices serial numbers separated by comma. For instance: SN1,SN2,SN3.
66
+
Instead of "devicesFile" you can specify "devicesPrettynamesFile" which will also work. You can specify both.
67
+
Do to share or commit your plaintext serial numbers to a public repo use: agenix or soaps.
70
+
ecoflowDevicesPrettyNamesFile = mkOption {
72
+
default = /etc/ecoflow-devices-pretty-names;
74
+
File must contain one line, example: {"R3300000":"Delta 2","R3400000":"Delta Pro",...}
75
+
The key/value map of custom names for your devices. Key is a serial number, value is a device name you want
76
+
to see in Grafana Dashboard. It's helpful to see a meaningful name in Grafana dashboard instead of a serialnumber.
77
+
Do to share or commit your plaintext serial numbers to a public repo use: agenix or soaps.
85
+
Enable debug log messages. Disabled by default. Set to "1" to enable.
90
+
default = "ecoflow";
91
+
example = "ecoflow_privateSite";
93
+
The prefix that will be added to all metrics. Default value is ecoflow.
94
+
For instance metric bms_bmsStatus.minCellTemp will be exported to prometheus as ecoflow.bms_bmsStatus.minCellTemp.
95
+
With default value "ecoflow" you can use Grafana Dashboard with ID 17812 without any changes.
98
+
scrapingInterval = mkOption {
99
+
type = types.ints.positive;
103
+
Scrapping interval in seconds. How often should the exporter execute requests to Ecoflow Rest API in order to get the data.
104
+
Default value is 30 seconds. Align this value with your prometheus scraper interval settings.
107
+
mqttDeviceOfflineThreshold = mkOption {
108
+
type = types.ints.positive;
112
+
The threshold in seconds which indicates how long we should wait for a metric message from MQTT broker.
113
+
Default value: 60 seconds. If we don't receive message within 60 seconds we consider that device is offline.
114
+
If we don't receive messages within the threshold for all devices, we'll try to reconnect to the MQTT broker.
115
+
There is a strange behavior that MQTT stop sends messages if you open Ecoflow mobile app and then close it).
121
+
PROMETHEUS_ENABLED = "1";
122
+
EXPORTER_TYPE = cfg.exporterType;
123
+
DEBUG_ENABLED = cfg.debug;
124
+
METRIC_PREFIX = cfg.prefix;
125
+
SCRAPING_INTERVAL = toString cfg.scrapingInterval;
126
+
MQTT_DEVICE_OFFLINE_THRESHOLD_SECONDS = toString cfg.mqttDeviceOfflineThreshold;
129
+
export ECOFLOW_ACCESS_KEY="$(cat ${toString cfg.ecoflowAccessKeyFile})"
130
+
export ECOFLOW_SECRET_KEY="$(cat ${toString cfg.ecoflowSecretKeyFile})"
131
+
export ECOFLOW_EMAIL="$(cat ${toString cfg.ecoflowEmailFile})"
132
+
export ECOFLOW_PASSWORD="$(cat ${toString cfg.ecoflowPasswordFile})"
133
+
export ECOFLOW_DEVICES="$(cat ${toString cfg.ecoflowDevicesFile})"
134
+
export ECOFLOW_DEVICES_PRETTY_NAMES="$(cat ${toString cfg.ecoflowDevicesPrettyNamesFile})"
135
+
exec ${lib.getExe pkgs.go-ecoflow-exporter}'';
137
+
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
138
+
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
139
+
MemoryDenyWriteExecute = true;
140
+
NoNewPrivileges = true;
141
+
ProtectSystem = "strict";
142
+
Restart = "on-failure";
143
+
RestrictAddressFamilies = [
147
+
RestrictNamespaces = true;
148
+
User = "prometheus"; # context needed to runtime access encrypted token and secrets