Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add save metrics as file #55

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ services:
restart: unless-stopped
```

Example docker-compose.yml with node-exporter and file export:


```yml
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: matusnovak/prometheus-smartctl:latest
container_name: smartctl-exporter
privileged: true
environment:
- "SMARTCTL_METRICS_FILE_ENABLE=True"
volumes:
- ./tmp/:/metrics/
restart: unless-stopped
```



Your metrics will be available at <http://localhost:9902/metrics>

The exported metrics looks like these:
Expand Down Expand Up @@ -68,6 +98,8 @@ All configuration is done with environment variables.
- `SMARTCTL_REFRESH_INTERVAL`: (Optional) The refresh interval of the metrics. A larger value reduces CPU usage. The default is `60` seconds.
- `SMARTCTL_EXPORTER_PORT`: (Optional) The address the exporter should listen on. The default is `9902`.
- `SMARTCTL_EXPORTER_ADDRESS`: (Optional) The address the exporter should listen on. The default is to listen on all addresses.
- `SMARTCTL_METRICS_FILE_ENABLE`: (Optional) To enable metrics file, if you have a node exporter running anyway, you can simply read out this file . The default is `False`.
- `SMARTCTL_METRICS_FILE_PATH`: (Optional) the path, this must then also be specified in the docker-compose as volume. The default is `/metrics/`.

## Grafana dashboard

Expand Down
4 changes: 4 additions & 0 deletions smartprom.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def main():
exporter_address = os.environ.get("SMARTCTL_EXPORTER_ADDRESS", "0.0.0.0")
exporter_port = int(os.environ.get("SMARTCTL_EXPORTER_PORT", 9902))
refresh_interval = int(os.environ.get("SMARTCTL_REFRESH_INTERVAL", 60))
metrics_file_enable = os.environ.get("SMARTCTL_METRICS_FILE_ENABLE", False)
metrics_file_path = os.environ.get("SMARTCTL_METRICS_FILE_PATH", "/metrics/")

# Get drives (test smartctl)
DRIVES = get_drives()
Expand All @@ -303,6 +305,8 @@ def main():

while True:
collect()
if metrics_file_enable:
prometheus_client.write_to_textfile(metrics_file_path+"smartctl.prom", prometheus_client.REGISTRY)
time.sleep(refresh_interval)


Expand Down