sacloud / sakuracloud_exporter

Prometheus exporter for SakuraCloud metrics.
Apache License 2.0
7 stars 2 forks source link

Cannnot Get Metrics #8

Closed ryoryotaro closed 5 years ago

ryoryotaro commented 5 years ago

I installed Binaries of sakuracloud_exporter v0.2.1, on my prometheus server. I ran it but cannnot get metrics.

$ curl localhost:9542
<html>
                        <head><title>SakuraCloud Exporter</title></head>
                        <body>
                        <h1>SakuraCloud Exporter</h1>
                        <p><a href="/metrics">Metrics</a></p>
                        </body>
                        </html>
$ curl localhost:9542/metrics
curl: (52) Empty reply from server

When I tried to get metrics , following logs ware displayed.

level=info ts=2019-03-13T03:58:27.921116072Z caller=main.go:51 msg="starting sakuracloud_exporter" version=0.2.1 revision=73f3ab1 goVersion=go1.11
level=info ts=2019-03-13T03:58:28.17385399Z caller=main.go:106 msg=listening addr=:9542

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x83bc6f]

goroutine 326 [running]:
github.com/sacloud/sakuracloud_exporter/collector.(*LoadBalancerCollector).collectLBStatus(0xc00014c180, 0xc00005f260, 0xc0003134e0)
        /home/travis/gopath/src/github.com/sacloud/sakuracloud_exporter/collector/loadbalancer.go:358 +0x44f
github.com/sacloud/sakuracloud_exporter/collector.(*LoadBalancerCollector).Collect.func1.2(0xc00014c180, 0xc00005f260, 0xc0003134e0, 0xc0002df200)
        /home/travis/gopath/src/github.com/sacloud/sakuracloud_exporter/collector/loadbalancer.go:177 +0x3f
created by github.com/sacloud/sakuracloud_exporter/collector.(*LoadBalancerCollector).Collect.func1
        /home/travis/gopath/src/github.com/sacloud/sakuracloud_exporter/collector/loadbalancer.go:176 +0x402

What I should do to solve this problem ?

yamamoto-febc commented 5 years ago

Hi @ryoryotaro, Thank you for your detailed reporting!

I have tried to reproduce this issue but I can't.

According to your reported error message, it seems to be occurring nil pointer exception. However, my load-balancer I have created for reproducing wasn't cause nil pointer exception. So we need more information for deep investigating.

Could you describe information of your load-balancer? If it is possible, please get load-balancer information by following command.

$ export TOKEN=your-api-token
$ export SECRET=your-api-secret
$ export ZONE=zone-name(is1a/is1b/tk1a/tk1v)
$ export LB_ID=your-load-balancer-ID

$ curl --user "$TOKEN":"$SECRET" \
     https://secure.sakura.ad.jp/cloud/zone/$ZONE/api/cloud/1.1/appliance/$LB_ID

NOTE

This command returns JSON. This JSON maybe includes your sensitive information, so please mask sensitive information before post it.

ryoryotaro commented 5 years ago

Thank you for your replay. I got a load-balancer information. By using command that you teached me.

curl --user "$TOKEN":"$SECRET" \
>      https://secure.sakura.ad.jp/cloud/zone/$ZONE/api/cloud/1.1/appliance/$LB_ID
{"Appliance":{"ID":"112700504481","Class":"loadbalancer","Name":"<lb-name>","Description":"\u66ae\u3089\u3057\u30cb\u30b9\u30bf\u306e\u30ed\u30fc\u30c9\u30d0\u30e9\u30f3\u30b5","Plan":{"ID":2},"Settings":{"LoadBalancer":[{"VirtualIPAddress":"<IPAddress>","Port":"80","DelayLoop":"10","Servers":[{"IPAddress":"<IPAddress>","Port":"80","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"},{"IPAddress":"<IPAddress>","Port":"80","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"}]},{"VirtualIPAddress":"<IPAddress>","Port":"443","DelayLoop":"10","Servers":[{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"},{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"}]},{"VirtualIPAddress":"<IPAddress>","Port":"80","DelayLoop":"10","SorryServer":"","Servers":[{"IPAddress":"<IPAddress>","Port":"80","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"},{"IPAddress":"<IPAddress>","Port":"80","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"}]},{"VirtualIPAddress":"<IPAddress>","Port":"443","DelayLoop":"10","SorryServer":"","Servers":[{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"},{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"}]},{"VirtualIPAddress":"<IPAddress>","Port":"443","DelayLoop":"10","SorryServer":"","Servers":[{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"},{"IPAddress":"<IPAddress>","Port":"443","HealthCheck":{"Protocol":"tcp"},"Enabled":"True"}]}]},"SettingsHash":"<Hash>","Remark":{"Zone":{"ID":21001},"Switch":{"ID":"112700504258"},"VRRP":{"VRID":1},"Network":{"NetworkMaskLen":28,"DefaultRoute":"<IPAddress>"},"Servers":[{"IPAddress":"<IPAddress>"},{"IPAddress":"<IPAddress>"}],"Plan":{"ID":2}},"Availability":"available","Instance":{"Status":"up","StatusChangedAt":"2018-10-29T09:52:09+09:00","Host":null},"ServiceClass":"cloud\/appliance\/loadbalancer-h\/2","CreatedAt":"2015-06-09T16:05:33+09:00","Icon":null,"Switch":{"ID":"112700504258","Name":"\u66ae\u3089\u3057\u30cb\u30b9\u30bf250Mbps\u30eb\u30fc\u30bf\u30b9\u30a4\u30c3\u30c1","Internet":null,"Scope":"user","Availability":"available","Zone":{"ID":21001,"Name":"tk1a","Region":{"ID":210,"Name":"\u6771\u4eac"}}},"Interfaces":[{"IPAddress":null,"UserIPAddress":"<IPAddress>","HostName":null,"Switch":{"ID":"112700504258","Name":"\u66ae\u3089\u3057\u30cb\u30b9\u30bf250Mbps\u30eb\u30fc\u30bf\u30b9\u30a4\u30c3\u30c1","Scope":"user","Subnet":{"NetworkAddress":"<IPAddress>","NetworkMaskLen":28,"DefaultRoute":"<IPAddress>","Internet":{"BandWidthMbps":250}},"UserSubnet":{"DefaultRoute":"<IPAddress>","NetworkMaskLen":28}}}],"Tags":[]},"is_ok":true}
yamamoto-febc commented 5 years ago

Thank you for your cooperation:+1: and sorry for my delayed response:pray:.

Hmm...:thinking: Your posted JSON seems no-problem.

Can you reproduce this problem even now?

I tried with using same as your load-balancer settings, but I can't reproduce...

ryoryotaro commented 5 years ago

Thank you for your replay. I tried to new API key ,but it’s still going on now.   But API key of another account worked well. The acount who's API works bad has a few LB and one of them do not use.
Is it the cause of this? That LB is now stopped.

I tried curl command you taught me by using LB_ID that do not use.

$ curl --user "$TOKEN":"$SECRET"  https://secure.saku
ra.ad.jp/cloud/zone/$ZONE/api/cloud/1.1/appliance/$LB_ID
{"is_fatal":true,"serial":"6f40a213f1a956c696332e6d5d6cb4ea","status":"404 Not Found","error_code":"not_found","error_msg":"\u5bfe\u8c61\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3002\u5bfe\u8c61\u306f\u5229\u7528\u3067\u304d\u306a\u3044\u72b6\u614b\u304b\u3001ID\u307e\u305f\u306f\u30d1\u30b9\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3059\u3002"}
yamamoto-febc commented 5 years ago

Sorry for the late replay again.

I have reproduced this. It is caused by following code.

https://github.com/sacloud/sakuracloud_exporter/blob/0.2.1/collector/loadbalancer.go#L346-L382

It is expecting to return serverStatus from SakuraCloud API. However, if real-server is set Enable=False, it will be returned nil and it isn't checked by this exporter. So this problem is coming.

I'm going to fix this.

yamamoto-febc commented 5 years ago

We just have released v0.2.2

https://github.com/sacloud/sakuracloud_exporter/releases/tag/0.2.2

Please try it:+1:

ryoryotaro commented 5 years ago

Thank you for your response. v0.2.2 worked well !