func CheckContainerHealth(cont string) (float64, float64, error) {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
        return 0, 0, err
    }
    defer cli.Close()

    resp, err := cli.ContainerStats(ctx, cont, false)
    if err != nil {
        return 0, 0, err
    }

    var containerStats types.StatsJSON
    decoder := json.NewDecoder(resp.Body)
    decoder.Decode(&containerStats)
    stats := containerStats.Stats

    cpuPercent := calculateContainerCPU(&stats)
    //fmt.Println("cpu", cpuPercent)

    memPercent := calculateContainerMemory(&stats.MemoryStats)
    //fmt.Println("mem", memPercent)

    return cpuPercent, memPercent, nil
}
// calculate container cpu and mem usage
calculate container cpu and mem usage
// calculate container cpu and mem usage
func CheckContainerHealth(cont string) (float64, float64, error) {
    ctx := context.Background()
    cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
    if err != nil {
        return 0, 0, err
    }
    defer cli.Close()
    resp, err := cli.ContainerStats(ctx, cont, false)
    if err != nil {
        return 0, 0, err
    }
    var containerStats types.StatsJSON
    decoder := json.NewDecoder(resp.Body)
    decoder.Decode(&containerStats)
    stats := containerStats.Stats
    cpuPercent := calculateContainerCPU(&stats)
    memPercent := calculateContainerMemory(&stats.MemoryStats)
    return cpuPercent, memPercent, nil
}
func CheckContainerHealth ( cont string ) ( float64 , float64 , error ) { ctx := context . Background ( ) cli , err := client . NewClientWithOpts ( client . FromEnv , client . WithAPIVersionNegotiation ( ) ) if err != nil { return 0 , 0 , err } defer cli . Close ( ) resp , err := cli . ContainerStats ( ctx , cont , false ) if err != nil { return 0 , 0 , err } var containerStats types . StatsJSON decoder := json . NewDecoder ( resp . Body ) decoder . Decode ( & containerStats ) stats := containerStats . Stats cpuPercent := calculateContainerCPU ( & stats ) memPercent := calculateContainerMemory ( & stats . MemoryStats ) return cpuPercent , memPercent , nil }
calculate container cpu and mem usage
calculate container cpu and mem usage
//fmt.Println("cpu", cpuPercent) //fmt.Println("mem", memPercent)