annotate tasks.py @ 61:fb0519859645

better py configs
author drewp@bigasterisk.com
date Thu, 02 May 2024 18:35:46 -0700
parents e3151ab43579
children 8134cd480817
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
20
f5777b65f035 fast update of scrape_main.yaml
drewp@bigasterisk.com
parents: 15
diff changeset
2 import yaml
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
3 from invoke import task
20
f5777b65f035 fast update of scrape_main.yaml
drewp@bigasterisk.com
parents: 15
diff changeset
4 from kubernetes import config
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
5
22
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
6 import alert_rules
27
eec015e90818 reformat
drewp@bigasterisk.com
parents: 22
diff changeset
7 from k8s_ops import firstPodName, refreshPodCmaps, replaceCmap
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
8
20
f5777b65f035 fast update of scrape_main.yaml
drewp@bigasterisk.com
parents: 15
diff changeset
9 config.load_kube_config()
12
b6720e379d5b config updates
drewp@bigasterisk.com
parents: 10
diff changeset
10
b6720e379d5b config updates
drewp@bigasterisk.com
parents: 10
diff changeset
11
22
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
12 @task
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
13 def push_config(ctx):
32
eb1de82c93aa refactor the merging of all the groups
drewp@bigasterisk.com
parents: 27
diff changeset
14 rulesObj = alert_rules.allRules(ctx)
10
2023a6ce7bc0 some of the config-rebuild code
drewp@bigasterisk.com
parents: 4
diff changeset
15
54
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
16 replaceCmap("victoriametrics-config", {
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
17 "scrape_main": scrapeConfig("config/scrape_main.yaml"),
58
0064c490c33d some tiny scrape configs for testing multi-node vmstorage/vmselect
drewp@bigasterisk.com
parents: 54
diff changeset
18 "scrape_recent": scrapeConfig("config/scrape_recent.yaml"),
0064c490c33d some tiny scrape configs for testing multi-node vmstorage/vmselect
drewp@bigasterisk.com
parents: 54
diff changeset
19 "scrape_forever": scrapeConfig("config/scrape_forever.yaml"),
54
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
20 "rules": rulesObj,
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
21 })
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
22
34
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
23 # these don't give errors on rules format! they just quietly keep the old
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
24 # rules! use `skaffold run` to get errs.
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
25 #
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
26 # or run
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
27 # validateTemplates = flag.Bool("rule.validateTemplates", true, "Whether to validate annotation and label templates")
54
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
28 # validateExpressions = flag.Bool("rule.validateExpressions", true, "Whether to validate rules expressions via MetricsQL engine")
34
3b91d52b007d rules tuning
drewp@bigasterisk.com
parents: 32
diff changeset
29
22
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
30 refreshPodCmaps(firstPodName("app=victoriametrics"))
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
31 refreshPodCmaps(firstPodName("app=vmalert"))
4
1eb6e6a2b9b6 version control configs finally; use configmaps to present them to VM
drewp@bigasterisk.com
parents:
diff changeset
32
22
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
33 # If the VM reloader isn't fast enough, we could do this too:
cd115f1ca2a8 use configmaps and a special pod refresh trick
drewp@bigasterisk.com
parents: 20
diff changeset
34 # hup(ctx, 'deploy/victoriametrics', 'victoria-metrics-prod')
20
f5777b65f035 fast update of scrape_main.yaml
drewp@bigasterisk.com
parents: 15
diff changeset
35
f5777b65f035 fast update of scrape_main.yaml
drewp@bigasterisk.com
parents: 15
diff changeset
36
60
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
37 @task
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
38 def push_config_2024(ctx):
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
39 # plan:
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
40 # every discovered service may:
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
41 # - be described here as a forever retention - ignore the discovery
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
42 # - be blocked here as a no-metrics service - ignore the discovery
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
43 # - be scraped as 'recent', with possible overrides of port/path
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
44 # all per-node metrics shall be 'recent' (oops, not smartctl!)
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
45 map: dict[str, object] = {
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
46 'rules': alert_rules.allRules(ctx),
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
47 }
61
fb0519859645 better py configs
drewp@bigasterisk.com
parents: 60
diff changeset
48 top=Path('config/build/scrape_jobs')
fb0519859645 better py configs
drewp@bigasterisk.com
parents: 60
diff changeset
49 for p in top.glob('**/*.yaml'):
fb0519859645 better py configs
drewp@bigasterisk.com
parents: 60
diff changeset
50 map[str(p.relative_to(top))] = scrapeConfig(p)
60
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
51 replaceCmap("next-victoriametrics-config", map)
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
52 refreshPodCmaps(firstPodName("app=next-victoriametrics-forever-vmagent"))
61
fb0519859645 better py configs
drewp@bigasterisk.com
parents: 60
diff changeset
53 refreshPodCmaps(firstPodName("app=next-victoriametrics-recent-vmagent"))
60
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
54
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
55
54
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
56 def scrapeConfig(fn):
21185db8a52e refactor
drewp@bigasterisk.com
parents: 34
diff changeset
57 return yaml.load(open(fn), yaml.FullLoader)
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
58
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
60 metricsToMigrate = [
60
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
61 'currently_on_wifi',
e3151ab43579 moving scrape target configs in py, and into separate retention classes
drewp@bigasterisk.com
parents: 59
diff changeset
62 'connected',
59
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
63 'house_power_kwh',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
64 'house_power_price',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
65 'house_power_w',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
66 'lan_bytes_sent_from_created',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
67 'lan_bytes_sent_from_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
68 'lan_last_seen_time',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
69 'maildir_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
70 'mongodb_mongod_db_coll_avgobjsize',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
71 'mongodb_mongod_db_coll_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
72 'mongodb_mongod_db_coll_index_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
73 'mongodb_mongod_db_coll_indexes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
74 'mongodb_mongod_db_coll_indexes_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
75 'mongodb_mongod_db_coll_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
76 'mongodb_mongod_db_coll_storage_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
77 'mongodb_mongod_db_collections_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
78 'mongodb_mongod_db_data_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
79 'mongodb_mongod_db_index_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
80 'mongodb_mongod_db_indexes_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
81 'mongodb_mongod_db_objects_total',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
82 'probe_duration_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
83 'smartctl_device',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
84 'smartctl_device_attribute',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
85 'smartctl_device_available_spare',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
86 'smartctl_device_available_spare_threshold',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
87 'smartctl_device_block_size',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
88 'smartctl_device_bytes_read',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
89 'smartctl_device_bytes_written',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
90 'smartctl_device_capacity_blocks',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
91 'smartctl_device_capacity_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
92 'smartctl_device_critical_warning',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
93 'smartctl_device_interface_speed',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
94 'smartctl_device_media_errors',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
95 'smartctl_device_num_err_log_entries',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
96 'smartctl_device_percentage_used',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
97 'smartctl_device_power_cycle_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
98 'smartctl_device_power_on_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
99 'smartctl_device_smart_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
100 'smartctl_device_smartctl_exit_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
101 'smartctl_device_status',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
102 'smartctl_device_temperature',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
103 'zfs_dataset_logical_used_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
104 'zfs_dataset_referenced_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
105 'zfs_dataset_used_by_dataset_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
106 'zfs_dataset_used_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
107 'zfs_dataset_written_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
108 'zfs_exporter_build_info',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
109 'zfs_pool_allocated_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
110 'zfs_pool_deduplication_ratio',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
111 'zfs_pool_fragmentation_ratio',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
112 'zfs_pool_free_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
113 'zfs_pool_freeing_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
114 'zfs_pool_health',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
115 'zfs_pool_leaked_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
116 'zfs_pool_readonly',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
117 'zfs_pool_size_bytes',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
118 'zfs_scrape_collector_duration_seconds',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
119 'zfs_scrape_collector_success',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
120 'zigbee_availability',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
121 'zigbee_battery',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
122 'zigbee_brightness',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
123 'zigbee_contact',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
124 'zigbee_link_quality',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
125 'zigbee_occupancy',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
126 'zpool_device_error_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
127 'zpool_device_state',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
128 'zpool_error_count',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
129 'zpool_state',
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
130 ]
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
131
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
132
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
133 @task
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
134 def exportForeverMetrics(ctx):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
135 svc = ctx.run('khost victoriametrics').stdout
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
136 for m in metricsToMigrate:
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
137 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
138
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
139
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
140 @task
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
141 def ingestForeverMetrics(ctx):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
142 svc = ctx.run('khost next-victoriametrics-forever-vminsert').stdout
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
143 for p in Path('export').glob('*.native.gz'):
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
144 print(f'importing {p}')
6a357b483c04 migration tasks for new layout
drewp@bigasterisk.com
parents: 58
diff changeset
145 ctx.run(f'zcat {p} | curl -s http://{svc}/m/next/forever/vminsert/insert/0/prometheus/api/v1/import/native --data-binary @-')