|
|
|
@ -16,6 +16,8 @@ func sendRequests(conn *client.Connection) { |
|
|
|
|
cumulativeMetricID uint32 = 10001 |
|
|
|
|
fracDigits int = 2 |
|
|
|
|
err error |
|
|
|
|
|
|
|
|
|
seriesInDays = 62 |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
conn.DeleteMetric(instantMetricID) |
|
|
|
@ -41,17 +43,17 @@ func sendRequests(conn *client.Connection) { |
|
|
|
|
log.Fatalf("conn.GetMetric: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf(` |
|
|
|
|
GetMetric: |
|
|
|
|
metricID: %d |
|
|
|
|
metricType: %s |
|
|
|
|
fracDigits: %d |
|
|
|
|
`, |
|
|
|
|
GetMetric: |
|
|
|
|
metricID: %d |
|
|
|
|
metricType: %s |
|
|
|
|
fracDigits: %d |
|
|
|
|
`, |
|
|
|
|
iMetric.MetricID, metricTypeToName[iMetric.MetricType], fracDigits) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// APPEND MEASURES
|
|
|
|
|
|
|
|
|
|
instantMeasures := GenerateInstantMeasures(62, 220) |
|
|
|
|
instantMeasures := GenerateInstantMeasures(seriesInDays, 220) |
|
|
|
|
|
|
|
|
|
err = conn.AppendMeasures(proto.AppendMeasuresReq{ |
|
|
|
|
MetricID: instantMetricID, |
|
|
|
@ -78,10 +80,10 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListInstantMeasures: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListInstantMeasures %s - %s:\n", |
|
|
|
|
formatTime(uint32(since.Unix())), formatTime(uint32(until.Unix()))) |
|
|
|
|
fmt.Printf("\nListInstantMeasures %s − %s:\n", |
|
|
|
|
formatTime(since), formatTime(until)) |
|
|
|
|
for _, item := range instantList { |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTime(item.Timestamp), item.Value) |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTimestamp(item.Timestamp), item.Value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -93,13 +95,13 @@ GetMetric: |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListAllInstantMeasures (last 15 items):\n") |
|
|
|
|
for _, item := range instantList[:15] { |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTime(item.Timestamp), item.Value) |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTimestamp(item.Timestamp), item.Value) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST INSTANT PERIODS (group by hour)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.Add(-24 * time.Hour) |
|
|
|
|
|
|
|
|
|
instantPeriods, err := conn.ListInstantPeriods(proto.ListInstantPeriodsReq{ |
|
|
|
@ -120,16 +122,19 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListInstantPeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListInstantPeriods (1 day, group by hour):\n") |
|
|
|
|
fmt.Printf("\nListInstantPeriods (%s − %s, group by day):\n", |
|
|
|
|
formatDate(since), formatDate(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range instantPeriods { |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", formatHourPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", |
|
|
|
|
formatHourPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST INSTANT PERIODS (group by day)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
since = until.AddDate(0, 0, -7) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.AddDate(0, 0, -6) |
|
|
|
|
|
|
|
|
|
instantPeriods, err = conn.ListInstantPeriods(proto.ListInstantPeriodsReq{ |
|
|
|
|
MetricID: instantMetricID, |
|
|
|
@ -149,16 +154,19 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListInstantPeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListInstantPeriods (7 days, group by day):\n") |
|
|
|
|
fmt.Printf("\nListInstantPeriods (%s − %s, group by day):\n", |
|
|
|
|
formatDate(since), formatDate(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range instantPeriods { |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", formatDayPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", |
|
|
|
|
formatDayPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST INSTANT PERIODS (group by month)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
since = until.AddDate(0, 0, -62) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.AddDate(0, 0, -seriesInDays) |
|
|
|
|
|
|
|
|
|
instantPeriods, err = conn.ListInstantPeriods(proto.ListInstantPeriodsReq{ |
|
|
|
|
MetricID: instantMetricID, |
|
|
|
@ -178,9 +186,11 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListInstantPeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListInstantPeriods (62 days, group by month):\n") |
|
|
|
|
fmt.Printf("\nListInstantPeriods (%s − %s, group by day):\n", |
|
|
|
|
formatMonth(since), formatMonth(until)) |
|
|
|
|
for _, item := range instantPeriods { |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", formatMonthPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
fmt.Printf(" %s => min %.2f, max %.2f, avg %.2f\n", |
|
|
|
|
formatMonthPeriod(item.Period), item.Min, item.Max, item.Avg) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -234,7 +244,9 @@ GetMetric: |
|
|
|
|
|
|
|
|
|
// APPEND MEASURES
|
|
|
|
|
|
|
|
|
|
cumulativeMeasures := GenerateCumulativeMeasures(62) |
|
|
|
|
cumulativeMeasures := GenerateCumulativeMeasures(seriesInDays) |
|
|
|
|
|
|
|
|
|
//pretty.PPrintln("CUMULATIVE MEASURES", cumulativeMeasures)
|
|
|
|
|
|
|
|
|
|
err = conn.AppendMeasures(proto.AppendMeasuresReq{ |
|
|
|
|
MetricID: cumulativeMetricID, |
|
|
|
@ -261,11 +273,12 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListCumulativeMeasures: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListCumulativeMeasures %s - %s:\n", |
|
|
|
|
formatTime(uint32(since.Unix())), formatTime(uint32(until.Unix()))) |
|
|
|
|
fmt.Printf("\nListCumulativeMeasures %s − %s:\n", |
|
|
|
|
formatTime(since), formatTime(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range cumulativeList { |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTime(item.Timestamp), item.Value) |
|
|
|
|
fmt.Printf(" %s => %.2f (%.2f)\n", |
|
|
|
|
formatTimestamp(item.Timestamp), item.Value, item.Total) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -277,13 +290,14 @@ GetMetric: |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListAllCumulativeMeasures (last 15 items):\n") |
|
|
|
|
for _, item := range cumulativeList[:15] { |
|
|
|
|
fmt.Printf(" %s => %.2f\n", formatTime(item.Timestamp), item.Value) |
|
|
|
|
fmt.Printf(" %s => %.2f (%.2f)\n", |
|
|
|
|
formatTimestamp(item.Timestamp), item.Value, item.Total) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST CUMULATIVE PERIODS (group by hour)
|
|
|
|
|
//LIST CUMULATIVE PERIODS (group by hour)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.Add(-24 * time.Hour) |
|
|
|
|
|
|
|
|
|
cumulativePeriods, err := conn.ListCumulativePeriods(proto.ListCumulativePeriodsReq{ |
|
|
|
@ -303,16 +317,19 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListCumulativePeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (1 day, group by hour):\n") |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (%s − %s, group by hour):\n", |
|
|
|
|
formatDate(since), formatDate(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range cumulativePeriods { |
|
|
|
|
fmt.Printf(" %s => end value %.2f, total %.2f\n", formatHourPeriod(item.Period), item.EndValue, item.Total) |
|
|
|
|
fmt.Printf(" %s => %.2f (%.2f)\n", |
|
|
|
|
formatHourPeriod(item.Period), item.EndValue, item.EndValue-item.StartValue) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST CUMULATIVE PERIODS (group by day)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
since = until.AddDate(0, 0, -7) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.AddDate(0, 0, -6) |
|
|
|
|
|
|
|
|
|
cumulativePeriods, err = conn.ListCumulativePeriods(proto.ListCumulativePeriodsReq{ |
|
|
|
|
MetricID: cumulativeMetricID, |
|
|
|
@ -331,16 +348,19 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListCumulativePeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (7 days, group by day):\n") |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (%s − %s, group by day):\n", |
|
|
|
|
formatDate(since), formatDate(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range cumulativePeriods { |
|
|
|
|
fmt.Printf(" %s => end value %.2f, total %.2f\n", formatDayPeriod(item.Period), item.EndValue, item.Total) |
|
|
|
|
fmt.Printf(" %s => %.2f (%.2f)\n", |
|
|
|
|
formatDayPeriod(item.Period), item.EndValue, item.EndValue-item.StartValue) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// LIST CUMULATIVE PERIODS (group by day)
|
|
|
|
|
|
|
|
|
|
until = time.Unix(int64(lastTimestamp+1), 0) |
|
|
|
|
since = until.AddDate(0, 0, -62) |
|
|
|
|
until = time.Unix(int64(lastTimestamp), 0) |
|
|
|
|
since = until.AddDate(0, 0, -seriesInDays) |
|
|
|
|
|
|
|
|
|
cumulativePeriods, err = conn.ListCumulativePeriods(proto.ListCumulativePeriodsReq{ |
|
|
|
|
MetricID: cumulativeMetricID, |
|
|
|
@ -359,9 +379,12 @@ GetMetric: |
|
|
|
|
if err != nil { |
|
|
|
|
log.Fatalf("conn.ListCumulativePeriods: %s\n", err) |
|
|
|
|
} else { |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (62 days, group by month):\n") |
|
|
|
|
fmt.Printf("\nListCumulativePeriods (%s − %s, group by month):\n", |
|
|
|
|
formatMonth(since), formatMonth(until)) |
|
|
|
|
|
|
|
|
|
for _, item := range cumulativePeriods { |
|
|
|
|
fmt.Printf(" %s => end value %.2f, total %.2f\n", formatMonthPeriod(item.Period), item.EndValue, item.Total) |
|
|
|
|
fmt.Printf(" %s => %.2f (%.2f)\n", |
|
|
|
|
formatMonthPeriod(item.Period), item.EndValue, item.EndValue-item.StartValue) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -386,11 +409,21 @@ GetMetric: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const datetimeLayout = "2006-01-02 15:04:05" |
|
|
|
|
func formatMonth(tm time.Time) string { |
|
|
|
|
return tm.Format("2006-01") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formatDate(tm time.Time) string { |
|
|
|
|
return tm.Format("2006-01-02") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formatTime(tm time.Time) string { |
|
|
|
|
return tm.Format("2006-01-02 15:04:05") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formatTime(timestamp uint32) string { |
|
|
|
|
func formatTimestamp(timestamp uint32) string { |
|
|
|
|
tm := time.Unix(int64(timestamp), 0) |
|
|
|
|
return tm.Format(datetimeLayout) |
|
|
|
|
return tm.Format("2006-01-02 15:04:05") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func formatHourPeriod(period uint32) string { |
|
|
|
|