diff tasks.py @ 59:6a357b483c04

migration tasks for new layout
author drewp@bigasterisk.com
date Fri, 26 Apr 2024 23:37:14 -0700
parents 0064c490c33d
children e3151ab43579
line wrap: on
line diff
--- a/tasks.py	Fri Apr 26 15:48:22 2024 -0700
+++ b/tasks.py	Fri Apr 26 23:37:14 2024 -0700
@@ -1,3 +1,4 @@
+from pathlib import Path
 import yaml
 from invoke import task
 from kubernetes import config
@@ -35,3 +36,89 @@
 
 def scrapeConfig(fn):
     return yaml.load(open(fn), yaml.FullLoader)
+
+
+metricsToMigrate = [
+    'house_power_kwh',
+    'house_power_price',
+    'house_power_w',
+    'lan_bytes_sent_from_created',
+    'lan_bytes_sent_from_total',
+    'lan_last_seen_time',
+    'maildir_count',
+    'mongodb_mongod_db_coll_avgobjsize',
+    'mongodb_mongod_db_coll_count',
+    'mongodb_mongod_db_coll_index_size',
+    'mongodb_mongod_db_coll_indexes',
+    'mongodb_mongod_db_coll_indexes_size',
+    'mongodb_mongod_db_coll_size',
+    'mongodb_mongod_db_coll_storage_size',
+    'mongodb_mongod_db_collections_total',
+    'mongodb_mongod_db_data_size_bytes',
+    'mongodb_mongod_db_index_size_bytes',
+    'mongodb_mongod_db_indexes_total',
+    'mongodb_mongod_db_objects_total',
+    'probe_duration_seconds',
+    'smartctl_device',
+    'smartctl_device_attribute',
+    'smartctl_device_available_spare',
+    'smartctl_device_available_spare_threshold',
+    'smartctl_device_block_size',
+    'smartctl_device_bytes_read',
+    'smartctl_device_bytes_written',
+    'smartctl_device_capacity_blocks',
+    'smartctl_device_capacity_bytes',
+    'smartctl_device_critical_warning',
+    'smartctl_device_interface_speed',
+    'smartctl_device_media_errors',
+    'smartctl_device_num_err_log_entries',
+    'smartctl_device_percentage_used',
+    'smartctl_device_power_cycle_count',
+    'smartctl_device_power_on_seconds',
+    'smartctl_device_smart_status',
+    'smartctl_device_smartctl_exit_status',
+    'smartctl_device_status',
+    'smartctl_device_temperature',
+    'zfs_dataset_logical_used_bytes',
+    'zfs_dataset_referenced_bytes',
+    'zfs_dataset_used_by_dataset_bytes',
+    'zfs_dataset_used_bytes',
+    'zfs_dataset_written_bytes',
+    'zfs_exporter_build_info',
+    'zfs_pool_allocated_bytes',
+    'zfs_pool_deduplication_ratio',
+    'zfs_pool_fragmentation_ratio',
+    'zfs_pool_free_bytes',
+    'zfs_pool_freeing_bytes',
+    'zfs_pool_health',
+    'zfs_pool_leaked_bytes',
+    'zfs_pool_readonly',
+    'zfs_pool_size_bytes',
+    'zfs_scrape_collector_duration_seconds',
+    'zfs_scrape_collector_success',
+    'zigbee_availability',
+    'zigbee_battery',
+    'zigbee_brightness',
+    'zigbee_contact',
+    'zigbee_link_quality',
+    'zigbee_occupancy',
+    'zpool_device_error_count',
+    'zpool_device_state',
+    'zpool_error_count',
+    'zpool_state',
+]
+
+
+@task
+def exportForeverMetrics(ctx):
+    svc = ctx.run('khost victoriametrics').stdout
+    for m in metricsToMigrate:
+        ctx.run(f'curl http://{svc}/m/api/v1/export/native?match={m} | gzip -c > export/{m}.native.gz')
+
+
+@task
+def ingestForeverMetrics(ctx):
+    svc = ctx.run('khost next-victoriametrics-forever-vminsert').stdout
+    for p in Path('export').glob('*.native.gz'):
+        print(f'importing {p}')
+        ctx.run(f'zcat {p} | curl -s http://{svc}/m/next/forever/vminsert/insert/0/prometheus/api/v1/import/native --data-binary @-')