I have scraped data from Prometheus and the response is as below. I want to get the dimension data into an array (for manipulation) using Go. Can anyone Help me please. Thank You :)
func main() {
resp, err := http.Get("http://desktop-o1hkgm7:9090/federate?match%5B%5D=%7Bdialer_name%3D%22alertmanager%22%7D")
if err != nil {
log.Fatalln(err)
}
//We Read the response body on the line below.
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}
//Convert the body to type string
sb := string(body)
log.Printf(sb)
}
The response is as below:
# TYPE net_conntrack_dialer_conn_attempted_total untyped
net_conntrack_dialer_conn_attempted_total{dialer_name="alertmanager",instance="localhost:9090",job="prometheus"} 0 1609568651186
# TYPE net_conntrack_dialer_conn_closed_total untyped
net_conntrack_dialer_conn_closed_total{dialer_name="alertmanager",instance="localhost:9090",job="prometheus"} 0 1609568651186
# TYPE net_conntrack_dialer_conn_established_total untyped
net_conntrack_dialer_conn_established_total{dialer_name="alertmanager",instance="localhost:9090",job="prometheus"} 0 1609568651186
# TYPE net_conntrack_dialer_conn_failed_total untyped
net_conntrack_dialer_conn_failed_total{dialer_name="alertmanager",instance="localhost:9090",job="prometheus",reason="refused"} 0 1609568651186
"prometheus",reason="timeout"} 0 1609568651186
net_conntrack_dialer_conn_failed_total{dialer_name="alertmanager",instance="localhost:9090",job="prometheus",reason="unknown"} 0 1609568651186
I got this value after getting key and values. Can I loop through the 'name' and 'value' inside metric? How can I do this if it is possible? I tried but displays cannot loop through MetricFamily.