Compare commits
No commits in common. "2a296a08389b304331abf90eff0f2c7b5b62815b" and "d5ddb7a316e632252295429395907a0a511cbded" have entirely different histories.
2a296a0838
...
d5ddb7a316
@ -5,7 +5,6 @@ services:
|
|||||||
image: mathwave/sprint-repo:monitoring
|
image: mathwave/sprint-repo:monitoring
|
||||||
networks:
|
networks:
|
||||||
- clickhouse
|
- clickhouse
|
||||||
- monitoring
|
|
||||||
environment:
|
environment:
|
||||||
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
|
CLICKHOUSE_PASSWORD: $CLICKHOUSE_PASSWORD_PROD
|
||||||
deploy:
|
deploy:
|
||||||
@ -19,5 +18,3 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
clickhouse:
|
clickhouse:
|
||||||
external: true
|
external: true
|
||||||
monitoring:
|
|
||||||
external: true
|
|
||||||
|
@ -1,25 +0,0 @@
|
|||||||
package routers
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
increments "monitoring/app/storage/clickhouse/tables"
|
|
||||||
"net/http"
|
|
||||||
)
|
|
||||||
|
|
||||||
func AddIncrementMetric(r *http.Request) (interface{}, int) {
|
|
||||||
d := json.NewDecoder(r.Body)
|
|
||||||
body := increments.IncrementMetric{}
|
|
||||||
err := d.Decode(&body)
|
|
||||||
if err != nil {
|
|
||||||
return nil, http.StatusBadRequest
|
|
||||||
}
|
|
||||||
|
|
||||||
err = increments.AddIncrementMetric(body)
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err.Error())
|
|
||||||
return nil, http.StatusInternalServerError
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, http.StatusAccepted
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
package storage
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
type IncrementMetric struct {
|
|
||||||
Timestamp time.Time `json:"timestamp"`
|
|
||||||
Service string `json:"service"`
|
|
||||||
Environment string `json:"environment"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Count int `json:"count"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddIncrementMetric(metric IncrementMetric) error {
|
|
||||||
batch, err := connection().PrepareBatch(context.Background(), "INSERT INTO increments")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = batch.Append(
|
|
||||||
metric.Timestamp,
|
|
||||||
metric.Service,
|
|
||||||
metric.Environment,
|
|
||||||
metric.Name,
|
|
||||||
metric.Count,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return batch.Send()
|
|
||||||
}
|
|
2
main.go
2
main.go
@ -4,7 +4,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
endpoint "monitoring/app/routers/metrics"
|
endpoint "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"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -44,7 +43,6 @@ func main() {
|
|||||||
|
|
||||||
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
|
http.HandleFunc("/api/v1/metrics/endpoint", handlerWrapper(endpoint.AddEndpointMetric))
|
||||||
http.HandleFunc("/api/v1/metrics/task", handlerWrapper(task.AddTaskMetric))
|
http.HandleFunc("/api/v1/metrics/task", handlerWrapper(task.AddTaskMetric))
|
||||||
http.HandleFunc("/api/v1/metrics/increment", handlerWrapper(increment.AddIncrementMetric))
|
|
||||||
log.Printf("Server started")
|
log.Printf("Server started")
|
||||||
http.ListenAndServe(":1237", nil)
|
http.ListenAndServe(":1237", nil)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user