Commit 2fb5a659 authored by Your Name's avatar Your Name

add interface

parent 2f0cc906
...@@ -9,14 +9,208 @@ package main ...@@ -9,14 +9,208 @@ package main
//https://github.com/ricochet2200/go-disk-usage.git //https://github.com/ricochet2200/go-disk-usage.git
import ( import (
"context"
"fmt" "fmt"
"time"
"github.com/jaypipes/ghw" "github.com/jaypipes/ghw"
"github.com/pkg/errors" "github.com/pkg/errors"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
"github.com/ricochet2200/go-disk-usage/du" "github.com/ricochet2200/go-disk-usage/du"
) )
//100 - ((node_filesystem_free_bytes * 100) / node_filesystem_size_bytes)
func (c *ProApi) DiskUtil() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := ` (100 - ((node_filesystem_avail_bytes * 100) / node_filesystem_size_bytes))`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
unique := make(map[string]bool)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["device"]; ok {
if _, subOk := unique[string(modelName)]; subOk {
continue
} else {
unique[string(modelName)] = true
r.Model = string(modelName)
}
} else {
continue
}
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "DiskUtil"
res = append(res, r)
}
}
return res, nil
}
func (c *ProApi) DiskTotalSize() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `node_filesystem_size_bytes/1024/1024/1024`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
unique := make(map[string]bool)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["device"]; ok {
if _, subOk := unique[string(modelName)]; subOk {
continue
} else {
unique[string(modelName)] = true
r.Model = string(modelName)
}
} else {
continue
}
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "DiskTotalSize"
res = append(res, r)
}
}
return res, nil
}
//node_filesystem_free_bytes
func (c *ProApi) DiskFreeSize() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `node_filesystem_free_bytes/1024/1024/1024`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
unique := make(map[string]bool)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["device"]; ok {
if _, subOk := unique[string(modelName)]; subOk {
continue
} else {
unique[string(modelName)] = true
r.Model = string(modelName)
}
} else {
continue
}
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "DiskFreeSize"
res = append(res, r)
}
}
return res, nil
}
// showBlock show block storage information for the host system. // showBlock show block storage information for the host system.
func getBlock() ([]DeviceInfo, error) { func getBlock() ([]DeviceInfo, error) {
......
package main
import "testing"
func TestDiskTotalSize(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.DiskTotalSize()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
func TestDiskFreeSize(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.DiskFreeSize()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
//DiskUtils()
func TestDiskUtil(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.DiskUtil()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
package main
import "testing"
func TestCli(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
_ = cli
}
package main package main
import ( import (
"context"
"fmt" "fmt"
"syscall" "syscall"
"time" "time"
"github.com/jaypipes/ghw" "github.com/jaypipes/ghw"
"github.com/pkg/errors" "github.com/pkg/errors"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
// "github.com/pkg/errors" // "github.com/pkg/errors"
// "github.com/spf13/cobra" // "github.com/spf13/cobra"
) )
func (c *ProApi) CpuUtil() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, warnings, err := c.API.Query(ctx, `(1 - sum(rate(node_cpu_seconds_total{mode="idle"}[1m])) by (instance) / sum(rate(node_cpu_seconds_total[1m])) by (instance) ) * 100`, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
for k, v := range elem.Metric {
fmt.Println("k", k, "v", v)
}
r := DeviceInfo{}
// if modelName, ok := elem.Metric["modelName"]; ok {
// r.Model = string(modelName)
// } else {
// continue
// }
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = string(`(1 - sum(rate(node_cpu_seconds_total{mode="idle"}[1m])) by (instance) / sum(rate(node_cpu_seconds_total[1m])) by (instance) ) * 100`)
//}
r.Power = uint64(elem.Value)
r.Type = "CpuUtil"
res = append(res, r)
}
}
return res, nil
}
// cpuCmd represents the install command // cpuCmd represents the install command
// var cpuCmd = &cobra.Command{ // var cpuCmd = &cobra.Command{
// Use: "cpu", // Use: "cpu",
...@@ -44,7 +98,6 @@ func getCPU() ([]DeviceInfo, error) { ...@@ -44,7 +98,6 @@ func getCPU() ([]DeviceInfo, error) {
func getCPUUsage() ([]DeviceInfo, error) { func getCPUUsage() ([]DeviceInfo, error) {
res := make([]DeviceInfo, 0) res := make([]DeviceInfo, 0)
var rusage syscall.Rusage var rusage syscall.Rusage
...@@ -53,7 +106,7 @@ func getCPUUsage() ([]DeviceInfo, error) { ...@@ -53,7 +106,7 @@ func getCPUUsage() ([]DeviceInfo, error) {
if err := syscall.Getrusage(pid, &rusage); err != nil { if err := syscall.Getrusage(pid, &rusage); err != nil {
fmt.Println("Getrusage",err.Error()) fmt.Println("Getrusage", err.Error())
return nil, err return nil, err
} }
......
package main
import "testing"
func TestCpuUtil(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.CpuUtil()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
{
"swagger": "2.0",
"info": {
"title": "GPU+Model service",
"version": "1.0.0"
},
"paths": {
"/hw": {
"post": {
"summary": "get host hardware info and usage",
"responses": {
"200": {
"description": "success",
"schema": {
"$ref": "#/definitions/hw"
}
}
}
}
},
"/callback": {
"post": {}
}
},
"definitions": {
"hw": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"msg": {
"type": "string"
},
"data": {
"type": "object",
"properties": {
}
}
}
},
"gpu": {
"type": "object",
"properties": {
"seq": {
"type": "integer",
"format": "int64"
},
"model": {
"type": "string"
},
"mem_util": {
"type": "integer",
"format": "int64"
},
"total_mem": {
"type": "integer",
"format": "int64"
},
"power": {
"type": "integer",
"format": "int64"
},
"gpu_tmp": {
"type": "integer",
"format": "int64"
},
}
}
"cpu": {
"type": "object",
"properties": {
"seq": {
"type": "integer",
"format": "int64"
},
"model": {
"type": "string"
},
"mem_util": {
"type": "integer",
"format": "int64"
},
"total_mem": {
"type": "integer",
"format": "int64"
},
"power": {
"type": "integer",
"format": "int64"
},
"gpu_tmp": {
"type": "integer",
"format": "int64"
},
}
}
"mem": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"format": "int64"
},
"used": {
"type": "string"
},
"free": {
"type": "integer",
"format": "int64"
},
}
}
"disk": {
"type": "object",
"properties": {
"total": {
"type": "integer",
"format": "int64"
},
"mount": {
"type": "string"
},
"used": {
"type": "integer",
"format": "int64"
},
}
}
"network": {
"type": "object",
"properties": {
"seed": {
"type": "integer",
"format": "int64"
},
"send": {
"type": "integer",
"format": "int64"
},
"receive": {
"type": "integer",
"format": "int64"
},
}
}
"Error": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
},
"message": {
"type": "string"
}
}
}
}
}
openapi: 3.0.0
servers:
- url: http://124.193.167.71:5000/
description: Default server
info:
description: |
This is a sample sniper wallet server.
You can find out more http://124.193.167.71:8001/docs/polygon/Uniswap
## Introduction
This API is documented in **OpenAPI format** and is based on
version: 0.0.1
title: Swagger Uniswap Wallet YAML
termsOfService: "http://swagger.io/terms/"
contact:
name: API Support
email: apiteam@swagger.io
url: https://github.com/Redocly/redoc
x-logo:
url: "https://redocly.github.io/redoc/petstore-logo.png"
altText: Petstore logo
license:
name: Apache 2.0
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
externalDocs:
description: Find out how to create Github repo for your OpenAPI spec.
url: "https://github.com/Rebilly/generator-openapi-repo"
tags:
- name: MonitorHardware
description: Everything about host hardware
# - name: User
# description: Everything about user
# - name: store
# description: Access to Petstore orders
# x-displayName: Petstore Orders
# - name: user
# description: Operations about user
# x-displayName: Users
# - name: pet_model
# x-displayName: The Pet Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Pet" />
# - name: store_model
# x-displayName: The Order Model
# description: |
# <SchemaDefinition schemaRef="#/components/schemas/Order" exampleRef="#/components/examples/Order" showReadOnly={true} showWriteOnly={true} />
x-tagGroups:
- name: General
tags:
- pet
- store
- name: User Management
tags:
- user
- name: Models
tags:
- pet_model
- store_model
paths:
/hd:
get:
summary: get host hardware info and usage
tags:
- MonitorHardware
responses:
"200":
description: successful operation
content:
application/json:
schema:
type: object
properties:
data:
$ref: "#/components/schemas/hw"
code:
type: integer
format: int64
msg:
type: string
components:
securitySchemes:
api_key:
description: |
For this sample, you can use the api key `special-key` to test the authorization filters.
in: header
name: api_key
type: apiKey
petstore_auth:
description: |
Get access to data while protecting your account credentials.
OAuth2 is also a safer and more secure way to give you access.
flows:
implicit:
authorizationUrl: http://petstore.swagger.io/api/oauth/dialog
scopes:
read:pets: read your pets
write:pets: modify pets in your account
type: oauth2
schemas:
hw:
type: object
properties:
gpus:
type: array
items:
$ref: "#/components/schemas/gpu"
cpus:
type: object
properties:
total_util:
type: integer
format: int64
list:
type: array
items:
$ref: "#/components/schemas/cpu"
mem:
type: object
properties:
mem_total:
type: integer
format: int64
mem_free:
type: integer
format: int64
mem_used:
type: integer
format: int64
mem_util:
type: integer
format: int64
disk:
type: array
items:
$ref: "#/components/schemas/filesystem"
networks:
type: array
items:
$ref: "#/components/schemas/network"
network:
type: object
properties:
speed:
type: integer
format: int64
send:
type: integer
format: int64
receive:
type: integer
format: int64
filesystem:
type: object
properties:
device:
type: string
mount_points:
type: array
items:
type: string
free_bytes:
type: integer
format: int64
size_bytes:
type: integer
format: int64
gpu:
type: object
properties:
seq:
type: integer
format: int64
model:
type: string
mem_util:
type: integer
format: int64
mem_total:
type: integer
format: int64
power:
type: integer
format: int64
gpu_tmp:
type: integer
format: int64
cpu:
type: object
properties:
seq:
type: integer
format: int64
model:
description: addr
type: string
thread:
type: integer
format: int64
physical:
type: integer
format: int64
...@@ -30,7 +30,7 @@ import ( ...@@ -30,7 +30,7 @@ import (
func ExampleAPI_query() { func ExampleAPI_query() {
client, err := api.NewClient(api.Config{ client, err := api.NewClient(api.Config{
Address: "http://demo.robustperception.io:9090", Address: "http://192.168.1.21:9090",
}) })
if err != nil { if err != nil {
fmt.Printf("Error creating client: %v\n", err) fmt.Printf("Error creating client: %v\n", err)
......
...@@ -7,24 +7,39 @@ toolchain go1.22.1 ...@@ -7,24 +7,39 @@ toolchain go1.22.1
require github.com/jaypipes/ghw v0.12.0 require github.com/jaypipes/ghw v0.12.0
require ( require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/NVIDIA/go-nvml v0.12.0-3 // indirect github.com/NVIDIA/go-nvml v0.12.0-3 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/StackExchange/wmi v1.2.1 // indirect github.com/StackExchange/wmi v1.2.1 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gofiber/fiber/v3 v3.0.0-20240313181542-df1f877cc0be // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.3 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect
github.com/go-openapi/spec v0.20.4 // indirect
github.com/go-openapi/swag v0.19.15 // indirect
github.com/gofiber/fiber v1.14.6 // indirect
github.com/gofiber/fiber/v2 v2.52.0 // indirect
github.com/gofiber/fiber/v3 v3.0.0-beta.2 // indirect
github.com/gofiber/swagger v1.0.0 // indirect
github.com/gofiber/utils v0.0.10 // indirect
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
github.com/golang/protobuf v1.5.3 // indirect github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.6.0 // indirect github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/schema v1.1.0 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.6 // indirect github.com/klauspost/compress v1.17.8 // indirect
github.com/kr/text v0.2.0 // indirect github.com/kr/text v0.2.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect github.com/modern-go/reflect2 v1.0.2 // indirect
...@@ -35,14 +50,18 @@ require ( ...@@ -35,14 +50,18 @@ require (
github.com/prometheus/common v0.51.1 // indirect github.com/prometheus/common v0.51.1 // indirect
github.com/prometheus/procfs v0.12.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285 // indirect github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/shopspring/decimal v1.3.1 // indirect github.com/shopspring/decimal v1.3.1 // indirect
github.com/swaggo/files/v2 v2.0.0 // indirect
github.com/swaggo/swag v1.16.3 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.52.0 // indirect github.com/valyala/fasthttp v1.52.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/net v0.22.0 // indirect golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sys v0.18.0 // indirect golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/appengine v1.6.7 // indirect google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.33.0 // indirect google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
......
github.com/KyleBanks/depth v1.2.1 h1:5h8fQADFrWtarTdtDudMmGsC7GPbOAu6RVB3ffsVFHc=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE= github.com/NVIDIA/go-nvml v0.12.0-3 h1:QwfjYxEqIQVRhl8327g2Y3ZvKResPydpGSKtCIIK9jE=
github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA= github.com/NVIDIA/go-nvml v0.12.0-3/go.mod h1:SOufGc5Wql+cxrIZ8RyJwVKDYxfbs4WPkHXqadcbfvA=
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
...@@ -16,10 +23,32 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME ...@@ -16,10 +23,32 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.2.5/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY= github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0= github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.19.6 h1:UBIxjkht+AWIgYzCDSv2GN+E/togfwXUJFRTWhl2Jjs=
github.com/go-openapi/jsonreference v0.19.6/go.mod h1:diGHMEHg2IqXZGKxqyvWdfWU/aim5Dprw5bqpKkTvns=
github.com/go-openapi/spec v0.20.4 h1:O8hJrt0UMnhHcluhIdUgCLRWyM2x7QkBXRvOs7m+O1M=
github.com/go-openapi/spec v0.20.4/go.mod h1:faYFR1CvsJZ0mNsmsphTMSoRrNV3TEDoAM7FOEWeq8I=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-openapi/swag v0.19.15 h1:D2NRCBzS9/pEY3gP9Nl8aDqGUcPFrwG2p+CNFrLyrCM=
github.com/go-openapi/swag v0.19.15/go.mod h1:QYRuS/SOXUCsnplDa677K7+DxSOj6IPNl/eQntq43wQ=
github.com/gofiber/fiber v1.14.6 h1:QRUPvPmr8ijQuGo1MgupHBn8E+wW0IKqiOvIZPtV70o=
github.com/gofiber/fiber v1.14.6/go.mod h1:Yw2ekF1YDPreO9V6TMYjynu94xRxZBdaa8X5HhHsjCM=
github.com/gofiber/fiber/v2 v2.52.0 h1:S+qXi7y+/Pgvqq4DrSmREGiFwtB7Bu6+QFLuIHYw/UE=
github.com/gofiber/fiber/v2 v2.52.0/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofiber/fiber/v3 v3.0.0-20240313181542-df1f877cc0be h1:k24c/hl8cK7TilhP693AN3bJ62zqKh+Z7NFswe0CwX4= github.com/gofiber/fiber/v3 v3.0.0-20240313181542-df1f877cc0be h1:k24c/hl8cK7TilhP693AN3bJ62zqKh+Z7NFswe0CwX4=
github.com/gofiber/fiber/v3 v3.0.0-20240313181542-df1f877cc0be/go.mod h1:vYjHc92UkENqQ7bj/JhoTl84ZPKnb+seO8ddclUT0Xs= github.com/gofiber/fiber/v3 v3.0.0-20240313181542-df1f877cc0be/go.mod h1:vYjHc92UkENqQ7bj/JhoTl84ZPKnb+seO8ddclUT0Xs=
github.com/gofiber/fiber/v3 v3.0.0-beta.2 h1:mVVgt8PTaHGup3NGl/+7U7nEoZaXJ5OComV4E+HpAao=
github.com/gofiber/fiber/v3 v3.0.0-beta.2/go.mod h1:w7sdfTY0okjZ1oVH6rSOGvuACUIt0By1iK0HKUb3uqM=
github.com/gofiber/swagger v1.0.0 h1:BzUzDS9ZT6fDUa692kxmfOjc1DZiloLiPK/W5z1H1tc=
github.com/gofiber/swagger v1.0.0/go.mod h1:QrYNF1Yrc7ggGK6ATsJ6yfH/8Zi5bu9lA7wB8TmCecg=
github.com/gofiber/utils v0.0.10 h1:3Mr7X7JdCUo7CWf/i5sajSaDmArEDtti8bM1JUVso2U=
github.com/gofiber/utils v0.0.10/go.mod h1:9J5aHFUIjq0XfknT4+hdSMG6/jzfaAgCu4HEbWDeBlo=
github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw= github.com/gofiber/utils/v2 v2.0.0-beta.3 h1:pfOhUDDVjBJpkWv6C5jaDyYLvpui7zQ97zpyFFsUOKw=
github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo= github.com/gofiber/utils/v2 v2.0.0-beta.3/go.mod h1:jsl17+MsKfwJjM3ONCE9Rzji/j8XNbwjhUVTjzgfDCo=
github.com/gofiber/utils/v2 v2.0.0-beta.4 h1:1gjbVFFwVwUb9arPcqiB6iEjHBwo7cHsyS41NeIW3co=
github.com/gofiber/utils/v2 v2.0.0-beta.4/go.mod h1:sdRsPU1FXX6YiDGGxd+q2aPJRMzpsxdzCXo9dz+xtOY=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
...@@ -28,27 +57,44 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ ...@@ -28,27 +57,44 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.1.0 h1:CamqUDOFUBqzrvxuz2vEwo8+SUdwsluFh7IlzJh30LY=
github.com/gorilla/schema v1.1.0/go.mod h1:kgLaKoK1FELgZqMAVxx/5cbj0kT+57qxUrAlIO2eleU=
github.com/jaypipes/ghw v0.12.0 h1:xU2/MDJfWmBhJnujHY9qwXQLs3DBsf0/Xa9vECY0Tho= github.com/jaypipes/ghw v0.12.0 h1:xU2/MDJfWmBhJnujHY9qwXQLs3DBsf0/Xa9vECY0Tho=
github.com/jaypipes/ghw v0.12.0/go.mod h1:jeJGbkRB2lL3/gxYzNYzEDETV1ZJ56OKr+CSeSEym+g= github.com/jaypipes/ghw v0.12.0/go.mod h1:jeJGbkRB2lL3/gxYzNYzEDETV1ZJ56OKr+CSeSEym+g=
github.com/jaypipes/pcidb v1.0.0 h1:vtZIfkiCUE42oYbJS0TAq9XSfSmcsgo9IdxSm9qzYU8= github.com/jaypipes/pcidb v1.0.0 h1:vtZIfkiCUE42oYbJS0TAq9XSfSmcsgo9IdxSm9qzYU8=
github.com/jaypipes/pcidb v1.0.0/go.mod h1:TnYUvqhPBzCKnH34KrIX22kAeEbDCSRJ9cqLRCuNDfk= github.com/jaypipes/pcidb v1.0.0/go.mod h1:TnYUvqhPBzCKnH34KrIX22kAeEbDCSRJ9cqLRCuNDfk=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs=
github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI= github.com/klauspost/compress v1.17.6 h1:60eq2E/jlfwQXtvZEeBUYADs+BwKBWURIY+Gj2eRGjI=
github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM= github.com/klauspost/compress v1.17.6/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU=
github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.6 h1:8yTIVnZgCoiM1TgqoeTl+LfU5Jg6/xL3QhGQnimLYnA=
github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
...@@ -58,6 +104,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G ...@@ -58,6 +104,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
...@@ -75,24 +122,41 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k ...@@ -75,24 +122,41 @@ github.com/prometheus/procfs v0.12.0 h1:jluTpSng7V9hY0O2R9DzzJHYb2xULk9VTR1V1R/k
github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo= github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3cnaOZAZEfOo=
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285 h1:d54EL9l+XteliUfUCGsEwwuk65dmmxX85VXF+9T6+50= github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285 h1:d54EL9l+XteliUfUCGsEwwuk65dmmxX85VXF+9T6+50=
github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285/go.mod h1:fxIDly1xtudczrZeOOlfaUvd2OPb2qZAPuWdU2BsBTk= github.com/ricochet2200/go-disk-usage/du v0.0.0-20210707232629-ac9918953285/go.mod h1:fxIDly1xtudczrZeOOlfaUvd2OPb2qZAPuWdU2BsBTk=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=
github.com/swaggo/swag v1.16.3 h1:PnCYjPCah8FK4I26l2F/KQ4yz3sILcVUN3cTlBFA9Pg=
github.com/swaggo/swag v1.16.3/go.mod h1:DImHIuOFXKpMFAQjcC7FG4m3Dg4+QuUgUzJmKjI/gRk=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA=
github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0=
github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ= github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI=
golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8 h1:OH54vjqzRWmbJ62fjuhxy7AxFFgoHN0/DPc/UrL8cAs=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
...@@ -101,11 +165,18 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= ...@@ -101,11 +165,18 @@ golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o=
golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c= google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6c=
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
...@@ -118,8 +189,12 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh ...@@ -118,8 +189,12 @@ google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHh
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg= gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM=
howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g= howett.net/plist v1.0.0/go.mod h1:lqaXoTrLY4hg8tnEzNru53gicrbv7rrk+2xJA/7hw9g=
package main package main
import ( import (
"context"
"fmt" "fmt"
"time"
"github.com/NVIDIA/go-nvml/pkg/nvml" v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
) )
// NVIDIA GeForce RTX 3080 //DCGM_FI_DEV_POWER_USAGE
func (c *ProApi) GpuPowerUsage() ([]DeviceInfo, error) {
func getGPU() ([]DeviceInfo, error) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
ret := nvml.Init() defer cancel()
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret)) result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_POWER_USAGE", time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
} }
defer func() { // fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
ret := nvml.Shutdown()
if ret != nvml.SUCCESS { res := make([]DeviceInfo, 0, 8)
fmt.Println("defer", nvml.ErrorString(ret)) switch {
//return nil, fmt.Errorf(nvml.ErrorString(ret)) case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["modelName"]; ok {
r.Model = string(modelName)
} else {
continue
}
if name, ok := elem.Metric["__name__"]; ok {
r.Param = string(name)
}
r.Power = uint64(elem.Value)
r.Type = "GpuPower"
res = append(res, r)
} }
}() }
count, ret := nvml.DeviceGetCount() return res, nil
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret)) }
func (c *ProApi) GpuMemTemp() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_MEMORY_TEMP", time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
} }
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, count) res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
for i := 0; i < count; i++ { vectorVal := result.(model.Vector)
device, ret := nvml.DeviceGetHandleByIndex(i) for _, elem := range vectorVal {
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret))
}
// memory, err := device.GetMemoryInfo() // for k, v := range elem.Metric {
// if err != nvml.SUCCESS { // fmt.Println("k", k, "v", v)
// panic(err) // }
// }
// d1, _, err := device.GetDriverModel() r := DeviceInfo{}
// if err != nvml.SUCCESS { if modelName, ok := elem.Metric["modelName"]; ok {
// //panic(err) r.Model = string(modelName)
// } } else {
continue
}
name, ret := device.GetName() if name, ok := elem.Metric["__name__"]; ok {
if ret != nvml.SUCCESS { r.Param = string(name)
return nil, fmt.Errorf(nvml.ErrorString(ret)) }
}
r.Power = uint64(elem.Value)
r.Type = "GpuMemTemp"
memory, ret := device.GetMemoryInfo() res = append(res, r)
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret))
//fmt.Println(err)
} }
}
//fmt.Printf(" %v\n", proc) return res, nil
e := DeviceInfo{ }
Type: fmt.Sprintf("GPU-%d", i),
Model: name,
Param: "device.GetMemoryInfo()",
Power: uint64(memory.Total),
}
res = append(res, e) func (c *ProApi) GpuTemp() ([]DeviceInfo, error) {
c := uint64(0) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if v, ok := comput[name]; ok { result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_GPU_TEMP", time.Now(), v1.WithTimeout(5*time.Second))
c = v if err != nil {
} return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
// } else { res := make([]DeviceInfo, 0, 8)
// fmt.Println("can not find the model '" + name + "'") switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
// for k, v := range comput { vectorVal := result.(model.Vector)
// fmt.Println(k, v)
// }
// }
e = DeviceInfo{ for _, elem := range vectorVal {
Type: fmt.Sprintf("GPU-%d", i),
Model: name, // for k, v := range elem.Metric {
Param: "compute", // fmt.Println("k", k, "v", v)
Power: c, // }
}
r := DeviceInfo{}
if modelName, ok := elem.Metric["modelName"]; ok {
r.Model = string(modelName)
} else {
continue
}
res = append(res, e) if name, ok := elem.Metric["__name__"]; ok {
r.Param = string(name)
}
r.Power = uint64(elem.Value)
r.Type = "GpuTemp"
res = append(res, r)
}
} }
return res, nil return res, nil
} }
func getGpuUsage() ([]DeviceInfo, error) { func (c *ProApi) GpuUtil() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
ret := nvml.Init() result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_GPU_UTIL", time.Now(), v1.WithTimeout(5*time.Second))
if ret != nvml.SUCCESS { if err != nil {
return nil, fmt.Errorf(nvml.ErrorString(ret)) return nil, err
} }
defer func() { if len(warnings) > 0 {
ret := nvml.Shutdown() fmt.Printf("Warnings: %v\n", warnings)
if ret != nvml.SUCCESS { }
fmt.Println("defer", nvml.ErrorString(ret)) // fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
//return nil, fmt.Errorf(nvml.ErrorString(ret)) for _, elem := range vectorVal {
//log.Fatalf("Unable to shutdown NVML: %v", nvml.ErrorString(ret))
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["modelName"]; ok {
r.Model = string(modelName)
} else {
continue
}
if name, ok := elem.Metric["__name__"]; ok {
r.Param = string(name)
}
r.Power = uint64(elem.Value)
r.Type = "GpuUtil"
res = append(res, r)
} }
}() }
count, ret := nvml.DeviceGetCount() return res, nil
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret)) }
//log.Fatalf("Unable to get device count: %v", nvml.ErrorString(ret))
// DCGM_FI_DEV_MEM_COPY_UTIL
func (c *ProApi) GpuMemUtil() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_MEM_COPY_UTIL", time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
} }
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, count) res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
for i := 0; i < count; i++ { vectorVal := result.(model.Vector)
device, ret := nvml.DeviceGetHandleByIndex(i) for _, elem := range vectorVal {
if ret != nvml.SUCCESS {
return nil, fmt.Errorf(nvml.ErrorString(ret))
//log.Fatalf("Unable to get device at index %d: %v", i, nvml.ErrorString(ret))
}
name, ret := device.GetName() // for k, v := range elem.Metric {
if ret != nvml.SUCCESS { // fmt.Println("k", k, "v", v)
return nil, fmt.Errorf(nvml.ErrorString(ret)) // }
//panic(err)
}
utilization, ret := device.GetUtilizationRates() r := DeviceInfo{}
if modelName, ok := elem.Metric["modelName"]; ok {
r.Model = string(modelName)
} else {
continue
}
if ret != nvml.SUCCESS { if name, ok := elem.Metric["__name__"]; ok {
return nil, fmt.Errorf(nvml.ErrorString(ret)) r.Param = string(name)
} }
r.Power = uint64(elem.Value)
r.Type = "GPU-Mem-Util"
e := DeviceInfo{ res = append(res, r)
Type: fmt.Sprintf("GPU-%d", i),
Model: name,
Param: "gpu usage",
Power: uint64(utilization.Gpu),
} }
}
res = append(res, e) return res, nil
e = DeviceInfo{ }
Type: fmt.Sprintf("GPU-%d", i),
Model: name, func (c *ProApi) GpuInfo() ([]DeviceInfo, error) {
Param: "gpu mem usage",
Power: uint64(utilization.Memory), ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
} defer cancel()
result, warnings, err := c.API.Query(ctx, "DCGM_FI_DEV_GPU_UTIL", time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res = append(res, e) res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
//fmt.Println("utilization", utilization) vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["modelName"]; ok {
r.Model = string(modelName)
} else {
continue
}
if gpuNum, ok := elem.Metric["gpu"]; ok {
//r.Model = string(modelName)
r.Param = string(gpuNum)
}
//if name, ok := elem.Metric["__name__"]; ok {
//r.Param = fmt.Sprintf("get by %s", r.Model)
//}
fmt.Println("r.Model", r.Model, "r.Model")
r.Power = comput[r.Model]
r.Type = "GpuInfo"
res = append(res, r)
}
} }
return res, nil return res, nil
} }
// NVIDIA GeForce RTX 3080
// func getGPU() ([]DeviceInfo, error) {
// ret := nvml.Init()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// defer func() {
// ret := nvml.Shutdown()
// if ret != nvml.SUCCESS {
// fmt.Println("defer", nvml.ErrorString(ret))
// //return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// }()
// count, ret := nvml.DeviceGetCount()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// res := make([]DeviceInfo, 0, count)
// for i := 0; i < count; i++ {
// device, ret := nvml.DeviceGetHandleByIndex(i)
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// // memory, err := device.GetMemoryInfo()
// // if err != nvml.SUCCESS {
// // panic(err)
// // }
// // d1, _, err := device.GetDriverModel()
// // if err != nvml.SUCCESS {
// // //panic(err)
// // }
// name, ret := device.GetName()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// memory, ret := device.GetMemoryInfo()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// //fmt.Println(err)
// }
// //fmt.Printf(" %v\n", proc)
// e := DeviceInfo{
// Type: fmt.Sprintf("GPU-%d", i),
// Model: name,
// Param: "device.GetMemoryInfo()",
// Power: uint64(memory.Total),
// }
// res = append(res, e)
// c := uint64(0)
// if v, ok := comput[name]; ok {
// c = v
// }
// // } else {
// // fmt.Println("can not find the model '" + name + "'")
// // for k, v := range comput {
// // fmt.Println(k, v)
// // }
// // }
// e = DeviceInfo{
// Type: fmt.Sprintf("GPU-%d", i),
// Model: name,
// Param: "compute",
// Power: c,
// }
// res = append(res, e)
// }
// return res, nil
// }
// func getGpuUsage() ([]DeviceInfo, error) {
// ret := nvml.Init()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// defer func() {
// ret := nvml.Shutdown()
// if ret != nvml.SUCCESS {
// fmt.Println("defer", nvml.ErrorString(ret))
// //return nil, fmt.Errorf(nvml.ErrorString(ret))
// //log.Fatalf("Unable to shutdown NVML: %v", nvml.ErrorString(ret))
// }
// }()
// count, ret := nvml.DeviceGetCount()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// //log.Fatalf("Unable to get device count: %v", nvml.ErrorString(ret))
// }
// res := make([]DeviceInfo, 0, count)
// for i := 0; i < count; i++ {
// device, ret := nvml.DeviceGetHandleByIndex(i)
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// //log.Fatalf("Unable to get device at index %d: %v", i, nvml.ErrorString(ret))
// }
// name, ret := device.GetName()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// //panic(err)
// }
// utilization, ret := device.GetUtilizationRates()
// if ret != nvml.SUCCESS {
// return nil, fmt.Errorf(nvml.ErrorString(ret))
// }
// e := DeviceInfo{
// Type: fmt.Sprintf("GPU-%d", i),
// Model: name,
// Param: "gpu usage",
// Power: uint64(utilization.Gpu),
// }
// res = append(res, e)
// e = DeviceInfo{
// Type: fmt.Sprintf("GPU-%d", i),
// Model: name,
// Param: "gpu mem usage",
// Power: uint64(utilization.Memory),
// }
// res = append(res, e)
// //fmt.Println("utilization", utilization)
// }
// return res, nil
// }
var comput map[string]uint64 var comput map[string]uint64
//NVIDIA GeForce RTX 3080, //NVIDIA GeForce RTX 3080,
......
package main
import "testing"
func TestGpuUtil(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.GpuUtil()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
func TestGpuMemUtil(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.GpuMemUtil()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
//GpuInfo()
func TestGpuInfo(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.GpuInfo()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
...@@ -2,162 +2,384 @@ package main ...@@ -2,162 +2,384 @@ package main
import ( import (
"fmt" "fmt"
"log"
"github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/swagger"
) )
func main() { func main() {
//ExampleAPI_query()
ExampleAPI_query() cli, err := NewProCli("http://192.168.1.21:9090")
} if err != nil {
fmt.Println(err.Error())
return
}
func main123() {
// Initialize a new Fiber app // Initialize a new Fiber app
app := fiber.New() app := fiber.New()
app.Use(cors.New())
app.Static("/swagger/docs", "./docs")
app.Get("/swagger/*", swagger.New(swagger.Config{ // custom
URL: "http://124.193.167.71:5000/swagger/docs/swagger.yaml", //http://124.193.167.71:8000/
DeepLinking: false,
// Expand ("list") or Collapse ("none") tag groups by default
DocExpansion: "none",
// Prefill OAuth ClientId on Authorize popup
// OAuth: &swagger.OAuthConfig{
// AppName: "OAuth Provider",
// ClientId: "21bb4edc-05a7-4afc-86f1-2e151e4ba6e2",
// },
// Ability to change OAuth2 redirect uri location
//OAuth2RedirectUrl: "http://localhost:8080/swagger/oauth2-redirect.html",
}))
app.Get("/hw", func(c *fiber.Ctx) error {
return nil
})
app.Get("/hw/usage", func(c *fiber.Ctx) error {
res := make([]DeviceInfo, 0, 10)
gpuUtils, err := cli.GpuUtil()
if err != nil {
return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
res = append(res, gpuUtils...)
//showMemory() gpuMemUtils, err := cli.GpuMemUtil()
if err != nil {
return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
res = append(res, gpuMemUtils...)
// Define a route for the GET method on the root path '/' diskUtil, err := cli.DiskUtil()
app.Get("/hw/info", func(c fiber.Ctx) error { if err != nil {
return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
res := make([]DeviceInfo, 0) res = append(res, diskUtil...)
block, err := getBlock() networkSpeed, err := cli.NetworkSpeed()
if err != nil { if err != nil {
c.SendString("getBlock err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, block...)
mem, err := getMemory() res = append(res, networkSpeed...)
cpuUtils, err := cli.CpuUtil()
if err != nil { if err != nil {
c.SendString("getMemory err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, mem...) res = append(res, cpuUtils...)
cpu, err := getCPU() //MemUtil()
memUtils, err := cli.MemUtil()
if err != nil { if err != nil {
c.SendString("getMemory err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, cpu...) res = append(res, memUtils...)
gpu, err := getGPU() netRece, err := cli.NetworkReceive()
if err != nil { if err != nil {
c.SendString("getGPU err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, gpu...) res = append(res, netRece...)
return c.JSON(res) netSend, err := cli.NetworkTransmit()
// Send a string response to the client if err != nil {
//return c.SendString("Hello, World 👋!") return c.JSON(Response{
}) Success: false,
Error: err.Error(),
})
}
res = append(res, netSend...)
app.Get("/hw/usage", func(c fiber.Ctx) error { diskFreeSize, err := cli.DiskFreeSize()
if err != nil {
return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
res := make([]DeviceInfo, 0) res = append(res, diskFreeSize...)
gpu, err := getGpuUsage() power, err := cli.GpuPowerUsage()
if err != nil { if err != nil {
c.SendString("getGpuUsage err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, gpu...) res = append(res, power...)
cpu, err := getCPUUsage() memTemp, err := cli.GpuMemTemp()
if err != nil { if err != nil {
c.SendString("getCPUUsage err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
fmt.Println("cpu", cpu) res = append(res, memTemp...)
gpuTemp, err := cli.GpuTemp()
if err != nil {
return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
res = append(res, gpuTemp...)
return c.JSON(Response{
Success: true,
Devices: res,
})
})
res = append(res, cpu...) app.Get("/hw/info", func(c *fiber.Ctx) error {
mem, err := getMemoryUsage() res := make([]DeviceInfo, 0, 10)
diskTotalSize, err := cli.DiskTotalSize()
if err != nil { if err != nil {
c.SendString("getMemoryUsage err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, mem...) res = append(res, diskTotalSize...)
memSize, err := cli.MemInfo()
block, err := getBlockUsage()
if err != nil { if err != nil {
c.SendString("getBlockUsage err: " + err.Error()) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
} }
res = append(res, block...) res = append(res, memSize...)
return c.JSON(res) gpuInfo, err := cli.GpuInfo()
//res := make([]DeviceInfo, 0) if err != nil {
//return c.JSON(res) return c.JSON(Response{
Success: false,
Error: err.Error(),
})
}
// Send a string response to the client res = append(res, gpuInfo...)
//return c.SendString("Hello, World 👋!")
return c.JSON(Response{
Success: true,
Devices: res,
})
}) })
// Start the server on port 3000 // Start the server on port 3000
app.Listen(":3000") log.Fatal(app.Listen(":5000"))
} }
// type Response struct {
// Use and distribution licensed under the Apache license version 2. Devices []DeviceInfo `json:"devices"`
// Success bool `json:"success"`
// See the COPYING file in the root project directory for full text. Error string `json:"error`
// }
// package main // func main123() {
// // Initialize a new Fiber app
// app := fiber.New()
// import ( // //showMemory()
// "fmt"
// "github.com/jaypipes/ghw" // // Define a route for the GET method on the root path '/'
// "github.com/pkg/errors" // app.Get("/hw/info", func(c fiber.Ctx) error {
// "github.com/spf13/cobra"
// )
// // blockCmd represents the install command // res := make([]DeviceInfo, 0)
// var blockCmd = &cobra.Command{
// Use: "block", // block, err := getBlock()
// Short: "Show block storage information for the host system",
// RunE: showBlock,
// }
// // showBlock show block storage information for the host system. // if err != nil {
// func showBlock(cmd *cobra.Command, args []string) error { // c.SendString("getBlock err: " + err.Error())
// block, err := ghw.Block()
// if err != nil {
// return errors.Wrap(err, "error getting block device info")
// }
// switch outputFormat {
// case outputFormatHuman:
// fmt.Printf("%v\n", block)
// for _, disk := range block.Disks {
// fmt.Printf(" %v\n", disk)
// for _, part := range disk.Partitions {
// fmt.Printf(" %v\n", part)
// }
// } // }
// case outputFormatJSON: // res = append(res, block...)
// fmt.Printf("%s\n", block.JSONString(pretty))
// case outputFormatYAML: // mem, err := getMemory()
// fmt.Printf("%s", block.YAMLString())
// }
// return nil
// }
// func init() { // if err != nil {
// rootCmd.AddCommand(blockCmd) // c.SendString("getMemory err: " + err.Error())
// }
// res = append(res, mem...)
// cpu, err := getCPU()
// if err != nil {
// c.SendString("getMemory err: " + err.Error())
// }
// res = append(res, cpu...)
// gpu, err := getGPU()
// if err != nil {
// c.SendString("getGPU err: " + err.Error())
// }
// res = append(res, gpu...)
// return c.JSON(res)
// // Send a string response to the client
// //return c.SendString("Hello, World 👋!")
// })
// app.Get("/hw/usage", func(c fiber.Ctx) error {
// res := make([]DeviceInfo, 0)
// gpu, err := getGpuUsage()
// if err != nil {
// c.SendString("getGpuUsage err: " + err.Error())
// }
// res = append(res, gpu...)
// cpu, err := getCPUUsage()
// if err != nil {
// c.SendString("getCPUUsage err: " + err.Error())
// }
// fmt.Println("cpu", cpu)
// res = append(res, cpu...)
// mem, err := getMemoryUsage()
// if err != nil {
// c.SendString("getMemoryUsage err: " + err.Error())
// }
// res = append(res, mem...)
// block, err := getBlockUsage()
// if err != nil {
// c.SendString("getBlockUsage err: " + err.Error())
// }
// res = append(res, block...)
// return c.JSON(res)
// //res := make([]DeviceInfo, 0)
// //return c.JSON(res)
// // Send a string response to the client
// //return c.SendString("Hello, World 👋!")
// })
// // Start the server on port 3000
// app.Listen(":3000")
// } // }
// //
// // Use and distribution licensed under the Apache license version 2.
// //
// // See the COPYING file in the root project directory for full text.
// //
// // package main
// // import (
// // "fmt"
// // "github.com/jaypipes/ghw"
// // "github.com/pkg/errors"
// // "github.com/spf13/cobra"
// // )
// // // blockCmd represents the install command
// // var blockCmd = &cobra.Command{
// // Use: "block",
// // Short: "Show block storage information for the host system",
// // RunE: showBlock,
// // }
// // // showBlock show block storage information for the host system.
// // func showBlock(cmd *cobra.Command, args []string) error {
// // block, err := ghw.Block()
// // if err != nil {
// // return errors.Wrap(err, "error getting block device info")
// // }
// // switch outputFormat {
// // case outputFormatHuman:
// // fmt.Printf("%v\n", block)
// // for _, disk := range block.Disks {
// // fmt.Printf(" %v\n", disk)
// // for _, part := range disk.Partitions {
// // fmt.Printf(" %v\n", part)
// // }
// // }
// // case outputFormatJSON:
// // fmt.Printf("%s\n", block.JSONString(pretty))
// // case outputFormatYAML:
// // fmt.Printf("%s", block.YAMLString())
// // }
// // return nil
// // }
// // func init() {
// // rootCmd.AddCommand(blockCmd)
// // }
package main package main
import ( import (
"context"
"fmt" "fmt"
"time"
"github.com/jaypipes/ghw" "github.com/jaypipes/ghw"
"github.com/pkg/errors" "github.com/pkg/errors"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
"github.com/shopspring/decimal" "github.com/shopspring/decimal"
) )
func (c *ProApi) MemUtil() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `(1- (node_memory_Buffers_bytes + node_memory_Cached_bytes + node_memory_MemFree_bytes) / node_memory_MemTotal_bytes) * 100`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
for k, v := range elem.Metric {
fmt.Println("k", k, "v", v)
}
r := DeviceInfo{}
// if modelName, ok := elem.Metric["modelName"]; ok {
// r.Model = string(modelName)
// } else {
// continue
// }
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "MemUtil"
res = append(res, r)
}
}
return res, nil
}
func (c *ProApi) MemInfo() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `node_memory_MemTotal_bytes/1024/1024/1024`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
for k, v := range elem.Metric {
fmt.Println("k", k, "v", v)
}
r := DeviceInfo{}
// if modelName, ok := elem.Metric["modelName"]; ok {
// r.Model = string(modelName)
// } else {
// continue
// }
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "MemInfo"
res = append(res, r)
}
}
return res, nil
}
// showMemory show memory information for the host system. // showMemory show memory information for the host system.
func getMemory() ([]DeviceInfo, error) { func getMemory() ([]DeviceInfo, error) {
mem, err := ghw.Memory() mem, err := ghw.Memory()
......
package main
import "testing"
func TestMemUtil(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.MemUtil()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
//MemInfo
func TestMemInfo(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.MemInfo()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
package main
import (
"context"
"fmt"
"time"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
"github.com/prometheus/common/model"
)
//node_network_speed_bytes/1024/1024/1024
func (c *ProApi) NetworkSpeed() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `rate(node_network_speed_bytes[10s])`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
if modelName, ok := elem.Metric["device"]; ok {
r.Model = string(modelName)
} else {
continue
}
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "NetworkSpeed"
res = append(res, r)
}
}
return res, nil
}
func (c *ProApi) NetworkReceive() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `sum by(instance) (irate(node_network_receive_bytes_total{device!~"bond.*?|lo"}[5m])) `
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
// for k, v := range elem.Metric {
// fmt.Println("k", k, "v", v)
// }
r := DeviceInfo{}
// if modelName, ok := elem.Metric["modelName"]; ok {
// r.Model = string(modelName)
// } else {
// continue
// }
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "NetworkReceive"
res = append(res, r)
}
}
return res, nil
}
//sum by(instance) (irate(node_network_receive_bytes_total{device!~"bond.*?|lo"}[5m]))
//sum by(instance) (irate(node_network_transmit_bytes{device!~"bond.*?|lo"}[5m]))
func (c *ProApi) NetworkTransmit() ([]DeviceInfo, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
queryStr := `sum by(instance) (irate(node_network_transmit_bytes_total{device!~"bond.*?|lo"}[5m]))`
result, warnings, err := c.API.Query(ctx, queryStr, time.Now(), v1.WithTimeout(5*time.Second))
if err != nil {
return nil, err
}
if len(warnings) > 0 {
fmt.Printf("Warnings: %v\n", warnings)
}
// fmt.Printf("Result:\n%v \nstring %v \n", result.Type(), result.String())
res := make([]DeviceInfo, 0, 8)
switch {
case result.Type() == model.ValScalar:
//scalarVal := result.(*model.Scalar)
// handle scalar stuff
case result.Type() == model.ValVector:
vectorVal := result.(model.Vector)
for _, elem := range vectorVal {
for k, v := range elem.Metric {
fmt.Println("k", k, "v", v)
}
r := DeviceInfo{}
// if modelName, ok := elem.Metric["modelName"]; ok {
// r.Model = string(modelName)
// } else {
// continue
// }
//if name, ok := elem.Metric["__name__"]; ok {
r.Param = queryStr
//}
r.Power = uint64(elem.Value)
r.Type = "NetworkTransmit"
res = append(res, r)
}
}
return res, nil
}
package main
import "testing"
func TestNetworkSpeed(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.NetworkSpeed()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
func TestNetworkReceive(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.NetworkReceive()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
//NetworkTransmit
func TestNetworkTransmit(t *testing.T) {
cli, err := NewProCli("http://192.168.1.21:9090")
if err != nil {
t.Fatal(err)
}
gpus, err := cli.NetworkTransmit()
for k, v := range gpus {
t.Log("k", k, "v", v)
}
}
package main
import (
"github.com/prometheus/client_golang/api"
v1 "github.com/prometheus/client_golang/api/prometheus/v1"
)
type ProApi struct {
v1.API
}
func NewProCli(addr string) (*ProApi, error) {
client, err := api.NewClient(api.Config{
//Address: "http://192.168.1.21:9090",
Address: addr,
})
if err != nil {
return nil, err
}
v1api := v1.NewAPI(client)
res := ProApi{
v1api,
}
return &res, nil
}
package main package main
type DeviceInfo struct { type DeviceInfo struct {
Type string Type string `json:"type"`
Model string Model string `json:"model"`
Param string Param string `json:"param"`
Power uint64 Power uint64 `json:"power"`
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment