Skip to content

Commit

Permalink
Fix metrics decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
kysre committed Feb 11, 2024
1 parent 0c152d4 commit cc346fd
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions datanode/src/datanode_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,38 @@
throughput = Histogram('disk_total_size', 'Total size of disk', labelnames=["provider"], _labelvalues=[ConfigManager.get_prop('datanode_name')])


# DECORATORS{
def inc_message_count(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
message_count.labels(provider=ConfigManager.get_prop('datanode_name')).inc()
message_count.inc()
return result
return wrapper


def dec_message_count(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
message_count.labels(provider=ConfigManager.get_prop('datanode_name')).dec()
message_count.dec()
return result
return wrapper


def set_message_count(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
message_count.labels(provider=ConfigManager.get_prop('datanode_name')).set(result)
message_count.set(result)
return result
return wrapper


def get_disk_info_decorator(func):
def wrapper():
result = func()
def wrapper(*args, **kwargs):
path = ConfigManager.get_prop('partition_home_path')
st = os.statvfs(path)
total = st.f_blocks * st.f_frsize
used = (st.f_blocks - st.f_bfree) * st.f_frsize
disk_total_size.labels(provider=ConfigManager.get_prop('datanode_name')).set(total)
disk_total_size.labels(provider=ConfigManager.get_prop('datanode_name')).set(used)
return result
disk_total_size.set(total)
disk_total_size.set(used)
return wrapper


Expand Down Expand Up @@ -173,6 +170,7 @@ def push_to_partition(partition_index: int,


def serve():
# Start metrics server
start_http_server(9000)

port = ConfigManager.get_prop('server_port')
Expand Down

0 comments on commit cc346fd

Please sign in to comment.