-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better data sources; fixed measure values; misc #8
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,13 +46,17 @@ function metric_string_parse(item): number | null { | |
if (!item) return null; | ||
return +item.metrics[0].value; | ||
} | ||
ipcMain.on("metrics", async (event) => { | ||
|
||
// better dev quality, temp solution | ||
async function getMetrics(): Promise<Metrics> { | ||
console.log("DEBUG: getMetrics start"); | ||
const res = await fetch("http://testnet-3.arweave.net:1984/metrics"); | ||
const data = await res.text(); | ||
Comment on lines
53
to
54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated to the PR, but we are perhaps missing try/catch here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For context of this PR no. Because I want that promise should be error, so FE will also receive error, so I can see it in browser console There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you may end up crashing nodejs if it's not caught anywhere, in a single threaded system it would be fatal error. It's not a big deal for now, I mainly thinking it makes sense to give better error messages. Uncaught errors in promises are quite hard to read and understand. |
||
|
||
const parsed: MinorParser[] = parsePrometheusTextFormat(data); | ||
let data_unpackaged = 0; | ||
let data_packaged = 0; | ||
let storage_available = 0; | ||
const packing_item = parsed.find( | ||
(item: MinorParser) => item.name === "v2_index_data_size_by_packing", | ||
); | ||
|
@@ -64,6 +68,7 @@ ipcMain.on("metrics", async (event) => { | |
} else { | ||
data_packaged += +item.value; | ||
} | ||
storage_available += +item.labels.partition_size; | ||
}); | ||
} | ||
const hash_rate = metric_string_parse( | ||
|
@@ -87,15 +92,24 @@ ipcMain.on("metrics", async (event) => { | |
} | ||
} | ||
} | ||
const metrics: Metrics = { | ||
const weave_size = metric_string_parse( | ||
parsed.find((item: MinorParser) => item.name === "weave_size"), | ||
); | ||
console.log("DEBUG: getMetrics complete"); | ||
return { | ||
data_unpackaged, | ||
data_packaged, | ||
storage_available, | ||
weave_size, | ||
hash_rate, | ||
earnings, | ||
vdf_time_lower_bound, | ||
}; | ||
} | ||
|
||
event.reply("metrics", metrics); | ||
const cached_metrics: Promise<Metrics> = getMetrics(); | ||
hlolli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ipcMain.on("metrics", async (event) => { | ||
event.reply("metrics", await cached_metrics); | ||
}); | ||
|
||
ipcMain.on("open-url", async (event, arg) => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,23 @@ | ||
export type ValueWithMeasureValue = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that you made this type. This is a bit controversial in typescript, but you could consider replacing type with interface if it's a simple record type (they are generally faster and more composeable), not a blocker and this is just a comment :) |
||
value: number; | ||
display_value: string; | ||
unit: string; | ||
}; | ||
export type DataRelatedChart = { | ||
data_package: { | ||
size: number; | ||
unit: string; | ||
}; | ||
storage_available: { | ||
size: number; | ||
unit: string; | ||
}; | ||
total_size: { | ||
size: number; | ||
unit: string; | ||
}; | ||
data_package: ValueWithMeasureValue; | ||
storage_available: ValueWithMeasureValue; | ||
total_size: ValueWithMeasureValue; | ||
}; | ||
|
||
// TODO merge into 1 type | ||
export type TopArrow = { | ||
value: number; | ||
value: string; | ||
unit: string; | ||
color: string; | ||
}; | ||
|
||
export type BottomArrow = { | ||
value: number; | ||
value: string; | ||
unit: string; | ||
color: string; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,35 @@ | ||
export function convertToGbFromPetabytes(value: number): number { | ||
const gigabytes = value * 1e9; // 1 petabyte = 1e9 gigabytes | ||
return parseFloat(gigabytes.toFixed(2)); | ||
import { ValueWithMeasureValue } from "../types/Charts"; | ||
const size_mv_list = ["B", "KB", "MB", "GB", "TB", "PB"]; | ||
|
||
// rough port from | ||
// https://github.com/virdpool/ar_miner_ui_playground/blob/e28a8034bd367a35fe40878c90c606e456b2346f/electron_app/htdocs/util/fmt.coffee#L6 | ||
// TODO refactor | ||
export function fmt_size(orig_value: number): ValueWithMeasureValue { | ||
hlolli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let idx = 0; | ||
let value = orig_value; | ||
while (idx < size_mv_list.length) { | ||
const unit = size_mv_list[idx]; | ||
if (value < 900 || idx + 1 >= size_mv_list.length) { | ||
if (idx === 0) { | ||
return { | ||
value: orig_value, | ||
display_value: value.toString(), | ||
unit, | ||
}; | ||
} else { | ||
return { | ||
value: orig_value, | ||
display_value: value.toFixed(2), | ||
unit, | ||
}; | ||
} | ||
} | ||
value /= 1024; | ||
idx++; | ||
} | ||
return { | ||
value: orig_value, | ||
display_value: "0", | ||
unit: "B", | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should consider using logger library (like winston or pino) in order to include debug logs but turn them down in releases