asyncvictoria 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. asyncvictoria-0.7.1/.gitignore +8 -0
  2. asyncvictoria-0.7.1/.pylintrc +3 -0
  3. asyncvictoria-0.7.1/MIGRATION.md +224 -0
  4. asyncvictoria-0.7.1/Makefile +12 -0
  5. asyncvictoria-0.7.1/PKG-INFO +40 -0
  6. asyncvictoria-0.7.1/README.rst +20 -0
  7. asyncvictoria-0.7.1/asyncvictoria/__init__.py +16 -0
  8. asyncvictoria-0.7.1/asyncvictoria/_impl.py +429 -0
  9. asyncvictoria-0.7.1/asyncvictoria/buffered.py +274 -0
  10. asyncvictoria-0.7.1/asyncvictoria/collectd.py +628 -0
  11. asyncvictoria-0.7.1/asyncvictoria/mock.py +134 -0
  12. asyncvictoria-0.7.1/asyncvictoria/model.py +260 -0
  13. asyncvictoria-0.7.1/asyncvictoria/sanitize.py +115 -0
  14. asyncvictoria-0.7.1/asyncvictoria.egg-info/PKG-INFO +40 -0
  15. asyncvictoria-0.7.1/asyncvictoria.egg-info/SOURCES.txt +30 -0
  16. asyncvictoria-0.7.1/asyncvictoria.egg-info/dependency_links.txt +1 -0
  17. asyncvictoria-0.7.1/asyncvictoria.egg-info/requires.txt +3 -0
  18. asyncvictoria-0.7.1/asyncvictoria.egg-info/top_level.txt +1 -0
  19. asyncvictoria-0.7.1/examples/cfg.yaml.sample +5 -0
  20. asyncvictoria-0.7.1/examples/do_collectd.py +228 -0
  21. asyncvictoria-0.7.1/examples/do_mysql.py +105 -0
  22. asyncvictoria-0.7.1/examples/do_rrd.py +221 -0
  23. asyncvictoria-0.7.1/examples/power_prices.py +55 -0
  24. asyncvictoria-0.7.1/migrate_from_akumuli.py +285 -0
  25. asyncvictoria-0.7.1/pyproject.toml +165 -0
  26. asyncvictoria-0.7.1/setup.cfg +4 -0
  27. asyncvictoria-0.7.1/tests/__init__.py +0 -0
  28. asyncvictoria-0.7.1/tests/conftest.py +3 -0
  29. asyncvictoria-0.7.1/tests/test_basic.py +38 -0
  30. asyncvictoria-0.7.1/tests/test_migration.py +209 -0
  31. asyncvictoria-0.7.1/tests/test_migration_script.py +262 -0
  32. asyncvictoria-0.7.1/tests/test_sanitization.py +239 -0
@@ -0,0 +1,8 @@
1
+ /cfg.yaml
2
+ __pycache__
3
+ /.pybuild/
4
+ /asyncakumuli.egg-info/
5
+ /dist/
6
+ /.eggs/
7
+ /build/
8
+ /debian/
@@ -0,0 +1,3 @@
1
+ [MESSAGES CONTROL]
2
+ disable=bad-continuation,invalid-name,unnecessary-pass,protected-access,fixme,broad-except,no-absolute-import,global-statement,C,R
3
+
@@ -0,0 +1,224 @@
1
+ # Migrating from Akumuli to VictoriaMetrics
2
+
3
+ This document describes how to migrate your data from Akumuli to VictoriaMetrics.
4
+
5
+ ## Prerequisites
6
+
7
+ 1. Both `asyncakumuli` and `asyncvictoria` packages installed:
8
+ ```bash
9
+ pip install asyncakumuli
10
+ pip install asyncvictoria
11
+ ```
12
+
13
+ 2. Access to your running Akumuli instance
14
+
15
+ 3. A running VictoriaMetrics instance with OpenTSDB protocol enabled
16
+
17
+ ## Starting VictoriaMetrics
18
+
19
+ VictoriaMetrics needs to be started with OpenTSDB protocol support:
20
+
21
+ ```bash
22
+ victoria-metrics \
23
+ -storageDataPath=/path/to/data \
24
+ -httpListenAddr=:8428 \
25
+ -opentsdbListenAddr=:4242
26
+ ```
27
+
28
+ Where:
29
+ - `-httpListenAddr` specifies the port for HTTP queries (default: 8428)
30
+ - `-opentsdbListenAddr` specifies the port for OpenTSDB telnet protocol data ingestion (default: 4242)
31
+
32
+ ## Migration Methods
33
+
34
+ ### Method 1: Using the Migration Script
35
+
36
+ The `migrate_from_akumuli.py` script automates the migration process.
37
+
38
+ #### Option A: Auto-discover series from Akumuli database
39
+
40
+ The script can automatically discover all series by reading Akumuli's SQLite database:
41
+
42
+ ```bash
43
+ python migrate_from_akumuli.py \
44
+ --akumuli-http http://localhost:8181 \
45
+ --akumuli-db /path/to/akumuli/db.akumuli \
46
+ --victoria-tcp localhost:4242 \
47
+ --victoria-http http://localhost:8428 \
48
+ --start-time 1500000000 \
49
+ --end-time 1600000000
50
+ ```
51
+
52
+ #### Option B: Specify series manually
53
+
54
+ Alternatively, you can specify which series to migrate:
55
+
56
+ ```bash
57
+ python migrate_from_akumuli.py \
58
+ --akumuli-http http://localhost:8181 \
59
+ --victoria-tcp localhost:4242 \
60
+ --victoria-http http://localhost:8428 \
61
+ --series "cpu_usage{host=server1}" \
62
+ --series "memory_usage{host=server1}" \
63
+ --start-time 1500000000 \
64
+ --end-time 1600000000
65
+ ```
66
+
67
+ #### Options:
68
+ - `--akumuli-http`: Akumuli HTTP endpoint (default: http://localhost:8181)
69
+ - `--akumuli-db`: Path to Akumuli's SQLite database (db.akumuli) for auto-discovering series
70
+ - `--victoria-tcp`: VictoriaMetrics OpenTSDB TCP endpoint (default: localhost:4242)
71
+ - `--victoria-http`: VictoriaMetrics HTTP endpoint (default: http://localhost:8428)
72
+ - `--series`: Series to migrate (can be specified multiple times)
73
+ - Format: `"series_name"` or `"series_name{tag1=val1,tag2=val2}"`
74
+ - `--start-time`: Optional start timestamp (Unix timestamp in seconds)
75
+ - `--end-time`: Optional end timestamp (Unix timestamp in seconds)
76
+
77
+ **Note:** Either `--series` or `--akumuli-db` must be specified.
78
+
79
+ ### Method 2: Programmatic Migration
80
+
81
+ You can also write your own migration script:
82
+
83
+ ```python
84
+ import anyio
85
+ import httpx
86
+ from asyncakumuli import get_data as akumuli_get_data
87
+ from asyncvictoria import connect as victoria_connect, Entry as VEntry, DS
88
+
89
+ async def migrate():
90
+ async with httpx.AsyncClient(timeout=600) as akumuli_session:
91
+ async with victoria_connect(host="localhost", port=4242) as victoria:
92
+ # Read from Akumuli
93
+ data = akumuli_get_data(
94
+ akumuli_session,
95
+ series="cpu_usage",
96
+ tags={"host": "server1"},
97
+ t_start=1500000000,
98
+ t_end=1600000000,
99
+ url="http://localhost:8181/api/query"
100
+ )
101
+
102
+ # Write to VictoriaMetrics
103
+ count = 0
104
+ async for entry in data:
105
+ ve = VEntry(
106
+ series=entry.series,
107
+ time=entry.time,
108
+ value=entry.value,
109
+ tags=entry.tags,
110
+ mode=DS.gauge
111
+ )
112
+ await victoria.put(ve)
113
+ count += 1
114
+
115
+ if count % 1000 == 0:
116
+ await victoria.flush()
117
+ print(f"Migrated {count} points...")
118
+
119
+ await victoria.flush()
120
+ print(f"Migration complete: {count} points")
121
+
122
+ anyio.run(migrate)
123
+ ```
124
+
125
+ ## Key Differences Between Akumuli and VictoriaMetrics
126
+
127
+ ### Data Format
128
+
129
+ **Akumuli** uses a custom RESP (Redis Serialization Protocol) format:
130
+ ```
131
+ series_name tag1=value1 tag2=value2
132
+ timestamp
133
+ value
134
+ ```
135
+
136
+ **VictoriaMetrics** uses OpenTSDB telnet protocol format:
137
+ ```
138
+ put series_name timestamp value tag1=value1 tag2=value2
139
+ ```
140
+
141
+ ### Querying
142
+
143
+ **Akumuli** uses a JSON-based query API:
144
+ ```json
145
+ {
146
+ "select": "cpu_usage",
147
+ "where": {"host": "server1"},
148
+ "range": {"from": "20210101T000000", "to": "20210201T000000"}
149
+ }
150
+ ```
151
+
152
+ **VictoriaMetrics** uses PromQL-compatible queries:
153
+ ```
154
+ cpu_usage{host="server1"}
155
+ ```
156
+
157
+ ### API Endpoints
158
+
159
+ **Akumuli:**
160
+ - Write: TCP port (default 8282)
161
+ - Read: HTTP `/api/query` (default port 8181)
162
+
163
+ **VictoriaMetrics:**
164
+ - Write: OpenTSDB telnet protocol (default port 4242)
165
+ - Read: HTTP `/api/v1/query` and `/api/v1/query_range` (default port 8428)
166
+
167
+ ## Testing Migration
168
+
169
+ A test suite is provided to verify migration correctness:
170
+
171
+ ```bash
172
+ pytest tests/test_migration.py
173
+ ```
174
+
175
+ This test:
176
+ 1. Starts an Akumuli instance
177
+ 2. Writes test data
178
+ 3. Starts a VictoriaMetrics instance
179
+ 4. Migrates the data
180
+ 5. Verifies all data was migrated correctly
181
+
182
+ ## Post-Migration
183
+
184
+ After successful migration:
185
+
186
+ 1. Update your application code to use `asyncvictoria` instead of `asyncakumuli`
187
+ 2. Change connection parameters:
188
+ - Write port: 8282 → 4242 (or your configured OpenTSDB port)
189
+ - Read URL: `http://host:8181/api/query` → `http://host:8428/api/v1/query`
190
+ 3. Update your queries to use VictoriaMetrics query format
191
+ 4. Consider VictoriaMetrics' additional features like:
192
+ - Prometheus-compatible remote write
193
+ - Native InfluxDB line protocol support
194
+ - Built-in deduplication
195
+ - Downsampling
196
+
197
+ ## Troubleshooting
198
+
199
+ ### "Connection refused" errors
200
+
201
+ Ensure VictoriaMetrics is running with OpenTSDB protocol enabled:
202
+ ```bash
203
+ victoria-metrics -opentsdbListenAddr=:4242
204
+ ```
205
+
206
+ ### Data not appearing in VictoriaMetrics
207
+
208
+ 1. Check VictoriaMetrics logs for errors
209
+ 2. Verify the data format is correct
210
+ 3. Try querying with a wider time range
211
+ 4. Force flush data to disk: `curl -X GET http://localhost:8428/internal/force_flush`
212
+
213
+ ### Slow migration
214
+
215
+ - Increase batch size in the migration script
216
+ - Use multiple parallel migration processes for different series
217
+ - Ensure sufficient network bandwidth between Akumuli and VictoriaMetrics
218
+
219
+ ## Support
220
+
221
+ For issues with:
222
+ - `asyncakumuli`: See https://github.com/smurfix/asyncakumuli
223
+ - `asyncvictoria`: See https://github.com/smurfix/asyncvictoria
224
+ - VictoriaMetrics: See https://docs.victoriametrics.com/
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/make -f
2
+
3
+ PACKAGE=asyncvictoria
4
+ ifneq ($(wildcard /usr/share/sourcemgr/make/py),)
5
+ include /usr/share/sourcemgr/make/py
6
+ # availabe via http://github.com/smurfix/sourcemgr
7
+
8
+ else
9
+ %:
10
+ @echo "Please use 'python setup.py'."
11
+ @exit 1
12
+ endif
@@ -0,0 +1,40 @@
1
+ Metadata-Version: 2.4
2
+ Name: asyncvictoria
3
+ Version: 0.7.1
4
+ Summary: Write data to VictoriaMetrics
5
+ Author-email: Matthias Urlichs <matthias@urlichs.de>
6
+ Project-URL: homepage, http://github.com/smurfix/asyncvictoria
7
+ Keywords: iot,logging
8
+ Classifier: Operating System :: POSIX :: Linux
9
+ Classifier: Programming Language :: Python :: 3 :: Only
10
+ Classifier: Programming Language :: Python :: 3.7
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: Implementation :: CPython
13
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
14
+ Classifier: Framework :: Trio
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/x-rst
17
+ Requires-Dist: anyio>=4
18
+ Requires-Dist: httpx
19
+ Requires-Dist: pytz
20
+
21
+ AsyncVictoria
22
+ =============
23
+
24
+ Welcome to `AsyncVictoria <https://github.com/M-o-a-T/asyncvictoria>`__!
25
+
26
+ This library contains a small async wrapper for submission of data to,
27
+ and (rudimentary) reading from, `VictoriaMetrics <https://victoriametrics.com>`__.
28
+
29
+ Also included:
30
+
31
+ * A basic unit test
32
+ * Test scaffolding, to easily test your own code
33
+ * a utility to read the last timestamp, as VictoriaMetrics supports efficient queries
34
+ * helper code to interpret RRD / collectd input so that you can feed those
35
+ to VictoriaMetrics
36
+ * a couple of example scripts
37
+ * a migration tool to migrate data from Akumuli to VictoriaMetrics
38
+
39
+ Tests and collectd support currently require Trio because (a) anyio doesn't
40
+ support subprocesses, (b) UDP socket support in anyio is kindof limited.
@@ -0,0 +1,20 @@
1
+ AsyncVictoria
2
+ =============
3
+
4
+ Welcome to `AsyncVictoria <https://github.com/M-o-a-T/asyncvictoria>`__!
5
+
6
+ This library contains a small async wrapper for submission of data to,
7
+ and (rudimentary) reading from, `VictoriaMetrics <https://victoriametrics.com>`__.
8
+
9
+ Also included:
10
+
11
+ * A basic unit test
12
+ * Test scaffolding, to easily test your own code
13
+ * a utility to read the last timestamp, as VictoriaMetrics supports efficient queries
14
+ * helper code to interpret RRD / collectd input so that you can feed those
15
+ to VictoriaMetrics
16
+ * a couple of example scripts
17
+ * a migration tool to migrate data from Akumuli to VictoriaMetrics
18
+
19
+ Tests and collectd support currently require Trio because (a) anyio doesn't
20
+ support subprocesses, (b) UDP socket support in anyio is kindof limited.
@@ -0,0 +1,16 @@
1
+ """asyncvictoria - Write data to VictoriaMetrics."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ._impl import NoCodeError as NoCodeError
6
+ from ._impl import RespError as RespError
7
+ from ._impl import RespUnknownError as RespUnknownError
8
+ from ._impl import connect as connect
9
+ from ._impl import get_data as get_data
10
+ from ._impl import get_max_ts as get_max_ts
11
+ from .model import DS as DS
12
+ from .model import Entry as Entry
13
+ from .model import EntryDelta as EntryDelta
14
+ from .sanitize import sanitize_entry as sanitize_entry
15
+ from .sanitize import sanitize_label_name as sanitize_label_name
16
+ from .sanitize import sanitize_metric_name as sanitize_metric_name