Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d634470d9 | ||
|
|
072f5bc7eb | ||
|
|
6e3bb0ff7b |
@@ -38,5 +38,6 @@ jobs:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
-t "${IMAGE_NAME}:${IMAGE_TAG}" \
|
-t "${IMAGE_NAME}:${IMAGE_TAG}" \
|
||||||
|
-t "${IMAGE_NAME}:latest" \
|
||||||
--push \
|
--push \
|
||||||
.
|
.
|
||||||
|
|||||||
@@ -75,26 +75,30 @@ topology with `cluster`, `node`, `pool`, `component`, `path`, and `leaf` labels:
|
|||||||
- `pve_node_zfs_write_errors`
|
- `pve_node_zfs_write_errors`
|
||||||
- `pve_node_zfs_checksum_errors`
|
- `pve_node_zfs_checksum_errors`
|
||||||
|
|
||||||
## Build
|
## Pull the Latest Image
|
||||||
|
|
||||||
|
The latest published version can be downloaded from the Gitea container registry:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker pull gitea.lostak.dev/lostakj/pve-exporter:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build Locally
|
||||||
|
|
||||||
To build the Docker image for PVE Exporter, use the following command:
|
To build the Docker image for PVE Exporter, use the following command:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker build --rm -t gitea.lostak.dev/lostakj/pve-exporter:version .
|
docker build --rm -t gitea.lostak.dev/lostakj/pve-exporter:latest .
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace `version` with the appropriate version tag you want to use.
|
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
To run the Docker image, use the following command:
|
To run the downloaded or locally built image, use the following command:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
docker run --rm -d -p 9090:9090 --name pve-exporter gitea.lostak.dev/lostakj/pve-exporter:version
|
docker run --rm -d -p 9090:9090 --name pve-exporter gitea.lostak.dev/lostakj/pve-exporter:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
Replace `version` with the appropriate version tag you used during the build.
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Once the Docker container is running, the exporter will be available on port `9090`. You can configure Prometheus to scrape metrics from the exporter by adding a new scrape configuration to your Prometheus configuration file.
|
Once the Docker container is running, the exporter will be available on port `9090`. You can configure Prometheus to scrape metrics from the exporter by adding a new scrape configuration to your Prometheus configuration file.
|
||||||
|
|||||||
@@ -63,6 +63,10 @@ func (c *Configuration) Validate() error {
|
|||||||
if !(u.Scheme == "http" || u.Scheme == "https") {
|
if !(u.Scheme == "http" || u.Scheme == "https") {
|
||||||
return fmt.Errorf("PVE host '%s' must be protocol type of HTTP or HTTPS.", host)
|
return fmt.Errorf("PVE host '%s' must be protocol type of HTTP or HTTPS.", host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if u.Hostname() == "" {
|
||||||
|
return fmt.Errorf("PVE host '%s' must contain an IP address or DNS name.", host)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate PVE token
|
// Validate PVE token
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package configuration
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestConfigurationValidateAcceptsIPAndDNSPveHosts(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
host string
|
||||||
|
}{
|
||||||
|
{name: "IP address", host: "https://192.168.0.10:8006"},
|
||||||
|
{name: "DNS name", host: "https://pve.example.com:8006"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
configuration := Configuration{
|
||||||
|
Host: "0.0.0.0",
|
||||||
|
PVE: PveConfiguration{
|
||||||
|
Hosts: []string{tt.host},
|
||||||
|
Token: PveTokenConfiguration{
|
||||||
|
TokenId: "token",
|
||||||
|
Secret: "secret",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := configuration.Validate(); err != nil {
|
||||||
|
t.Fatalf("Validate() rejected %s host %q: %v", tt.name, tt.host, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -55,7 +56,7 @@ func NewApiClient(endpoints []string, tokenId string, secret string, checkInterv
|
|||||||
// Prepare API endpoints.
|
// Prepare API endpoints.
|
||||||
for _, endpoint := range endpoints {
|
for _, endpoint := range endpoints {
|
||||||
apiEndpoint := ApiEndpoint{
|
apiEndpoint := ApiEndpoint{
|
||||||
host: endpoint,
|
host: normalizeApiHost(endpoint),
|
||||||
alive: false,
|
alive: false,
|
||||||
}
|
}
|
||||||
instance.endpoints = append(instance.endpoints, &apiEndpoint)
|
instance.endpoints = append(instance.endpoints, &apiEndpoint)
|
||||||
@@ -86,6 +87,11 @@ func NewApiClient(endpoints []string, tokenId string, secret string, checkInterv
|
|||||||
return &instance
|
return &instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// normalizeApiHost ensures API paths can be appended to either IP- or DNS-based hosts.
|
||||||
|
func normalizeApiHost(host string) string {
|
||||||
|
return strings.TrimRight(strings.TrimSpace(host), "/") + "/"
|
||||||
|
}
|
||||||
|
|
||||||
// Check endpoint liveness state.
|
// Check endpoint liveness state.
|
||||||
func (instance *ApiClient) checkEndpointsLiveness() {
|
func (instance *ApiClient) checkEndpointsLiveness() {
|
||||||
// We want to make sure other routines won't make any requests until we have checked for alive connections.
|
// We want to make sure other routines won't make any requests until we have checked for alive connections.
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package proxmox
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestNewApiClientNormalizesEndpointHosts(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
host string
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "IP without trailing slash",
|
||||||
|
host: "https://192.168.0.10:8006",
|
||||||
|
want: "https://192.168.0.10:8006/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "IP with trailing slash",
|
||||||
|
host: "https://192.168.0.10:8006/",
|
||||||
|
want: "https://192.168.0.10:8006/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "DNS without trailing slash",
|
||||||
|
host: "https://pve.example.com:8006",
|
||||||
|
want: "https://pve.example.com:8006/",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "DNS with trailing slash",
|
||||||
|
host: "https://pve.example.com:8006/",
|
||||||
|
want: "https://pve.example.com:8006/",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
client := NewApiClient([]string{tt.host}, "token", "secret", time.Second)
|
||||||
|
defer client.httpClient.CloseIdleConnections()
|
||||||
|
|
||||||
|
if got := client.endpoints[0].host; got != tt.want {
|
||||||
|
t.Fatalf("normalized endpoint host = %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
if got := client.endpoints[0].host + "api2/json/"; got != tt.want+"api2/json/" {
|
||||||
|
t.Fatalf("liveness URL = %q, want %q", got, tt.want+"api2/json/")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user