boynux / squid-exporter

Squid Prometheus Exporter
https://www.boynux.com/squid-exporter
MIT License
134 stars 53 forks source link

Statistics is gathered from the main process instead of a child #66

Closed gummeah closed 9 months ago

gummeah commented 1 year ago

Describe the bug https://github.com/boynux/squid-exporter/commit/bb147c83cbe445d03c3fb86476fae631bc3be1d9

I think there's no much point to get such statistics (max/open files, memory/cpu) from main process, because all the work is done by child.

Moreover statistics about open files and some of mem/cpu stats could be taken from cache_object. For example, with squidclient: Add to config:

acl manager proto cache_object
http_access allow manager localhost
http_access deny manager

do:

squidclient  mgr:info
boynux commented 1 year ago

Hi gummeah, I'm not sure if I understood this issue correctly, but this exporter reads all those information from the same endpoint that squidclient mgr:info uses. It's just exporting that in Prometheus format. If you describe your use case we we can figure out if there is anything that we can do to support that.

gummeah commented 1 year ago

You only read counters and service_times from cache_object if I'm not mistaken: https://github.com/boynux/squid-exporter/blob/master/collector/client.go#L112 https://github.com/boynux/squid-exporter/blob/master/collector/client.go#L136

And you use standard prometheus collector for collecting, for example, process_open_fds, again if I'm not mistaken: https://github.com/boynux/squid-exporter/blob/master/main.go#L57 And you collecting it by the pid from the pidfile, which is the pid of the main squid process, but all the work is done by its child. You can run ss -nlpt or netstat -nlp and see that tcp socket is opened by child process, or run lsof -n and see that all connections are serviced by the child process, meaning you need to monitor free file descriptors on the child process, in case you run out of them because of a lot of connections for example. And if you change max_filedescriptors you also can see (by running cat /proc/<pid>/limits) that soft limit on open files is changed only on child process. And statistics for File descriptor usage for squid section on the cache_object info page is gathered from the child process also. Not sure how it was on older versions though, I'm checking on 4.10 version of squid.

boynux commented 1 year ago

Ok, right. Those Pid metrics are only read from the main process and not the child processes. I need to check to see if these metrics are available from the cache object and collect them from that instead.

But if that's something you are interested to investigate and make a PR I'll be happy to merge that.

I'm replying with some delay, because I'm not actively working this project and sometimes get overloaded with other work. thanks for your patience.

Tofolcr commented 10 months ago

Hi, I am facing the same use case described in this issue, I need to get metrics from the file descriptors. I have been investigating both the tool that the exporter uses to get metrics (squidclient), and the exporter itself. I found all the metrics will need in the /info path. I am implementing the necessary changes so that the exporter also attacks to that path and obtain all the metrics, when I have it ready I will make a pr so that you can review it and if it is correct merge it.

boynux commented 9 months ago

@Tofolcr thank you for taking time to file the PR, could you please take a look at my comments/suggestion

Tofolcr commented 9 months ago

@boynux, thank you very much for all the comments and suggestions. I'll begin implementing all the changes as soon as possible.

Tofolcr commented 9 months ago

I have finished working with the suggestions.