"ขวดป๊อป" -- เบิร์ดแมน
กระจุกกราไฟท์ค่อนข้างเจ๋ง ต่อไปนี้เป็นเครื่องมือพื้นฐานบางส่วนที่จะช่วยคุณจัดการคลัสเตอร์กราไฟท์
เครื่องมือทั้งหมดรองรับข้อโต้แย้งทั่วไปสองข้อ เส้นทางไปยังไฟล์กำหนดค่า และชื่อของคลัสเตอร์ การใช้เครื่องมือเหล่านี้ควบคู่ไปกับไฟล์กำหนดค่าที่อธิบายกลุ่มกราไฟท์ของคุณ คุณสามารถสร้างสคริปต์เพื่อจัดการหน่วยวัดของคุณได้ เครื่องมือบางอย่างสามารถเปลี่ยนได้อย่างง่ายดายด้วย one-liners ในเชลล์ แต่มีอยู่ที่นี่เพื่อความสะดวกและอ่านง่าย เป้าหมายคือการจัดหายูทิลิตี้ที่รวดเร็วและคาดการณ์ได้ซึ่งสามารถประกอบเป็นเครื่องมือขั้นสูงได้อย่างง่ายดาย
Carbonate มีให้บริการจากพื้นที่เก็บข้อมูลบุคคลที่สามอย่างเป็นทางการของ Python (หรือที่รู้จักในชื่อ PyPi) และสามารถติดตั้งผ่านตัวจัดการแพ็คเกจ Python ทั่วไปได้ โปรดทราบว่าคุณอาจต้องติดตั้งตัวจัดการแพ็คเกจหลาม (เช่น apt-get install python-setuptools บนโฮสต์ Ubuntu)
pip install carbonate
Carbonate ต้องการไฟล์การกำหนดค่าที่กำหนดคลัสเตอร์ในสภาพแวดล้อมของคุณ ไฟล์กำหนดค่าเริ่มต้นอยู่ที่ /opt/graphite/conf/carbonate.conf
หรือสามารถระบุได้ในบรรทัดคำสั่ง คลัสเตอร์เริ่มต้นมีชื่อว่า 'main' ค่าเริ่มต้นทั้งสองสามารถแทนที่ได้โดยการตั้งค่าในสภาพแวดล้อม CARBONATE_CONFIG
และ CARBONATE_CLUSTER
ตามลำดับ
[main]
DESTINATIONS = 192.168.9.13:2004:carbon01, 192.168.9.15:2004:carbon02, 192.168.6.20:2004:carbon03
REPLICATION_FACTOR = 2
SSH_USER = carbon
[agg]
DESTINATIONS = 192.168.9.13:2004:carbon01, 192.168.9.15:2004:carbon02, 192.168.6.20:2004:carbon03
RELAY_METHOD = aggregated-consistent-hashing
REPLICATION_FACTOR = 2
SSH_USER = carbon
[fnv]
DESTINATIONS = 192.168.9.13:2004:ba603c36342304ed77953f84ac4d357b, 192.168.9.15:2004:5dd63865534f84899c6e5594dba6749a, 192.168.6.20:2004:866a18b81f2dc4649517a1df13e26f28
REPLICATION_FACTOR = 2
SSH_USER = carbonate
HASHING_TYPE = fnv1a_ch
คุณควรดูแลจับคู่รายการ IP ปลายทางหรือชื่อโฮสต์กับโหนดในคลัสเตอร์ของคุณ (เช่น ควรจับคู่กับการกำหนดค่าเส้นทางของ Carbon Relay ของคุณ) ลำดับมีความสำคัญเนื่องจากวิธีสร้างแฮชริงที่สอดคล้องกัน
คุณสามารถกำหนดค่าวิธีการส่งต่อให้เป็นหนึ่งใน "การแฮชที่สอดคล้องกัน" หรือ "การแฮชแบบรวมที่สอดคล้อง" ได้ หากละเว้น ระบบจะใช้ "การแฮชที่สอดคล้องกัน" เป็นค่าเริ่มต้น การใช้ "aggregated-consistent-hashing" มักจะต้องมีไฟล์กฎให้กับคำสั่งที่เกี่ยวข้อง
ปัจจัยการจำลองควรตรงกับปัจจัยการจำลองสำหรับคลัสเตอร์
นอกจากนี้ คุณยังสามารถเลือกที่จะระบุผู้ใช้ SSH ที่จะใช้เมื่อคาร์บอเนตจำเป็นต้องเชื่อมต่อกับโหนดอื่นในคลัสเตอร์เพื่อดำเนินการ หากไม่มีการระบุ ผู้ใช้ปัจจุบันที่ดำเนินการคำสั่งจะถูกเลือก
สุดท้าย คุณสามารถระบุ HASHING_TYPE ของคลัสเตอร์ของคุณได้ ค่าเริ่มต้นคือ carbon_ch
และยังรองรับ fnv1a_ch
ด้วย โปรดทราบว่าในการใช้ fnv1a_ch
hashing คุณต้องติดตั้ง carbon
1.0.2 หรือใหม่กว่า (หรือคุณต้องใช้รีเลย์ carbon-c-relay แทน)
usage: carbon-hosts [-h] [-c CONFIG_FILE] [-C CLUSTER]
Return the addresses for all nodes in a cluster
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
usage: carbon-lookup [-h] [-c CONFIG_FILE] [-C CLUSTER] [-s] METRIC
Lookup where a metric lives in a carbon cluster
positional arguments:
METRIC Full metric name to search for
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
-a AGGREGATION_RULES, --aggregation-rules AGGREGATION_RULES
File containing rules used in conjunction with the
"aggregated-consistent-hashing" relay method (default:
/opt/graphite/conf/aggregation-rules.conf)
-s, --short Only display the address, without port and cluster
name (default: False)
usage: carbon-list [-h] [-c CONFIG_FILE] [-C CLUSTER] [-d STORAGE_DIR]
List the metrics this carbon node contains
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
-d STORAGE_DIR, --storage-dir STORAGE_DIR
Storage dir (default: /opt/graphite/storage/whisper)
usage: carbon-sieve [-h] [-c CONFIG_FILE] [-C CLUSTER] [-f METRICS_FILE]
[-n NODE] [-I]
Given a list of metrics, output those that belong to a node
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
-a AGGREGATION_RULES, --aggregation-rules AGGREGATION_RULES
File containing rules used in conjunction with the
"aggregated-consistent-hashing" relay method (default:
/opt/graphite/conf/aggregation-rules.conf)
-f METRICS_FILE, --metrics-file METRICS_FILE
File containing metric names to filter, or '-' to read
from STDIN (default: -)
-n NODE, --node NODE Filter for metrics belonging to this node (default:
self)
-I, --invert Invert the sieve, match metrics that do NOT belong to
a node (default: False)
usage: carbon-sync [-h] [-c CONFIG_FILE] [-C CLUSTER] [-f METRICS_FILE] -s
SOURCE_NODE [-d STORAGE_DIR] [-b BATCH_SIZE]
[--source-storage-dir SOURCE_STORAGE_DIR]
[--rsync-options RSYNC_OPTIONS] [--rsync-disable-copy-dest]
[--tmpdir TMP_STAGING_DIR] [--rsync-max-retries MAX_RETRIES]
[--rsync-retries-interval SECONDS] [--dirty] [-l] [-o]
Sync local metrics using remote nodes in the cluster
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (env: CARBONATE_CONFIG) (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (env: CARBONATE_CLUSTER) (default: main)
-f METRICS_FILE, --metrics-file METRICS_FILE
File containing metric names to filter, or '-' to read
from STDIN (default: -)
-s SOURCE_NODE, --source-node SOURCE_NODE
Override the source for metrics data (default: None)
-d STORAGE_DIR, --storage-dir STORAGE_DIR
Storage dir (default: /opt/graphite/storage/whisper)
-b BATCH_SIZE, --batch-size BATCH_SIZE
Batch size for the rsync job (default: 1000)
--source-storage-dir SOURCE_STORAGE_DIR
Source storage dir (default:
/opt/graphite/storage/whisper)
--rsync-options RSYNC_OPTIONS
Pass option(s) to rsync. Make sure to use "--rsync-
options=" if option starts with '-' (default: -azpS)
--rsync-disable-copy-dest
Avoid --copy-dest, transfer all whisper data between
nodes. (default: False)
--rsync-max-retries RETRIES
Number of times rsync will attempt to copy each batch
of metrics before moving on. If all retry attempts are
unsuccessful, carbon-sync will write a file containing
the name of each metric in the failed batch so they can
be easily retried at a later time. (Default: 3)
--rsync-retries-interval SECONDS
How long to wait in between each rsync retry attempt
(see --rsync-max-retries). (default: 5)
-t TMP_STAGING_DIR, --tmpdir TMP_STAGING_DIR
Specify an alternate location in which the temporary
rsync staging dirs will be created. This can be useful
for large syncs where the default location (as chosen
by mkdtemp) resides on a filesystem that's too small
to store all the metrics being copied from the remote
host.
--dirty If set, don't clean temporary rsync directory
(default: False)
-l, --lock Lock whisper files during filling (default: False)
-o, --overwrite Write all non nullpoints from src to dst (default:
False)
usage: carbon-path [-h] [-c CONFIG_FILE] [-C CLUSTER] [-f METRICS_FILE] [-r]
[-p] [-d STORAGE_DIR]
Transform metric paths to (or from) filesystem paths
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
-f METRICS_FILE, --metrics-file METRICS_FILE
File containing metric names to transform to file
paths, or '-' to read from STDIN (default: -)
-r, --reverse Transform from file paths to metric paths (default:
False)
-p, --prepend Prepend storage dir to file paths (default: False)
-d STORAGE_DIR, --storage-dir STORAGE_DIR
Whisper storage directory to prepend when -p given
(default: /opt/graphite/storage/whisper)
usage: carbon-stale [-h] [-c CONFIG_FILE] [-C CLUSTER] [-f METRICS_FILE] [-r]
[-d STORAGE_DIR] [-l HOURS] [-o HOURS] [-w] [-p]
Find and list potentially stale metrics.
optional arguments:
-h, --help show this help message and exit
-c CONFIG_FILE, --config-file CONFIG_FILE
Config file to use (default:
/opt/graphite/conf/carbonate.conf)
-C CLUSTER, --cluster CLUSTER
Cluster name (default: main)
-f METRICS_FILE, --metrics-file METRICS_FILE
File containing metric names to transform to file
paths, or '-' to read from STDIN (default: -)
-r, --reverse Output metrics which are not stale instead (default:
False)
-d STORAGE_DIR, --storage-dir STORAGE_DIR
Whisper storage directory to prepend when -p given
(default: /opt/graphite/storage/whisper)
-l HOURS, --limit HOURS
Definition of staleness, in hours (default: 24)
-o HOURS, --offset HOURS
Use a whisper data window ending HOURS ago (implies
-w) (default: 0)
-w, --whisper Use whisper data instead of filesystem stat() call
(default: False)
-p, --paths Print filesystem paths instead of metric names
(default: False)
usage: whisper-aggregate [-h] [-f METRICS_FILE] [-d STORAGE_DIR]
Set aggregation for whisper-backed metrics this carbon instance contains
optional arguments:
-h, --help show this help message and exit
-f METRICS_FILE, --metrics-file METRICS_FILE
File containing metric names and aggregation modes, or
'-' to read from STDIN (default: -)
-d STORAGE_DIR, --storage-dir STORAGE_DIR
Whisper storage directory (default:
/opt/graphite/storage/whisper)
usage: whisper-fill [-h] [-l] [-o] SRC DST
Backfill datapoints from one whisper file into another
positional arguments:
SRC Whisper source file
DST Whisper destination file
optional arguments:
-h, --help show this help message and exit
-l, --lock Lock whisper files during filling (default: False)
-o, --overwrite Write all non nullpoints from src to dst (default: False)
#!/bin/sh
#
# Resync a node from other nodes in the cluster
#
LOCAL_IP="$1"
for h in $(carbon-hosts) ; do
(
ssh $h -- carbon-list |
carbon-sieve -n $LOCAL_IP |
carbon-sync -s $h
) &
done
#!/bin/sh
#
# Rebalance a cluster from one size to another. Remember to cleanup metrics
# that no longer belong when all nodes are rebalanced!
#
LOCAL_IP="$1"
OLD_CLUSTER="old"
NEW_CLUSTER="main"
for h in $(carbon-hosts -C "$OLD_CLUSTER") ; do
ssh $h -- carbon-list |
carbon-sieve -C "$NEW_CLUSTER" -n $LOCAL_IP |
carbon-sync -s $h
done
#!/bin/sh
#
# List metrics from disk that don't belong
#
LOCAL_IP="$1"
carbon-list | carbon-sieve -I -n $LOCAL_IP
ตัวชี้วัดที่มีข้อมูลกระซิบซึ่งว่างเปล่าโดยสิ้นเชิงในช่วง 2 ชั่วโมงที่ผ่านมา (อาจมีประโยชน์หากคุณสงสัยว่ามีปัญหากับการประทับเวลา fs หรือไคลเอนต์คาร์บอนที่เขียนเป็น 'อนาคต'):
carbon-list | carbon-stale --whisper --limit=2
หน่วยวัดที่ไฟล์หน่วยวัดปรากฏว่าไม่มีการแตะต้องเป็นเวลา 48 ชั่วโมงขึ้นไป (ฟังก์ชันการทำงานเหมือนกันใน find /your/data/dir -type f -mtime +2
):
carbon-list | carbon-stale --limit=48
สิ่งที่น่าสนใจกว่านั้นคือถ้าคุณใช้ carbon-stale
จากนั้นกรองเพื่อระบุตัวชี้วัดเก่าที่ไม่ได้อยู่ในนี้ (เทียบกับตัวชี้วัดที่ไม่เก่า ซึ่ง อยู่ที่นี่ แต่ถูกรายงานอย่างไม่ถูกต้องในตะแกรงคาร์บอนเนื่องจากสิ่งต่าง ๆ เช่นระยะเวลาที่เพิ่มขึ้นสองเท่าในเส้นทางตัวชี้วัด เนื่องจากนักสะสมพัง..)
carbon-list | carbon-stale --limit=48 | carbon-sieve -I -n $LOCAL_IP
หากต้องการพิมพ์เส้นทางของไฟล์เพื่อใช้กับเช่น xargs rm
หรืออะไรก็ตาม ให้ใช้ -p
:
carbon-list | carbon-stale -p | xargs -n 100 rm
รหัสนี้มีให้ภายใต้ใบอนุญาต MIT