2020-08-13 00:26:38 +08:00
|
|
|
package proxmox
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2020-11-13 07:12:29 +08:00
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
|
|
|
|
|
2020-08-13 00:26:38 +08:00
|
|
|
"github.com/influxdata/telegraf"
|
2021-04-10 01:15:04 +08:00
|
|
|
"github.com/influxdata/telegraf/config"
|
2020-08-13 00:26:38 +08:00
|
|
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-18 01:10:18 +08:00
|
|
|
var (
|
|
|
|
|
qemu resourceType = "qemu"
|
|
|
|
|
lxc resourceType = "lxc"
|
|
|
|
|
)
|
|
|
|
|
|
2020-08-13 00:26:38 +08:00
|
|
|
type Proxmox struct {
|
2021-04-10 01:15:04 +08:00
|
|
|
BaseURL string `toml:"base_url"`
|
|
|
|
|
APIToken string `toml:"api_token"`
|
|
|
|
|
ResponseTimeout config.Duration `toml:"response_timeout"`
|
|
|
|
|
NodeName string `toml:"node_name"`
|
2020-08-13 00:26:38 +08:00
|
|
|
tls.ClientConfig
|
|
|
|
|
|
2024-12-18 01:10:18 +08:00
|
|
|
Log telegraf.Logger `toml:"-"`
|
2020-08-13 00:26:38 +08:00
|
|
|
|
2024-12-18 01:10:18 +08:00
|
|
|
httpClient *http.Client
|
|
|
|
|
|
|
|
|
|
nodeSearchDomain string
|
|
|
|
|
requestFunction func(px *Proxmox, apiUrl string, method string, data url.Values) ([]byte, error)
|
2020-08-13 00:26:38 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type resourceType string
|
2020-08-13 00:26:38 +08:00
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type vmStats struct {
|
|
|
|
|
Data []vmStat `json:"data"`
|
2020-08-13 00:26:38 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type vmCurrentStats struct {
|
|
|
|
|
Data vmStat `json:"data"`
|
2020-10-21 22:50:29 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type vmStat struct {
|
2021-11-10 06:29:36 +08:00
|
|
|
ID json.Number `json:"vmid"`
|
2020-08-13 00:26:38 +08:00
|
|
|
Name string `json:"name"`
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
UsedMem json.Number `json:"mem"`
|
|
|
|
|
TotalMem json.Number `json:"maxmem"`
|
|
|
|
|
UsedDisk json.Number `json:"disk"`
|
|
|
|
|
TotalDisk json.Number `json:"maxdisk"`
|
|
|
|
|
UsedSwap json.Number `json:"swap"`
|
|
|
|
|
TotalSwap json.Number `json:"maxswap"`
|
|
|
|
|
Uptime json.Number `json:"uptime"`
|
2021-03-02 05:04:35 +08:00
|
|
|
CPULoad json.Number `json:"cpu"`
|
2020-08-13 00:26:38 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type vmConfig struct {
|
2020-08-13 00:26:38 +08:00
|
|
|
Data struct {
|
|
|
|
|
Searchdomain string `json:"searchdomain"`
|
|
|
|
|
Hostname string `json:"hostname"`
|
2020-11-13 07:12:29 +08:00
|
|
|
Template int `json:"template"`
|
2020-08-13 00:26:38 +08:00
|
|
|
} `json:"data"`
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 00:50:23 +08:00
|
|
|
type nodeDNS struct {
|
2020-08-13 00:26:38 +08:00
|
|
|
Data struct {
|
|
|
|
|
Searchdomain string `json:"search"`
|
|
|
|
|
} `json:"data"`
|
|
|
|
|
}
|
2021-11-15 23:14:09 +08:00
|
|
|
|
|
|
|
|
type metrics struct {
|
|
|
|
|
total int64
|
|
|
|
|
used int64
|
|
|
|
|
free int64
|
|
|
|
|
usedPercentage float64
|
|
|
|
|
}
|