diff --git a/opcua-exporter/Dockerfile b/opcua-exporter/Dockerfile index dbf2bc5..ea394ba 100644 --- a/opcua-exporter/Dockerfile +++ b/opcua-exporter/Dockerfile @@ -39,9 +39,16 @@ RUN mkdir build && \ FROM openeuler/openeuler:24.03 -RUN mkdir /data +RUN dnf update -y && \ + dnf install -y supervisor &&\ + dnf clean all && \ + rm -rf /var/cache/dnf/* + +RUN curl -fsSL https://github.com/abtreece/confd/releases/download/v0.20.0/confd-v0.20.0-linux-amd64.tar.gz | tar -xz -C /usr/local/bin && \ + chmod +x /usr/local/bin/confd + +COPY ./supervisord/ /etc/supervisord/ COPY --from=build /app/build/opcua_exporter /usr/local/bin - -CMD [ "opcua_exporter", "/data/opcua/opcua.yaml" ] \ No newline at end of file +CMD [ "supervisord", "-c", "/etc/supervisord/supervisord.conf" ] \ No newline at end of file diff --git a/opcua-exporter/confd/confd.toml b/opcua-exporter/confd/confd.toml new file mode 100644 index 0000000..2fc4b41 --- /dev/null +++ b/opcua-exporter/confd/confd.toml @@ -0,0 +1,6 @@ +backend = "etcd" +nodes = [ + "http://etcd:2379", +] +watch = true + diff --git a/opcua-exporter/confd/templates/opcua.tmpl b/opcua-exporter/confd/templates/opcua.tmpl new file mode 100644 index 0000000..ba5ea6b --- /dev/null +++ b/opcua-exporter/confd/templates/opcua.tmpl @@ -0,0 +1,30 @@ +datasource: + data_source_type: {{ getv "/datasource/data_source_type" }} + name: {{ getv "/datasource/name" }} + description: {{ getv "/datasource/description" }} + opcua_service_address: {{ getv "/datasource/opcua_service_address" }} + security_policy_address: {{ getv "/datasource/security_policy_address" }} + security_mode: {{ getv "/datasource/security_mode" }} + key_authentication_file: {{ getv "/datasource/key_authentication_file" }} + certificate_authentication_file: {{ getv "/datasource/certificate_authentication_file" }} + trusted_list: {{ getv "/datasource/trusted_list" }} + username: {{ getv "/datasource/username" }} + password: {{ getv "/datasource/password" }} + certificate_identity_file: {{ getv "/datasource/certificate_identity_file" }} + key_identity_file: {{ getv "/datasource/key_identity_file" }} + read_mode: {{ getv "/datasource/read_mode" }} + cache_update: {{ getv "/datasource/cache_update" }} + cache_timeout: {{ getv "/datasource/cache_timeout" }} + +exporter: + exporter_bind: {{ getv "/exporter/exporter_bind" }} + exporter_thread: {{ getv "/exporter/exporter_thread" }} + exporter_auth: {{ getv "/exporter/exporter_auth" }} + +metrics: +{{ range $index, $element := ls "/metrics" }} + - name: {{ getv (printf "/metrics/%d/name" $index) }} + identifier_type: {{ getv (printf "/metrics/%d/identifier_type" $index) }} + nodeid: {{ getv (printf "/metrics/%d/nodeid" $index) }} + help: {{ getv (printf "/metrics/%d/help" $index) }} +{{ end }} diff --git a/opcua-exporter/supervisord/supervisord.conf b/opcua-exporter/supervisord/supervisord.conf new file mode 100644 index 0000000..50860f1 --- /dev/null +++ b/opcua-exporter/supervisord/supervisord.conf @@ -0,0 +1,18 @@ +[supervisord] +nodaemon=true ; 让 supervisor 运行在前台,保持容器不退出 +logfile=/var/log/supervisor/supervisord.log +pidfile=/var/run/supervisord.pid + +[program:opcua_exporter] +command=/usr/local/bin/opcua_exporter /etc/opcua/opcua.yaml +autostart=true +autorestart=true +stderr_logfile=/var/log/opcua_exporter.err.log +stdout_logfile=/var/log/opcua_exporter.out.log + +[program:confd] +command=/usr/local/bin/confd -config-file /etc/confd/confd.toml +autostart=true +autorestart=true +stderr_logfile=/var/log/confd.err.log +stdout_logfile=/var/log/confd.out.log