Compare commits
No commits in common. "22e5c275a91ba105b87420d7a2b28612a9bae404" and "56028ac4792d4a9c2ef4a70bc812bc49867c69e2" have entirely different histories.
22e5c275a9
...
56028ac479
@ -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.Print(err.Error())
|
log.Printf(err.Error())
|
||||||
return nil, http.StatusInternalServerError
|
return nil, http.StatusInternalServerError
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/ClickHouse/clickhouse-go/v2"
|
"github.com/ClickHouse/clickhouse-go/v2"
|
||||||
@ -21,10 +20,6 @@ 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()
|
||||||
@ -51,26 +46,3 @@ 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,13 +3,12 @@ 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 time.Time `json:"timestamp"`
|
Timestamp int `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,7 +33,6 @@ 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