matusnovak / prometheus-smartctl

HDD S.M.A.R.T exporter for Prometheus written in Python
The Unlicense
155 stars 43 forks source link

add option to save as text file #53

Open badsmoke opened 2 months ago

badsmoke commented 2 months ago

hey cool project, thanks for that.

an option to save the metrics as “smartmon_exporter.prom” would still be useful, the node-exporter can also retrieve the data in this way and thus no port has to be opened and the smart values are automatically retrieved with every node-exporter call

matusnovak commented 2 months ago

Hi.

Just out of curiosity, why do you want to avoid opening a port and reading metrics from there?

To answer your question, I think this could work quite easily. The Python prometheus_client seems to have an option write_to_textfile which is defined here: https://github.com/prometheus/client_python/blob/master/prometheus_client/exposition.py I haven't tried it, but it looks very promising.

I am currently busy with life events and other projects. I do not have time to implement this. However, PR is more than welcome if you would like to implement it.

badsmoke commented 1 month ago

Hey @matusnovak

this option means you don't have to set an extra target in prometheus again.

I have made a pull request

https://github.com/matusnovak/prometheus-smartctl/pull/55

badsmoke commented 1 day ago

for those who are interested, this is the customized image

image: docker.badcloud.eu/library/prometheus-smartctl:latest

version: "3"
services:
    node-exporter:
        image: quay.io/prometheus/node-exporter
        restart: always
        volumes:
            - '/:/host:ro,rslave'
            - './tmp/:/tmp/'
        network_mode: "host"
        pid: "host"
        command:
            - "--path.rootfs=/host"
            - "--collector.textfile.directory=/tmp/"
    smartctl-exporter:
      image: docker.badcloud.eu/library/prometheus-smartctl:latest
      container_name: smartctl-exporter
      privileged: true
      environment:
        - "SMARTCTL_METRICS_FILE_ENABLE=True"
      volumes:
        - ./tmp/:/metrics/
      restart: unless-stopped