1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| func WritePoint(database string, point *write.Point) error { writeAPI := client.WriteAPIBlocking("", database+"/autogen") err := writeAPI.WritePoint(context.Background(), point) if err != nil { return fmt.Errorf("write to influxdb error: %w", err) } return nil }
func WriteCPUPercentInfo(usage []float64) error { for id, percent := range usage { point := influxdb2.NewPoint("cpu_usage", map[string]string{"cpu_id": strconv.FormatInt(int64(id), 10)}, map[string]interface{}{"usage_percent": percent}, time.Now()) err := WritePoint("monitor", point) if err != nil { return fmt.Errorf("write cpu usage percent to influxdb error: %w", err) } } return nil }
|