annotate migration/tasks.py @ 63:84a4c4cca4a5

separate the migration tasks
author drewp@bigasterisk.com
date Thu, 02 May 2024 23:05:14 -0700
parents tasks.py@8134cd480817
children c5e98d891638
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
1 from pathlib import Path
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
2
63
84a4c4cca4a5 separate the migration tasks
drewp@bigasterisk.com
parents: 62
diff changeset
3 from invoke import task
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
4
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
5
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
6 metricsToMigrate = [
60
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
7 'currently_on_wifi',
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
8 'connected',
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
9 'house_power_kwh',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
10 'house_power_price',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
11 'house_power_w',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
12 'lan_bytes_sent_from_created',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
13 'lan_bytes_sent_from_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
14 'lan_last_seen_time',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
15 'maildir_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
16 'mongodb_mongod_db_coll_avgobjsize',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
17 'mongodb_mongod_db_coll_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
18 'mongodb_mongod_db_coll_index_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
19 'mongodb_mongod_db_coll_indexes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
20 'mongodb_mongod_db_coll_indexes_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
21 'mongodb_mongod_db_coll_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
22 'mongodb_mongod_db_coll_storage_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
23 'mongodb_mongod_db_collections_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
24 'mongodb_mongod_db_data_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
25 'mongodb_mongod_db_index_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
26 'mongodb_mongod_db_indexes_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
27 'mongodb_mongod_db_objects_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
28 'probe_duration_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
29 'smartctl_device',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
30 'smartctl_device_attribute',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
31 'smartctl_device_available_spare',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
32 'smartctl_device_available_spare_threshold',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
33 'smartctl_device_block_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
34 'smartctl_device_bytes_read',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
35 'smartctl_device_bytes_written',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
36 'smartctl_device_capacity_blocks',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
37 'smartctl_device_capacity_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
38 'smartctl_device_critical_warning',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
39 'smartctl_device_interface_speed',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
40 'smartctl_device_media_errors',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
41 'smartctl_device_num_err_log_entries',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
42 'smartctl_device_percentage_used',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
43 'smartctl_device_power_cycle_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
44 'smartctl_device_power_on_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
45 'smartctl_device_smart_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
46 'smartctl_device_smartctl_exit_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
47 'smartctl_device_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
48 'smartctl_device_temperature',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
49 'zfs_dataset_logical_used_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
50 'zfs_dataset_referenced_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
51 'zfs_dataset_used_by_dataset_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
52 'zfs_dataset_used_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
53 'zfs_dataset_written_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
54 'zfs_exporter_build_info',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
55 'zfs_pool_allocated_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
56 'zfs_pool_deduplication_ratio',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
57 'zfs_pool_fragmentation_ratio',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
58 'zfs_pool_free_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
59 'zfs_pool_freeing_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
60 'zfs_pool_health',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
61 'zfs_pool_leaked_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
62 'zfs_pool_readonly',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
63 'zfs_pool_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
64 'zfs_scrape_collector_duration_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
65 'zfs_scrape_collector_success',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
66 'zigbee_availability',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
67 'zigbee_battery',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
68 'zigbee_brightness',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
69 'zigbee_contact',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
70 'zigbee_link_quality',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
71 'zigbee_occupancy',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
72 'zpool_device_error_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
73 'zpool_device_state',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
74 'zpool_error_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
75 'zpool_state',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
76 ]
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
77
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
78
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
79 @task
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
80 def exportForeverMetrics(ctx):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
81 svc = ctx.run('khost victoriametrics').stdout
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
82 for m in metricsToMigrate:
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
83 ctx.run(f'curl http://{svc}/m/api/v1/export/native?match={m} | gzip -c > export/{m}.native.gz')
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
84
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
85
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
86 @task
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
87 def ingestForeverMetrics(ctx):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
88 svc = ctx.run('khost next-victoriametrics-forever-vminsert').stdout
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
89 for p in Path('export').glob('*.native.gz'):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
90 print(f'importing {p}')
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
91 ctx.run(f'zcat {p} | curl -s http://{svc}/m/next/forever/vminsert/insert/0/prometheus/api/v1/import/native --data-binary @-')