xperimental / nextcloud-exporter

Prometheus exporter for Nextcloud servers.
MIT License
226 stars 34 forks source link

Error during scrape: Client.Timeout exceeded while awaiting headers #108

Closed tim-krehan closed 7 months ago

tim-krehan commented 7 months ago

Hi!

first of: awesome you wrote this! I am currently trying to get this to work, but sadly it fails while scraping as it seems:

"Error during scrape: Get \"https://nextcloud.example/ocs/v2.php/apps/serverinfo/api/v1/info?format=json\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)"

The name resolution is working correctly and when I try to use curl it works:

curl -X GET -H "NC-Token: $NEXTCLOUD_API_KEY" "https://nextcloud.example/ocs/v2.php/apps/serverinfo/api/v1/info?format=json"
{"ocs":{"meta":{"status":"ok","statuscode":200,"message":"OK"},"data":{"nextcloud":{"system":{"version":"28.0.2.5","theme":"","enable_avatars":"yes","enable_previews":"yes","memcache.local":"\\OC\\Memcache\\APCu","memcache.distributed":"none","filelocking.enabled":"yes","memcache.locking":"\\OC\\Memcache\\Redis","debug":"no","freespace":6371377152,"cpuload":[0.18408203125,0.29150390625,0.26220703125],"mem_total":2097152,"mem_free":1306624,"swap_total":2097152,"swap_free":2096128},"storage":{"num_users":6,"num_files":165855,"num_storages":21,"num_storages_local":2,"num_storages_home":6,"num_storages_other":12},"shares":{"num_shares":3,"num_shares_user":0,"num_shares_groups":0,"num_shares_link":2,"num_shares_mail":0,"num_shares_room":0,"num_shares_link_no_password":0,"num_fed_shares_sent":1,"num_fed_shares_received":0,"permissions_3_31":2,"permissions_6_1":1}},"server":{"webserver":"Apache\/2.4.52 (Ubuntu)","php":{"version":"8.1.27","memory_limit":1073741824,"max_execution_time":3600,"upload_max_filesize":2097152,"opcache_revalidate_freq":60,"opcache":{"opcache_enabled":true,"cache_full":false,"restart_pending":false,"restart_in_progress":false,"memory_usage":{"used_memory":43261800,"free_memory":90947248,"wasted_memory":8680,"current_wasted_percentage":0.006467103958129883},"interned_strings_usage":{"buffer_size":8388608,"used_memory":7149696,"free_memory":1238912,"number_of_strings":82528},"opcache_statistics":{"num_cached_scripts":1989,"num_cached_keys":3827,"max_cached_keys":16229,"hits":3047421,"start_time":1708387201,"last_restart_time":0,"oom_restarts":0,"hash_restarts":0,"manual_restarts":0,"misses":2747,"blacklist_misses":0,"blacklist_miss_ratio":0,"opcache_hit_rate":99.90993938694524},"jit":{"enabled":false,"on":false,"kind":0,"opt_level":0,"opt_flags":0,"buffer_size":0,"buffer_free":0}},"apcu":{"cache":{"num_slots":4099,"ttl":0,"num_hits":182530,"num_misses":3806,"num_inserts":4083,"num_entries":650,"expunges":0,"start_time":1708387201,"mem_size":439568,"memory_type":"mmap"},"sma":{"num_seg":1,"seg_size":33554312,"avail_mem":33059400}},"extensions":["Core","date","libxml","openssl","pcre","zlib","filter","hash","json","Reflection","SPL","session","standard","sodium","apache2handler","mysqlnd","PDO","xml","apcu","bcmath","bz2","calendar","ctype","curl","dom","mbstring","FFI","fileinfo","ftp","gd","gettext","gmp","iconv","igbinary","imagick","intl","ldap","exif","mysqli","pdo_mysql","Phar","posix","readline","redis","shmop","SimpleXML","smbclient","sockets","sysvmsg","sysvsem","sysvshm","tokenizer","xmlreader","xmlwriter","xsl","zip","libsmbclient","Zend OPcache"]},"database":{"type":"mysql","version":"8.0.36","size":"207724544"}},"activeUsers":{"last5minutes":2,"last1hour":2,"last24hours":3}}}}

My config looks like this:

# required
server: "https://nextcloud.example"
# required for token authentication
authToken: "<< REDACTED >>"
# optional
listenAddress: ":9205"
timeout: "5s"
tlsSkipVerify: true

Is there any extended logging, where I can provide more information? Also it may be worth noting, that I compiled the go binary from source.

xperimental commented 7 months ago

I know that I am asking the obvious here, but: Is it taking the server longer than the configured timeout (5s) to respond? curl has a much higher default timeout than that.

If not, then details about the configuration would be great:

DNS should be a different error message as well as certificate errors, so it needs to be something different.

tim-krehan commented 7 months ago

Oh my - the timeout might be the reason. Sorry that I bothered with that question😂 Maybe it was because I stared for 5h at the same thing...

Anyways, I will test that later and be sure to respond to this thread!

Many thanks for the fast & detailed answer!

xperimental commented 7 months ago

No worries, it happens :slightly_smiling_face:

That said, if it really takes the server 5s to respond to the metrics request there is something wrong, but not something the exporter can fix.

tim-krehan commented 7 months ago

Hey :) so I checked it and it indeed was the timeout stopping me from accessing the stats.

And another thing: I was throttled from making any more calls, because of a security feature from the webserver - the initial calls where too often during my testing. I also added the exporter server as a exception and here we go: 5 seconds more then enough and I am not throttled anymore.

Thanks for your help!

xperimental commented 7 months ago

And another thing: I was throttled from making any more calls, because of a security feature from the webserver - the initial calls where too often during my testing. I also added the exporter server as a exception and here we go: 5 seconds more then enough and I am not throttled anymore.

Ah, that explains it quite well. Thanks for the follow-up! :+1:

Thanks for your help!

Happy to help. Have a nice day! :sunny:

fschn90 commented 1 month ago

I also added the exporter server as a exception and here we go: 5 seconds more then enough and I am not throttled anymore.

@tim-krehan : how did you do this?

im new to nextcloud and i use nginx as reverse proxy, to which i am also new. sorry if this is a rather general question and not immediately related to nextcloud-exporter.

i use NixOs and my nextcloud configuration is here. In which nextcloud-exporter is also configured. However i got the same time out error message:

for now i set the timout to 60s which seems to work.

but im not really happy with this approach and would like to set an exception for the exporter and would really appreciate a hint to the right direction on where and how to do that.

thank you!