mirror of
https://github.com/prometheus-community/windows_exporter.git
synced 2026-04-02 15:56:37 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
20762588b3 | ||
|
|
23397701ff |
@@ -75,13 +75,21 @@ func GetHNSEndpointStats(endpointID string) (EndpointStats, error) {
|
|||||||
return EndpointStats{}, err
|
return EndpointStats{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var stats EndpointStats
|
var response struct {
|
||||||
|
Success bool `json:"Success"`
|
||||||
|
Error string `json:"Error"`
|
||||||
|
Output EndpointStats `json:"Output"`
|
||||||
|
}
|
||||||
|
|
||||||
if err := json.Unmarshal([]byte(result), &stats); err != nil {
|
if err := json.Unmarshal([]byte(result), &response); err != nil {
|
||||||
return EndpointStats{}, fmt.Errorf("failed to unmarshal JSON %s: %w", result, err)
|
return EndpointStats{}, fmt.Errorf("failed to unmarshal JSON %s: %w", result, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return stats, nil
|
if !response.Success {
|
||||||
|
return EndpointStats{}, fmt.Errorf("HNSCall failed: %s", response.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.Output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func hnsCall(method, path, body *uint16) (string, error) {
|
func hnsCall(method, path, body *uint16) (string, error) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func NewCollector[T any](object string, _ []string) (*Collector, error) {
|
|||||||
counters: make(map[string]Counter),
|
counters: make(map[string]Counter),
|
||||||
}
|
}
|
||||||
|
|
||||||
valueType := reflect.TypeFor[T]().Elem()
|
valueType := reflect.TypeFor[T]()
|
||||||
|
|
||||||
if f, ok := valueType.FieldByName("Name"); ok {
|
if f, ok := valueType.FieldByName("Name"); ok {
|
||||||
if f.Type.Kind() == reflect.String {
|
if f.Type.Kind() == reflect.String {
|
||||||
|
|||||||
@@ -21,6 +21,22 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TestNewCollectorStructTypeParam guards against a regression where
|
||||||
|
// reflect.TypeFor[T]().Elem() panicked when T is a plain struct (not a pointer).
|
||||||
|
// See https://github.com/prometheus-community/windows_exporter/issues/2365
|
||||||
|
func TestNewCollectorStructTypeParam(t *testing.T) {
|
||||||
|
type systemCounterValues struct {
|
||||||
|
Name string
|
||||||
|
|
||||||
|
ProcessorQueueLength float64 `perfdata:"Processor Queue Length"`
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := NewCollector[systemCounterValues]("System", nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Skipf("skipping: failed to create collector: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkQueryPerformanceData(b *testing.B) {
|
func BenchmarkQueryPerformanceData(b *testing.B) {
|
||||||
for b.Loop() {
|
for b.Loop() {
|
||||||
_, _ = QueryPerformanceData("Global", "")
|
_, _ = QueryPerformanceData("Global", "")
|
||||||
|
|||||||
Reference in New Issue
Block a user