Skip to content

Commit

Permalink
optimize?!
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Oct 15, 2024
1 parent ec2ca40 commit 291d912
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 76 deletions.
1 change: 0 additions & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"context"
"encoding/json"
"fmt"
"io"
"log"
Expand Down
44 changes: 3 additions & 41 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,12 @@ type Container struct {
HealthStatus string `json:"health_status"`
}

func setupContainerRoutes(r *gin.Engine) {
// r.GET("/api/containers", func(c *gin.Context) {
// ctx := context.Background()
// apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
// if err != nil {
// c.JSON(500, gin.H{"error": err.Error()})
// return
// }
// apiClient.NegotiateAPIVersion(ctx)
// defer apiClient.Close()

// containers, err := apiClient.ContainerList(ctx, container.ListOptions{All: true})
// if err != nil {
// c.JSON(500, gin.H{"error": err.Error()})
// return
// }
// var containersData []Container
// for _, container := range containers {
// inspectData, err := apiClient.ContainerInspect(ctx, container.ID)
// if err != nil {
// log.Fatalf("Error inspecting container %s: %s", container.ID, err)
// c.JSON(500, gin.H{"error": err.Error()})
// return
// }
// healthStatus := "unhealthy"
// if inspectData.State.Health != nil {
// healthStatus = inspectData.State.Health.Status
// }
var containerIdRegex = regexp.MustCompile(`[^a-zA-Z0-9]+`)

// containersData = append(containersData, Container{
// Time: time.Now().Format("2006-01-02T15:04:05Z"),
// ID: container.ID,
// Image: container.Image,
// Labels: container.Labels,
// Name: container.Names[0][1:],
// State: container.State,
// HealthStatus: healthStatus,
// })
// }
// c.JSON(200, containersData)
// })
func setupContainerRoutes(r *gin.Engine) {
r.GET("/api/container/:containerId/cpu/history", func(c *gin.Context) {
containerID := strings.ReplaceAll(c.Param("containerId"), "/", "")
containerID = regexp.MustCompile(`[^a-zA-Z0-9]+`).ReplaceAllString(containerID, "")
containerID = containerIdRegex.ReplaceAllString(containerID, "")
from := c.Query("from")
if from == "" {
from = "1970-01-01T00:00:01Z"
Expand Down
50 changes: 25 additions & 25 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,35 @@ go 1.23.1
require (
github.com/docker/docker v27.3.1+incompatible
github.com/gin-gonic/gin v1.10.0
github.com/marcboeker/go-duckdb v1.8.1
github.com/json-iterator/go v1.1.12
github.com/marcboeker/go-duckdb v1.8.2
github.com/shirou/gopsutil v3.21.11+incompatible
)

require (
github.com/Microsoft/go-winio v0.4.14 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/apache/arrow/go/v17 v17.0.0 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/bytedance/sonic v1.12.3 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gabriel-vasile/mimetype v1.4.6 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.20.0 // indirect
github.com/go-playground/validator/v10 v10.22.1 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/flatbuffers v24.3.25+incompatible // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand All @@ -45,33 +45,33 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/tklauser/numcpus v0.9.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.55.0 // indirect
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.31.0 // indirect
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.29.0 // indirect
go.opentelemetry.io/otel/trace v1.31.0 // indirect
golang.org/x/arch v0.11.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20241009180824-f66d83c29e7c // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/tools v0.22.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/protobuf v1.34.2 // indirect
golang.org/x/tools v0.26.0 // indirect
golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
)
Loading

0 comments on commit 291d912

Please sign in to comment.