Skip to content

Commit

Permalink
Add sst_file_count and store_size metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Maquet committed Apr 4, 2016
1 parent 61b2a58 commit 5ba3750
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
36 changes: 35 additions & 1 deletion rocksdb_prometheus_exporter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def metric_name_escape(name):
return name.replace(".", "_").replace("-", "_").replace(" ", "_")

def incrementAbsPathGaugeValue(name, abs_path, amount, description = ""):
def abs_path_to_labels(abs_path):
labels = [ "dir_abs_path" ]
label_values = [ abs_path ]
i = 0
Expand All @@ -28,6 +28,10 @@ def incrementAbsPathGaugeValue(name, abs_path, amount, description = ""):
labels += [ 'dir_%d' % i ]
label_values += [ basename ]
i += 1
return labels, label_values

def incrementAbsPathGaugeValue(name, abs_path, amount, description = ""):
labels, label_values = abs_path_to_labels(abs_path)
incrementGaugeValue(name, labels, label_values, amount, description)

def incrementGaugeValue(name, labels, label_values, amount, description = ""):
Expand All @@ -42,6 +46,22 @@ def incrementGaugeValue(name, labels, label_values, amount, description = ""):
GAUGES[name].inc(amount)
GAUGES_LAST_UPDATE[name] = time.time()

def setAbsPathGaugeValue(name, abs_path, value, description =""):
labels, label_values = abs_path_to_labels(abs_path)
setGaugeValue(name, labels, label_values, value, description)

def setGaugeValue(name, labels, label_values, value, description =""):
with GAUGES_LOCK:
name = metric_name_escape(name)
if name not in GAUGES:
GAUGES[name] = Gauge(name, description, labels)
if labels:
GAUGES[name].labels(*label_values).set(value)
GAUGES_LABELS_LAST_UPDATE[(name, tuple(label_values))] = time.time()
else:
GAUGES[name].set(value)
GAUGES_LAST_UPDATE[name] = time.time()

def set_gauges_ttl(ttl):
global GAUGES_TTL
if ttl is not None: GAUGES_TTL = ttl
Expand Down Expand Up @@ -78,6 +98,18 @@ def ttl_watchdog():
def file_extension(path):
return os.path.splitext(path)[1]

def update_sst_file_count_metric(dir_abs_path, current_sst_abspaths):
setAbsPathGaugeValue("rocksdb:sst_file_count", dir_abs_path, len(current_sst_abspaths))

def update_store_size_metric(dir_abs_path, current_sst_abspaths):
store_size = 0
for path in current_sst_abspaths:
try:
store_size += os.stat(path).st_size
except OSError:
continue
setAbsPathGaugeValue("rocksdb:store_size", dir_abs_path, store_size)

def update_bytes_written_metric(dir_abs_path, sst_abspath):
try:
sst_file_size = os.stat(sst_abspath).st_size
Expand All @@ -103,6 +135,8 @@ def update_rocksdb_metrics(dir_paths):
for sst_basename in os.listdir(dir_path)
if file_extension(sst_basename) == '.sst'
])
update_sst_file_count_metric(dir_abs_path, current_sst_abspaths)
update_store_size_metric(dir_abs_path, current_sst_abspaths)
for sst_abspath in current_sst_abspaths:
update_bytes_written_metric(dir_abs_path, sst_abspath)
for sst_abspath in [ path for path in SST_ABSPATH_TO_SIZE_IN_BYTES.keys() if path.startswith(dir_abs_path) ]:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='rocksdb-prometheus-exporter',
version='0.3.0',
version='0.4.0',
description='RocksDB Prometheus exporter',
url='https://github.com/movio/rocksdb-prometheus-exporter',
author='Nicolas Maquet',
Expand Down

0 comments on commit 5ba3750

Please sign in to comment.