/** * Yats - yats * * This file is licensed under the Affero General Public License version 3 or * later. See the COPYING file. * * @author Paolo Lulli * @copyright Paolo Lulli 2024 */ package db import ( "fmt" "github.com/gocql/gocql" "time" "yats-server/model" ) func MetricsFrom(session *gocql.Session, idClient string, metricName string, fromTime string, limit int32) []model.MetricSaveRequest { var metrics []model.MetricSaveRequest m := map[string]interface{}{} q := fmt.Sprintf("SELECT id_client, mtime, name, value FROM metric where id_client='%s' and name ='%s' and mtime > '%s' order by mtime limit %d", idClient, metricName, fromTime, limit) fmt.Println(q) iter := session.Query(q).Iter() for iter.MapScan(m) { metrics = append(metrics, model.MetricSaveRequest{ IdClient: m["id_client"].(string), Mtime: m["mtime"].(time.Time).UnixMilli(), Name: m["name"].(string), Value: m["value"].(string), }) m = map[string]interface{}{} } return metrics }