Add measurement summary to list command
This commit is contained in:
parent
31ccb1c181
commit
8da12a9c07
|
@ -27,9 +27,27 @@ func init() {
|
||||||
log.WithError(err).Error("failed to list measurements")
|
log.WithError(err).Error("failed to list measurements")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
msmtSummary := output.MeasurementSummaryData{
|
||||||
|
TotalCount: 0,
|
||||||
|
AnomalyCount: 0,
|
||||||
|
DataUsageUp: 0,
|
||||||
|
DataUsageDown: 0,
|
||||||
|
}
|
||||||
for _, msmt := range measurements {
|
for _, msmt := range measurements {
|
||||||
|
// FIXME this logic should be adjusted for test groups that have many
|
||||||
|
// measurements in them
|
||||||
|
if msmtSummary.DataUsageUp == 0 {
|
||||||
|
msmtSummary.DataUsageUp = msmt.DataUsageUp
|
||||||
|
msmtSummary.DataUsageDown = msmt.DataUsageDown
|
||||||
|
}
|
||||||
|
if msmt.IsAnomaly.Bool == true {
|
||||||
|
msmtSummary.AnomalyCount++
|
||||||
|
}
|
||||||
|
msmtSummary.TotalCount++
|
||||||
output.MeasurementItem(msmt)
|
output.MeasurementItem(msmt)
|
||||||
}
|
}
|
||||||
|
output.MeasurementSummary(msmtSummary)
|
||||||
} else {
|
} else {
|
||||||
doneResults, incompleteResults, err := database.ListResults(ctx.DB)
|
doneResults, incompleteResults, err := database.ListResults(ctx.DB)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -19,8 +19,14 @@ func ListMeasurements(sess sqlbuilder.Database, resultID int64) ([]MeasurementUR
|
||||||
|
|
||||||
req := sess.Select(
|
req := sess.Select(
|
||||||
"measurements.id as msmt_tbl_id",
|
"measurements.id as msmt_tbl_id",
|
||||||
|
"measurements.is_done as measurement_is_done",
|
||||||
|
"measurements.start_time as measurement_start_time",
|
||||||
|
"measurements.runtime as measurement_runtime",
|
||||||
"networks.id as network_id",
|
"networks.id as network_id",
|
||||||
"results.id as result_id",
|
"results.id as result_id",
|
||||||
|
"results.start_time as result_start_time",
|
||||||
|
"results.is_done as result_is_done",
|
||||||
|
"results.runtime as result_runtime",
|
||||||
"urls.id as url_id",
|
"urls.id as url_id",
|
||||||
db.Raw("networks.*"),
|
db.Raw("networks.*"),
|
||||||
db.Raw("urls.*"),
|
db.Raw("urls.*"),
|
||||||
|
|
|
@ -21,13 +21,19 @@ type ResultNetwork struct {
|
||||||
|
|
||||||
// MeasurementURLNetwork is used for the JOIN between Measurement and URL
|
// MeasurementURLNetwork is used for the JOIN between Measurement and URL
|
||||||
type MeasurementURLNetwork struct {
|
type MeasurementURLNetwork struct {
|
||||||
Measurement `db:",inline"`
|
Measurement `db:",inline"`
|
||||||
MsmtTblID int64 `db:"msmt_tbl_id"`
|
MeasurementStartTime time.Time `db:"measurement_start_time"`
|
||||||
Network `db:",inline"`
|
MeasurementIsDone bool `db:"measurement_is_done"`
|
||||||
NetworkID int64 `db:"network_id"`
|
MeasurementRuntime float64 `db:"measurement_runtime"`
|
||||||
Result `db:",inline"`
|
MsmtTblID int64 `db:"msmt_tbl_id"`
|
||||||
ResultID int64 `db:"result_id"`
|
Network `db:",inline"`
|
||||||
URL `db:",inline"`
|
NetworkID int64 `db:"network_id"`
|
||||||
|
Result `db:",inline"`
|
||||||
|
ResultID int64 `db:"result_id"`
|
||||||
|
ResultRuntime float64 `db:"result_runtime"`
|
||||||
|
ResultStartTime time.Time `db:"result_start_time"`
|
||||||
|
ResultIsDone bool `db:"result_is_done"`
|
||||||
|
URL `db:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Network represents a network tested by the user
|
// Network represents a network tested by the user
|
||||||
|
|
|
@ -20,6 +20,23 @@ func Progress(key string, perc float64, msg string) {
|
||||||
}).Info(msg)
|
}).Info(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MeasurementSummaryData struct {
|
||||||
|
TotalCount int64
|
||||||
|
AnomalyCount int64
|
||||||
|
DataUsageUp int64
|
||||||
|
DataUsageDown int64
|
||||||
|
}
|
||||||
|
|
||||||
|
func MeasurementSummary(msmt MeasurementSummaryData) {
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"type": "measurement_summary",
|
||||||
|
"total_count": msmt.TotalCount,
|
||||||
|
"anomaly_count": msmt.AnomalyCount,
|
||||||
|
"data_usage_down": msmt.DataUsageDown,
|
||||||
|
"data_usage_up": msmt.DataUsageUp,
|
||||||
|
}).Info("measurement summary")
|
||||||
|
}
|
||||||
|
|
||||||
// MeasurementItem logs a progress type event
|
// MeasurementItem logs a progress type event
|
||||||
func MeasurementItem(msmt database.MeasurementURLNetwork) {
|
func MeasurementItem(msmt database.MeasurementURLNetwork) {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
|
@ -27,12 +44,12 @@ func MeasurementItem(msmt database.MeasurementURLNetwork) {
|
||||||
"id": msmt.MsmtTblID,
|
"id": msmt.MsmtTblID,
|
||||||
"test_name": msmt.TestName,
|
"test_name": msmt.TestName,
|
||||||
"test_group_name": msmt.Result.TestGroupName,
|
"test_group_name": msmt.Result.TestGroupName,
|
||||||
"start_time": msmt.Measurement.StartTime,
|
"start_time": msmt.MeasurementStartTime,
|
||||||
"test_keys": msmt.TestKeys,
|
"test_keys": msmt.TestKeys,
|
||||||
"probe_cc": msmt.Network.CountryCode,
|
"probe_cc": msmt.Network.CountryCode,
|
||||||
"network_name": msmt.Network.NetworkName,
|
"network_name": msmt.Network.NetworkName,
|
||||||
"asn": msmt.Network.ASN,
|
"asn": msmt.Network.ASN,
|
||||||
"runtime": msmt.Measurement.Runtime,
|
"runtime": msmt.MeasurementRuntime,
|
||||||
"url": msmt.URL.URL.String,
|
"url": msmt.URL.URL.String,
|
||||||
"url_category_code": msmt.URL.CategoryCode.String,
|
"url_category_code": msmt.URL.CategoryCode.String,
|
||||||
"url_country_code": msmt.URL.CountryCode.String,
|
"url_country_code": msmt.URL.CountryCode.String,
|
||||||
|
@ -42,7 +59,7 @@ func MeasurementItem(msmt database.MeasurementURLNetwork) {
|
||||||
"upload_failure_msg": msmt.UploadFailureMsg.String,
|
"upload_failure_msg": msmt.UploadFailureMsg.String,
|
||||||
"is_failed": msmt.IsFailed,
|
"is_failed": msmt.IsFailed,
|
||||||
"failure_msg": msmt.FailureMsg.String,
|
"failure_msg": msmt.FailureMsg.String,
|
||||||
"is_done": msmt.Measurement.IsDone,
|
"is_done": msmt.MeasurementIsDone,
|
||||||
"report_file_path": msmt.ReportFilePath,
|
"report_file_path": msmt.ReportFilePath,
|
||||||
}).Info("measurement")
|
}).Info("measurement")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user