Compare commits
No commits in common. "880b6313a9a14586732dd31363fa2cd851f242f9" and "fbeb173df0d075fc8173b66d30f2ac39e2cc8207" have entirely different histories.
880b6313a9
...
fbeb173df0
@ -8,7 +8,6 @@ services:
|
|||||||
- clickhouse-development
|
- clickhouse-development
|
||||||
environment:
|
environment:
|
||||||
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_DEV
|
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_DEV
|
||||||
STAGE: "development"
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
|
@ -8,7 +8,6 @@ services:
|
|||||||
- monitoring
|
- monitoring
|
||||||
environment:
|
environment:
|
||||||
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
|
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
|
||||||
STAGE: "production"
|
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
|
19
main.go
19
main.go
@ -7,28 +7,10 @@ import (
|
|||||||
increment "monitoring/app/routers/metrics"
|
increment "monitoring/app/routers/metrics"
|
||||||
task "monitoring/app/routers/metrics"
|
task "monitoring/app/routers/metrics"
|
||||||
client "monitoring/app/storage/clickhouse"
|
client "monitoring/app/storage/clickhouse"
|
||||||
endpoints "monitoring/app/storage/clickhouse/tables"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func writeMetric(timestamp time.Time, endpoint string, statusCode int, responseTime int, method string) {
|
|
||||||
loc, _ := time.LoadLocation("Europe/Moscow")
|
|
||||||
err := endpoints.AddEndpointMetric(endpoints.EndpointMetric{
|
|
||||||
Timestamp: timestamp.In(loc),
|
|
||||||
Service: "monitoring",
|
|
||||||
Environment: os.Getenv("STAGE"),
|
|
||||||
Endpoint: endpoint,
|
|
||||||
StatusCode: statusCode,
|
|
||||||
ResponseTime: responseTime,
|
|
||||||
Method: method,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("Error sending metrics %s", err.Error())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.ResponseWriter, *http.Request) {
|
func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.ResponseWriter, *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
@ -44,7 +26,6 @@ func handlerWrapper(f func(*http.Request) (interface{}, int)) func(http.Response
|
|||||||
} else {
|
} else {
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
}
|
}
|
||||||
go writeMetric(start, r.URL.Path, status, int(time.Since(start).Milliseconds()), r.Method)
|
|
||||||
log.Printf("%s %d %s", r.URL, status, time.Since(start))
|
log.Printf("%s %d %s", r.URL, status, time.Since(start))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user