Run through yapf
This commit is contained in:
parent
dc4ff85dbe
commit
b0e89990c6
1 changed files with 17 additions and 32 deletions
|
@ -128,18 +128,14 @@ class MetricValue:
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
label_str = ""
|
label_str = ""
|
||||||
if self.labels:
|
if self.labels:
|
||||||
label_str = (
|
label_str = ("{" + str.join(",", [f'{v[0]}="{v[1]}"'
|
||||||
"{"
|
for v in self.labels.items()]) + "}")
|
||||||
+ str.join(",", [f'{v[0]}="{v[1]}"' for v in self.labels.items()])
|
|
||||||
+ "}"
|
|
||||||
)
|
|
||||||
return f"{label_str} {self.value}"
|
return f"{label_str} {self.value}"
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = dish_common.create_arg_parser(
|
parser = dish_common.create_arg_parser(output_description="Prometheus exporter",
|
||||||
output_description="Prometheus exporter", bulk_history=False
|
bulk_history=False)
|
||||||
)
|
|
||||||
|
|
||||||
group = parser.add_argument_group(title="HTTP server options")
|
group = parser.add_argument_group(title="HTTP server options")
|
||||||
group.add_argument("--address", default="0.0.0.0", help="IP address to listen on")
|
group.add_argument("--address", default="0.0.0.0", help="IP address to listen on")
|
||||||
|
@ -159,9 +155,8 @@ def prometheus_export(opts, gstate):
|
||||||
raise NotImplementedError("Did not expect sequence data")
|
raise NotImplementedError("Did not expect sequence data")
|
||||||
|
|
||||||
with gstate.lock:
|
with gstate.lock:
|
||||||
rc, status_ts, hist_ts = dish_common.get_data(
|
rc, status_ts, hist_ts = dish_common.get_data(opts, gstate, data_add_item,
|
||||||
opts, gstate, data_add_item, data_add_sequencem
|
data_add_sequencem)
|
||||||
)
|
|
||||||
|
|
||||||
metrics = []
|
metrics = []
|
||||||
|
|
||||||
|
@ -178,11 +173,9 @@ def prometheus_export(opts, gstate):
|
||||||
MetricValue(
|
MetricValue(
|
||||||
value=int(raw_data["status_state"] == state_value),
|
value=int(raw_data["status_state"] == state_value),
|
||||||
labels={"state": state_value},
|
labels={"state": state_value},
|
||||||
)
|
) for state_value in STATE_VALUES
|
||||||
for state_value in STATE_VALUES
|
|
||||||
],
|
],
|
||||||
)
|
))
|
||||||
)
|
|
||||||
del raw_data["status_state"]
|
del raw_data["status_state"]
|
||||||
|
|
||||||
info_metrics = ["status_id", "status_hardware_version", "status_software_version"]
|
info_metrics = ["status_id", "status_hardware_version", "status_software_version"]
|
||||||
|
@ -198,14 +191,12 @@ def prometheus_export(opts, gstate):
|
||||||
MetricValue(
|
MetricValue(
|
||||||
value=1,
|
value=1,
|
||||||
labels={
|
labels={
|
||||||
x.replace("status_", ""): raw_data.pop(x)
|
x.replace("status_", ""): raw_data.pop(x) for x in info_metrics
|
||||||
for x in info_metrics
|
|
||||||
if x in raw_data
|
if x in raw_data
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
)
|
))
|
||||||
)
|
|
||||||
|
|
||||||
for name, metric_info in METRICS_INFO.items():
|
for name, metric_info in METRICS_INFO.items():
|
||||||
if name in raw_data:
|
if name in raw_data:
|
||||||
|
@ -215,8 +206,7 @@ def prometheus_export(opts, gstate):
|
||||||
timestamp=status_ts,
|
timestamp=status_ts,
|
||||||
kind=metric_info.kind,
|
kind=metric_info.kind,
|
||||||
values=[MetricValue(value=float(raw_data.pop(name) or 0))],
|
values=[MetricValue(value=float(raw_data.pop(name) or 0))],
|
||||||
)
|
))
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
metrics_not_found.append(name)
|
metrics_not_found.append(name)
|
||||||
|
|
||||||
|
@ -225,22 +215,17 @@ def prometheus_export(opts, gstate):
|
||||||
name="starlink_exporter_unprocessed_metrics",
|
name="starlink_exporter_unprocessed_metrics",
|
||||||
timestamp=status_ts,
|
timestamp=status_ts,
|
||||||
values=[MetricValue(value=1, labels={"metric": name}) for name in raw_data],
|
values=[MetricValue(value=1, labels={"metric": name}) for name in raw_data],
|
||||||
)
|
))
|
||||||
)
|
|
||||||
|
|
||||||
metrics.append(
|
metrics.append(
|
||||||
Metric(
|
Metric(
|
||||||
name="starlink_exporter_missing_metrics",
|
name="starlink_exporter_missing_metrics",
|
||||||
timestamp=status_ts,
|
timestamp=status_ts,
|
||||||
values=[
|
values=[MetricValue(
|
||||||
MetricValue(
|
|
||||||
value=1,
|
value=1,
|
||||||
labels={"metric": name},
|
labels={"metric": name},
|
||||||
)
|
) for name in metrics_not_found],
|
||||||
for name in metrics_not_found
|
))
|
||||||
],
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
return str.join("\n", [str(metric) for metric in metrics])
|
return str.join("\n", [str(metric) for metric in metrics])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue