metrics improvements (#234)

This commit is contained in:
Michael Quigley 2023-05-11 15:56:29 -04:00
parent d1688c450d
commit ce4eac8e4c
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 21 additions and 13 deletions

View File

@ -227,14 +227,21 @@ func runFluxForRxTxArray(query string, queryApi api.QueryAPI) (rx, tx, timestamp
return nil, nil, nil, err return nil, nil, nil, err
} }
for result.Next() { for result.Next() {
if v, ok := result.Record().Value().(int64); ok { switch result.Record().Field() {
switch result.Record().Field() { case "rx":
case "rx": rxV := int64(0)
rx = append(rx, float64(v)) if v, ok := result.Record().Value().(int64); ok {
timestamps = append(timestamps, float64(result.Record().Time().UnixMilli())) rxV = v
case "tx":
tx = append(tx, float64(v))
} }
rx = append(rx, float64(rxV))
timestamps = append(timestamps, float64(result.Record().Time().UnixMilli()))
case "tx":
txV := int64(0)
if v, ok := result.Record().Value().(int64); ok {
txV = v
}
tx = append(tx, float64(txV))
} }
} }
return rx, tx, timestamps, nil return rx, tx, timestamps, nil
@ -245,9 +252,9 @@ func sliceSize(duration time.Duration) time.Duration {
case 30 * 24 * time.Hour: case 30 * 24 * time.Hour:
return 24 * time.Hour return 24 * time.Hour
case 7 * 24 * time.Hour: case 7 * 24 * time.Hour:
return 20 * time.Minute return 4 * time.Hour
case 24 * time.Hour: case 24 * time.Hour:
return 5 * time.Minute return 30 * time.Minute
default: default:
return duration return duration
} }

View File

@ -50,8 +50,8 @@ const MetricsGraph = (props) => {
<CartesianGrid strokeDasharay={"3 3"} /> <CartesianGrid strokeDasharay={"3 3"} />
<XAxis dataKey={(v) => v.timestamp} scale={"time"} tickFormatter={(v) => moment(v).format("MMM DD") } style={{ fontSize: '75%'}}/> <XAxis dataKey={(v) => v.timestamp} scale={"time"} tickFormatter={(v) => moment(v).format("MMM DD") } style={{ fontSize: '75%'}}/>
<YAxis tickFormatter={(v) => bytesToSize(v)} style={{ fontSize: '75%' }}/> <YAxis tickFormatter={(v) => bytesToSize(v)} style={{ fontSize: '75%' }}/>
<Bar stroke={"#231069"} fill={"#04adef"} dataKey={"rx"} /> <Bar stroke={"#231069"} fill={"#04adef"} dataKey={(v) => v.rx ? v.rx : 0} />
<Bar stroke={"#231069"} fill={"#9BF316"} dataKey={"tx"} /> <Bar stroke={"#231069"} fill={"#9BF316"} dataKey={(v) => v.tx ? v.tx : 0} />
<Tooltip /> <Tooltip />
</BarChart> </BarChart>
</ResponsiveContainer> </ResponsiveContainer>

View File

@ -1,4 +1,5 @@
export const buildMetrics = (m) => { export const buildMetrics = (m) => {
console.log("build", m);
let metrics = { let metrics = {
data: m.samples, data: m.samples,
rx: 0, rx: 0,
@ -6,8 +7,8 @@ export const buildMetrics = (m) => {
} }
if(m.samples) { if(m.samples) {
m.samples.forEach(s => { m.samples.forEach(s => {
metrics.rx += s.rx; metrics.rx += s.rx ? s.rx : 0;
metrics.tx += s.tx; metrics.tx += s.tx ? s.tx : 0;
}); });
} }
return metrics; return metrics;