Merge pull request 'fix' (#10) from master into dev
Reviewed-on: https://gitea.chocomarsh.com/self/monitoring/pulls/10
This commit is contained in:
commit
22e5c275a9
@ -17,7 +17,7 @@ func AddEndpointMetric (r *http.Request) (interface{}, int) {
|
||||
|
||||
err = endpoints.AddEndpointMetric(body)
|
||||
if err != nil {
|
||||
log.Printf(err.Error())
|
||||
log.Print(err.Error())
|
||||
return nil, http.StatusInternalServerError
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go/v2"
|
||||
@ -20,6 +21,10 @@ func Connect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Close() {
|
||||
Connection.Close()
|
||||
}
|
||||
|
||||
func connect() (*driver.Conn, error) {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
@ -45,4 +50,27 @@ func connect() (*driver.Conn, error) {
|
||||
return nil, err
|
||||
}
|
||||
return &conn, nil
|
||||
}
|
||||
|
||||
func Migrate() error {
|
||||
rows, err := Connection.Query(
|
||||
context.TODO(),
|
||||
`CREATE TABLE IF NOT EXISTS endpoints (
|
||||
timestamp DateTime,
|
||||
service_name LowCardinality(String),
|
||||
endpoint LowCardinality(String),
|
||||
status_code UInt16,
|
||||
response_time_ms UInt32,
|
||||
request_method LowCardinality(String),
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
PARTITION BY toYYYYMM(timestamp)
|
||||
ORDER BY (service_name, endpoint, request_method, timestamp)`,
|
||||
)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return nil
|
||||
}
|
@ -3,12 +3,13 @@ package storage
|
||||
import (
|
||||
"context"
|
||||
client "monitoring/app/storage/clickhouse"
|
||||
"time"
|
||||
|
||||
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
||||
)
|
||||
|
||||
type EndpointMetric struct {
|
||||
Timestamp int `json:"timestamp"`
|
||||
Timestamp time.Time `json:"timestamp"`
|
||||
Service string `json:"service"`
|
||||
Endpoint string `json:"endpoint"`
|
||||
StatusCode int `json:"status_code"`
|
||||
|
Loading…
Reference in New Issue
Block a user