forked from M-Labs/artiq
1
0
Fork 0

artiq_influxdb: clarify argparse groups (#1212)

Make names of argparse group variables relate to what they're doing.
Meets Flake8.

Signed-off-by: Drew Risinger <drewrisinger@users.noreply.github.com>
This commit is contained in:
Drew 2019-01-08 22:40:55 -05:00 committed by Sébastien Bourdeauducq
parent 101ed5d534
commit b3b0b6f0a5
1 changed files with 25 additions and 20 deletions

View File

@ -11,7 +11,10 @@ import time
import numpy as np import numpy as np
import aiohttp import aiohttp
from artiq.tools import * from artiq.tools import (
simple_network_args, verbosity_args, atexit_register_coroutine,
bind_address_from_args, init_logger, TaskObject
)
from artiq.protocols.sync_struct import Subscriber from artiq.protocols.sync_struct import Subscriber
from artiq.protocols.pc_rpc import Server from artiq.protocols.pc_rpc import Server
from artiq.protocols import pyon from artiq.protocols import pyon
@ -27,34 +30,34 @@ def get_argparser():
"The default action on a key (dataset name) is to log it. " "The default action on a key (dataset name) is to log it. "
"Then the patterns are traversed in order and glob-matched " "Then the patterns are traversed in order and glob-matched "
"with the key. " "with the key. "
"Optional + and - pattern prefixes specify whether to ignore or " "Optional + and - pattern prefixes specify to either ignore or "
"log keys matching the rest of the pattern. " "log keys matching the rest of the pattern. "
"Default (in the absence of prefix) is to ignore. Last matched " "Default (in the absence of prefix) is to ignore. Last matched "
"pattern takes precedence.") "pattern takes precedence.")
group = parser.add_argument_group("master") master_group = parser.add_argument_group("master")
group.add_argument( master_group.add_argument(
"--server-master", default="::1", "--server-master", default="::1",
help="hostname or IP of the master to connect to") help="hostname or IP of the master to connect to")
group.add_argument( master_group.add_argument(
"--port-master", default=3250, type=int, "--port-master", default=3250, type=int,
help="TCP port to use to connect to the master") help="TCP port to use to connect to the master (default: %(default)s")
group.add_argument( master_group.add_argument(
"--retry-master", default=5.0, type=float, "--retry-master", default=5.0, type=float,
help="retry timer for reconnecting to master") help="retry timer for reconnecting to master")
group = parser.add_argument_group("database") database_group = parser.add_argument_group("database")
group.add_argument( database_group.add_argument(
"--baseurl-db", default="http://localhost:8086", "--baseurl-db", default="http://localhost:8086",
help="base URL to access InfluxDB (default: %(default)s)") help="base URL to access InfluxDB (default: %(default)s)")
group.add_argument( database_group.add_argument(
"--user-db", default="", help="InfluxDB username") "--user-db", default="", help="InfluxDB username")
group.add_argument( database_group.add_argument(
"--password-db", default="", help="InfluxDB password") "--password-db", default="", help="InfluxDB password")
group.add_argument( database_group.add_argument(
"--database", default="db", help="database name to use") "--database", default="db", help="database name to use")
group.add_argument( database_group.add_argument(
"--table", default="lab", help="table name to use") "--table", default="lab", help="table name to use")
group = parser.add_argument_group("filter") filter_group = parser.add_argument_group("filter")
group.add_argument( filter_group.add_argument(
"--pattern-file", default="influxdb_patterns.cfg", "--pattern-file", default="influxdb_patterns.cfg",
help="file to load the patterns from (default: %(default)s). " help="file to load the patterns from (default: %(default)s). "
"If the file is not found, no patterns are loaded " "If the file is not found, no patterns are loaded "
@ -98,18 +101,20 @@ class DBWriter(TaskObject):
while True: while True:
k, v, t = await self._queue.get() k, v, t = await self._queue.get()
url = self.base_url + "/write" url = self.base_url + "/write"
params = {"u": self.user, "p": self.password, "db": self.database, params = {"u": self.user, "p": self.password,
"precision": "ms"} "db": self.database, "precision": "ms"}
data = "{},dataset={} {} {}".format( data = "{},dataset={} {} {}".format(
self.table, k, format_influxdb(v), round(t*1e3)) self.table, k, format_influxdb(v), round(t*1e3))
try: try:
response = await session.post(url, params=params, data=data) response = await session.post(url, params=params,
except: data=data)
except Exception:
logger.warning("got exception trying to update '%s'", logger.warning("got exception trying to update '%s'",
k, exc_info=True) k, exc_info=True)
else: else:
if response.status not in (200, 204): if response.status not in (200, 204):
content = (await response.content.read()).decode().strip() content = (await response.content.read()).decode() \
.strip()
logger.warning("got HTTP status %d " logger.warning("got HTTP status %d "
"trying to update '%s': %s", "trying to update '%s': %s",
response.status, k, content) response.status, k, content)