Skip to content

First pass of a way of handling multiple apcupsd hosts.#1

Open
cyberfox wants to merge 1 commit intoAndrolGenhald:masterfrom
cyberfox:add-multiple-hosts-support
Open

First pass of a way of handling multiple apcupsd hosts.#1
cyberfox wants to merge 1 commit intoAndrolGenhald:masterfrom
cyberfox:add-multiple-hosts-support

Conversation

@cyberfox
Copy link
Copy Markdown

@cyberfox cyberfox commented Apr 9, 2025

An example yaml file that would satisfy this would look like this:

address: 0.0.0.0:9175
hosts:
  - address: 10.0.1.64
    port: 3551
    slug: ml-server
  - address: 127.0.0.1
    port: 3551
    slug: greybox

Without a slug defined, it will default to adding apcupsd{#} to the front of the metrics lines, otherwise it adds the slug.

This version changes the behavior; I can make it so that if there isn't a 'hosts' section, it doesn't prefix anything at all. I may also make it so it accepts hostnames instead of ports, but this works for me really well.

This is (literally) the first Rust code I've ever written, and even read more than a few lines of. My apologies if I've messed something up. The compiler is really surprisingly helpful. :)

Caveat: Once I had it entirely working by hand (only way to learn), I put it into a language model to ask if it was idiomatic, and it suggested some changes. I made some of them manually, and decided not to for others because they fit the style of the existing code more. It did show me how to clean up my absolute mess of clones, as_refs, '&'s and such, which I appreciated. 😅

An example yaml file that would satisfy this would look like this:
```
address: 0.0.0.0:9175
hosts:
  - address: 10.0.1.64
    port: 3551
    slug: ml-server
  - address: 127.0.0.1
    port: 3551
    slug: greybox
```
@AndrolGenhald
Copy link
Copy Markdown
Owner

Thanks for the interest!
I'm trying to understand the motivation here a bit, it would make sense to me to add support for exporting multiple UPSes connected to a single host, but it looks like this is adding support for extracting data from apcupsd on multiple separate hosts to export from a central host? Is there a reason you can't just run another copy of the exporter on the 10.0.1.64 host? This feels like it might be an XY problem that could be better solved somewhere else.

@9p4
Copy link
Copy Markdown

9p4 commented Jun 9, 2025

I think that this approach is incorrect: there should be labels for the new hosts, not prefixes. Take a look at our fork: purdueLUG/prometheus_exporter_apcupsd@ea49422

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants