monitoring/app/storage/clickhouse/tables/endpoints.go
Egor Matveev d11ae23369
All checks were successful
Deploy Dev / Build (pull_request) Successful in 57s
Deploy Dev / Push (pull_request) Successful in 35s
Deploy Dev / Deploy dev (pull_request) Successful in 12s
fix
2025-06-13 23:25:34 +03:00

44 lines
872 B
Go

package storage
import (
"context"
client "monitoring/app/storage/clickhouse"
"time"
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
)
type EndpointMetric struct {
Timestamp time.Time `json:"timestamp"`
Service string `json:"service"`
Endpoint string `json:"endpoint"`
StatusCode int `json:"status_code"`
ResponseTime int `json:"response_time"`
Method string `json:"method"`
}
func AddEndpointMetric(metric EndpointMetric) error {
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO endpoints")
if err != nil {
return err
}
err = batch.Append(
metric.Timestamp,
metric.Service,
metric.Endpoint,
metric.StatusCode,
metric.ResponseTime,
metric.Method,
)
if err != nil {
return err
}
return batch.Send()
}
func connection() driver.Conn {
return client.Connection
}