Giter Site home page Giter Site logo

Comments (6)

dmagliola avatar dmagliola commented on June 15, 2024

Hello,
Could you show us some sample code, or provide a bit more context of what you are doing?

from client_ruby.

devosalain avatar devosalain commented on June 15, 2024

My idea was to write a python client exporter for prometheus which spawns a webservice where prometheus can scrape the data of the gauges i write in this python program. Something like most existing exporters.
But for this i need to be able to specify the IP-address and port address.

Maybe another example to clarify. There exist a dovecot exporter for prometheus but you can specify the parameters.
"--web.listen-address="127.0.0.1:9166". So explicitly you can tell prometheus then to scrape on that IP-address and that specific port.
This is import in the case a port is already used by another instance which i think is in my case.

Or compare to python-code , because my knowledge of the ruby API is limited.
-> from prometheus_client import start_http_server
if name == 'main':
start_http_server(8000)
Works, but it is binding to all interfaces which is a serious security risk.

Maybe I need something like
prometheus = Prometheus::Client.registry(host:"127.0.0.1",port:"8000")

I looked at your code but was unable to find places where you pass IP-address or portnumber information which is essential for my use case.
Luckely the python api knows : "start_http_server(addr="127.0.0.1",port=38000)", but the ruby equivalent would be nice to have.

from client_ruby.

dmagliola avatar dmagliola commented on June 15, 2024

Our exporter middleware will allow you to filter by port, once we release the new version (which should be soon), so that's half the use case you are looking for. To also filter by IP you'd have to make your own exporter, you can start by copying the one in our master branch, and then adding the IP filtering.

That said, the error you describe seems to be that the same metric is being registered twice. This sounds like you are adding the Collector middleware twice?

from client_ruby.

devosalain avatar devosalain commented on June 15, 2024

Currently I have 80 tcp listeners running for different reasons, so probably that port was already occupied.
One final question. Could you guide me to which ruby file in this repo, or which function within it, where i can, after cloning this repo, hardcode an IP-address & Port. Probably this is the deepest function, where not all parameters are given or the defaults are taken.

from client_ruby.

dmagliola avatar dmagliola commented on June 15, 2024

You don't need to clone the repo. The way our middleware works, you can just copy the contents of it into a file in your app, and add that middleware to Rack, you don't need to modify the gem, just point to your copy of the middleware instead.

This is the file you are looking for:
https://github.com/prometheus/client_ruby/blob/master/lib/prometheus/middleware/exporter.rb

That said, I still think the error you are receiving is not a "two things tried to open the same port". That error is "the same metric got registered twice".

from client_ruby.

Sinjo avatar Sinjo commented on June 15, 2024

Closing this as it's stale, and I think wasn't for something our gem would handle in the first place.

Luckely the python api knows : "start_http_server(addr="127.0.0.1",port=38000)", but the ruby equivalent would be nice to have.

We don't start any HTTP servers directly in the gem, and by extension don't bind to any network interfaces.

from client_ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.