fix
This commit is contained in:
parent
de7567b0e6
commit
1d5d753c39
@ -17,7 +17,7 @@ func AddEndpointMetric (r *http.Request) (interface{}, int) {
|
|||||||
|
|
||||||
err = endpoints.AddEndpointMetric(body)
|
err = endpoints.AddEndpointMetric(body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf(err.Error())
|
log.Print(err.Error())
|
||||||
return nil, http.StatusInternalServerError
|
return nil, http.StatusInternalServerError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ClickHouse/clickhouse-go/v2"
|
"github.com/ClickHouse/clickhouse-go/v2"
|
||||||
@ -20,6 +21,10 @@ func Connect() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Close() {
|
||||||
|
Connection.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func connect() (*driver.Conn, error) {
|
func connect() (*driver.Conn, error) {
|
||||||
var (
|
var (
|
||||||
ctx = context.Background()
|
ctx = context.Background()
|
||||||
@ -46,3 +51,26 @@ func connect() (*driver.Conn, error) {
|
|||||||
}
|
}
|
||||||
return &conn, nil
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
client "monitoring/app/storage/clickhouse"
|
client "monitoring/app/storage/clickhouse"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
"github.com/ClickHouse/clickhouse-go/v2/lib/driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EndpointMetric struct {
|
type EndpointMetric struct {
|
||||||
Timestamp int `json:"timestamp"`
|
Timestamp time.Time `json:"timestamp"`
|
||||||
Service string `json:"service"`
|
Service string `json:"service"`
|
||||||
Endpoint string `json:"endpoint"`
|
Endpoint string `json:"endpoint"`
|
||||||
StatusCode int `json:"status_code"`
|
StatusCode int `json:"status_code"`
|
||||||
|
1
main.go
1
main.go
@ -33,6 +33,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
|
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
|
||||||
log.Printf("Server started")
|
log.Printf("Server started")
|
||||||
|
Loading…
Reference in New Issue
Block a user