Skip to content

Commit

Permalink
use nwpc-hpc-model in PI disk space exporter. fix #9
Browse files Browse the repository at this point in the history
set labels in config file. #4
  • Loading branch information
perillaroc committed Jul 24, 2018
1 parent 3181753 commit dde57e0
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 61 deletions.
55 changes: 0 additions & 55 deletions nwpc_hpc_exporter/disk_space/collector/linux/__init__.py

This file was deleted.

34 changes: 34 additions & 0 deletions nwpc_hpc_exporter/disk_space/collector/pi/__init__.py
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']))
19 changes: 19 additions & 0 deletions nwpc_hpc_exporter/disk_space/collector/pi/request.py
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ global:
password: password

collector:
type: aix # or linux
type: aix # or pi
metric:
gauge_label:
-
Expand All @@ -26,13 +26,13 @@ collector:

gauge_list:
-
name: hpc_aix_total_size_gb
name: hpc_aix_disk_space_total_size_gb
category_id: "disk_space.blocks.total_size_gb"
-
name: hpc_aix_free_size_gb
name: hpc_aix_disk_space_free_size_gb
category_id: "disk_space.blocks.free_size_gb"
-
name: hpc_aix_space_inode_used
name: hpc_aix_disk_space_inode_used
category_id: "disk_space.inode.used"

category_list:
Expand Down Expand Up @@ -85,5 +85,5 @@ collector:

tasks:
-
owner: nwp_xp
repo: aix
owner: owner
repo: repo
89 changes: 89 additions & 0 deletions nwpc_hpc_exporter/disk_space/conf/pi_disk_space.config.sample.yml
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

0 comments on commit dde57e0

Please sign in to comment.