add exclude
This commit is contained in:
@@ -28,4 +28,8 @@ Make collect.py executable:
|
||||
chmod +x collect.py
|
||||
```
|
||||
|
||||
Schedule a cronjob to run collect.py at your preferred interval
|
||||
Schedule a cronjob to run collect.py at your preferred interval. Cronjob command is:
|
||||
|
||||
```bash
|
||||
COLLECTOR_CONF=/root/collector/collector.json /root/collector/collect.py
|
||||
```
|
||||
@@ -8,7 +8,7 @@ from collector.helper import *
|
||||
|
||||
CONFIG_FILE = os.getenv("COLLECTOR_CONF", "collector.json")
|
||||
REQUIRED = ["graphite","os","data"]
|
||||
VALID_DATAPOINTS = ["storage"]
|
||||
VALID_DATAPOINTS = ["storage", "heartbeat"]
|
||||
VALID_OS = ["linux", "osx"]
|
||||
REQUIRED_STORAGE = ["path", "name"]
|
||||
CONFIG = {}
|
||||
@@ -67,5 +67,12 @@ if "storage" in data_points:
|
||||
else:
|
||||
name = item["name"]
|
||||
path = item["path"]
|
||||
exclude = item.get("exclude", None)
|
||||
else:
|
||||
storage_sender = functools.partial(sender, f"{HOSTNAME}.storage.{name}")
|
||||
thread(collect_storage, storage_sender, path)
|
||||
thread(collect_storage, storage_sender, path, exclude = exclude)
|
||||
|
||||
# Check heartbeat
|
||||
if "heartbeat" in data_points:
|
||||
heartbeat_sender = functools.partial(sender, f"{HOSTNAME}.heartbeat")
|
||||
thread(lambda: 1, heartbeat_sender)
|
||||
@@ -4,7 +4,6 @@ import threading
|
||||
import subprocess
|
||||
import re
|
||||
import functools
|
||||
import random
|
||||
import time
|
||||
|
||||
from .sender import send
|
||||
@@ -36,6 +35,9 @@ def collect_temp():
|
||||
def collect_compute():
|
||||
pass
|
||||
|
||||
def collect_storage(path):
|
||||
storage = nice_run(["du", "-sk", path])
|
||||
def collect_storage(path, exclude = None):
|
||||
cmd = ["du", "-sk", path]
|
||||
if exclude:
|
||||
cmd += [f"--exclude={exclude}"]
|
||||
storage = nice_run(cmd)
|
||||
return clean_storage(storage)
|
||||
@@ -5,6 +5,7 @@
|
||||
},
|
||||
"os": "osx",
|
||||
"data": {
|
||||
"heartbeat": null,
|
||||
"storage": [
|
||||
{
|
||||
"path": "/Users/ducoterra",
|
||||
@@ -21,6 +22,11 @@
|
||||
{
|
||||
"path": "/Users",
|
||||
"name": "users"
|
||||
},
|
||||
{
|
||||
"path": ".",
|
||||
"name": "curdir_noreadme",
|
||||
"exclude": "*.md"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user