-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use nwpc-hpc-model in PI disk space exporter. fix #9
set labels in config file. #4
- Loading branch information
1 parent
3181753
commit dde57e0
Showing
5 changed files
with
148 additions
and
61 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# coding: utf-8 | ||
|
||
from nwpc_hpc_model.base.query_item import get_property_data | ||
from nwpc_hpc_exporter.disk_space.collector import BaseCollector | ||
|
||
from .request import get_disk_space | ||
|
||
|
||
class Collector(BaseCollector): | ||
def __init__(self, collector_config): | ||
BaseCollector.__init__(self, collector_config) | ||
|
||
def process_single_task(self, task): | ||
client = task['client'] | ||
category_list = task['category_list'] | ||
|
||
disk_space_result_model = get_disk_space(category_list, client) | ||
for an_item in disk_space_result_model.items: | ||
for a_gauge in self.gauge_list: | ||
labels = {} | ||
for a_label_config in self.gauge_label_config: | ||
label_name = a_label_config['name'] | ||
label_type = a_label_config['type'] | ||
if label_type == "task": | ||
config_key = a_label_config['config_key'] | ||
labels[label_name] = task[config_key] | ||
elif label_type == "category": | ||
category_id = a_label_config['category_id'] | ||
labels[label_name] = get_property_data(an_item, category_id) | ||
else: | ||
raise Exception("label type not supported:", label_type) | ||
|
||
a_gauge['metric'].labels(**labels).set( | ||
get_property_data(an_item, a_gauge['category_id'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# coding: utf-8 | ||
from paramiko import SSHClient | ||
from nwpc_hpc_exporter.base.run import run_command | ||
from nwpc_hpc_model.disk_space.pi import PiDiskSpaceCategoryList, PiDiskSpaceQueryModel | ||
|
||
|
||
def run_df_command(client) -> (str, str): | ||
command = 'df -m' | ||
return run_command(client, command) | ||
|
||
|
||
def get_disk_space(category_list: dict, client: SSHClient) -> PiDiskSpaceQueryModel: | ||
std_out_string, std_error_out_string = run_df_command(client) | ||
result_lines = std_out_string.split("\n") | ||
|
||
category_list = PiDiskSpaceCategoryList.build_from_config(category_list) | ||
model = PiDiskSpaceQueryModel.build_from_category_list(result_lines, category_list) | ||
|
||
return model |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
nwpc_hpc_exporter/disk_space/conf/pi_disk_space.config.sample.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
global: | ||
exporter: | ||
port: port number | ||
auth: | ||
host: some host | ||
port: port number | ||
user: user name | ||
password: password | ||
|
||
collector: | ||
type: pi | ||
metric: | ||
gauge_label: | ||
- | ||
name: owner | ||
type: task | ||
config_key: owner | ||
- | ||
name: repo | ||
type: task | ||
config_key: repo | ||
- | ||
name: file_system | ||
type: category | ||
category_id: "disk_space.mounted_on" | ||
|
||
gauge_list: | ||
- | ||
name: hpc_pi_disk_space_total_size_mb | ||
category_id: "disk_space.blocks.total_size_mb" | ||
- | ||
name: hpc_pi_disk_space_used_size_mb | ||
category_id: "disk_space.blocks.used_size_mb" | ||
- | ||
name: hpc_pi_disk_space_available_size_mb | ||
category_id: "disk_space.blocks.available_size_mb" | ||
|
||
category_list: | ||
- | ||
id: "disk_space.file_system" | ||
display_name: Filesystem | ||
label: Filesystem | ||
record_parser_class: RegexGroupParser | ||
record_parser_arguments: | ||
- 1 | ||
value_saver_class: StringSaver | ||
value_saver_arguments: [] | ||
- | ||
id: "disk_space.blocks.total_size_mb" | ||
display_name: "Total size (MB)" | ||
label: "1M-Blocks" | ||
record_parser_class: RegexGroupParser | ||
record_parser_arguments: | ||
- 2 | ||
value_saver_class: NumberSaver | ||
value_saver_arguments: [] | ||
- | ||
id: "disk_space.blocks.used_size_mb" | ||
display_name: "Used size (MB)" | ||
label: "Used" | ||
record_parser_class: RegexGroupParser | ||
record_parser_arguments: | ||
- 3 | ||
value_saver_class: NumberSaver | ||
value_saver_arguments: [] | ||
- | ||
id: "disk_space.blocks.available_size_mb" | ||
display_name: "Available size (MB)" | ||
label: "Available" | ||
record_parser_class: RegexGroupParser | ||
record_parser_arguments: | ||
- 4 | ||
value_saver_class: NumberSaver | ||
value_saver_arguments: [] | ||
- | ||
id: "disk_space.mounted_on" | ||
display_name: "Mounted on" | ||
label: "Mounted on" | ||
record_parser_class: RegexGroupParser | ||
record_parser_arguments: | ||
- 6 | ||
value_saver_class: StringSaver | ||
value_saver_arguments: [] | ||
|
||
|
||
tasks: | ||
- | ||
owner: owner | ||
repo: repo |