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