Skip to content

Commit

Permalink
Merge pull request #55 from badsmoke/master
Browse files Browse the repository at this point in the history
add save metrics as file
  • Loading branch information
matusnovak authored Nov 14, 2024
2 parents eb017e7 + e7c6a0f commit e3e2f6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
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

0 comments on commit e3e2f6f

Please sign in to comment.