forked from prometheus/client_golang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Client: Support new metadata endpoint in v1
Introduces support for the new metadata endpoint from Prometheus. The new endpoint provides information independent of targets and collapses the unique combinations of HELP, TYPE and UNIT. Fixes prometheus#705 Signed-off-by: gotjosh <josue@grafana.com>
- Loading branch information
Showing
3 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/api" | ||
v1 "github.com/prometheus/client_golang/api/prometheus/v1" | ||
) | ||
|
||
func main() { | ||
client, err := api.NewClient(api.Config{ | ||
Address: "http://localhost:9091", | ||
}) | ||
if err != nil { | ||
fmt.Printf("Error creating client: %v\n", err) | ||
os.Exit(1) | ||
} | ||
|
||
v1api := v1.NewAPI(client) | ||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) | ||
defer cancel() | ||
metadata, err := v1api.MetricsMetadata(ctx, "", "") | ||
if err != nil { | ||
fmt.Printf("Error querying Prometheus: %v\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Println("Result:") | ||
for metric, metadata := range metadata { | ||
fmt.Println(metric) | ||
for _, m := range metadata { | ||
fmt.Println(m.Type) | ||
fmt.Println(m.Help) | ||
fmt.Println(m.Unit) | ||
fmt.Println("\n\n") | ||
} | ||
} | ||
|
||
} |