ioBroker / ioBroker.js-controller

ioBroker controller
http://iobroker.net
MIT License
294 stars 58 forks source link

Collect Ressourceusage from adapters #1017

Open Apollon77 opened 4 years ago

Apollon77 commented 4 years ago

We discussed several times that it would be good to know which "ressources" are used by adapter instances. With resources I mean:

Beside the "user info cases" described above also the planned "HA adapter" would utilize these informations to decide if an instance can be moved or not.

We already have the "getPort" method which searches a free port. I would not adjust this method but leave it as is because "finding" a port and "using" is are two different topics.

My idea would be the following: We add a new "resources" key to the io-package common section where an adapter developer can describe the resources used by his adapter in general, e.g.:

...
resources: [
    {
        type: 'fs', // type of the resource: 'fs', 'network', 'serial', 'local' ...
        id: 'myfs', // optional own "Name" of that resource to later dynamically add details like paths or ports ids. if all known by config time can be ommitted
        active: true, // true if always used, false if configured at runtime
        localPath: '...' // local Path of the used resources (optional, I think most of the time only known by runtime)
    },
    {
        type: 'network', // type of the resource
        id: 'myport', // optional own "Name" of that resource to later dynamically add details like paths or ports ids. if all known by config time can be ommitted
        active: true, // true if always used, false if configured at runtime
        listenPort: '...' // Port it listens on, can be set if always the same or empty if dynamic at runtime
        dynamicPort: true // false if static, true if can be adjusted on availablility
    },
    {
        type: 'serial', // type of the resource
        id: 'myserial1', // optional own "Name" of that resource to later dynamically add details like paths or ports ids. if all known by config time can be ommitted
        active: true, // true if always used, false if configured at runtime
        port: '...' // Port, most likely not static
    },
    {
        type: 'local', // type of the resource:
        id: 'mygpio', // optional own "Name" of that resource to later dynamically add details like paths or ports ids. if all known by config time can be ommitted
        active: true, // true if always used, false if configured at runtime
        info: 'GPIO ports used' // Info on what other type of local resource used
    }
    ...
]
...

So all static stuff can be "hard" configured in io-package, for the details of it we have extra methods in adapter:

The infos collected here are provided as a new state in system.adapter.name.instance as a json of the array. So all adapters can access the infos. The data statically defined in io-package can be inserted here directly on installation time of the adapter and will be adjusted "On the fly". The content will not be cleared on adapter stop.

The js-controller process will also describe to all these states of "his" adapters and will provide a summary state in system.host.name of used network/serial ports of active adapters and which adapter uses it, e.g.

{
    'network': {
        8081: 'admin.0',
        1883: 'mqtt.1
    },
    'serial': {
        '/dev/ttyUSB0': 'smartmeter.0'
    }
}

This could be used by Admin UIs of adapters that allow resource definition to grey out stuff or such.

Also "getPort" method can be adjusted to check the list of defined port here to not use them.

What do you think about this idea?

Ingo

GermanBluefox commented 4 years ago

I wanted to monitor such info for a long time... TCP and UDP ports must be distinguished, not just "network"

Apollon77 commented 4 years ago

TCP and UDP ports must be distinguished, not just "network"

I would then propose still "network" but a key in the object like "portType: 'tcp'/'udp'" or such

AlCalzone commented 4 years ago

Would it make sense if this proposal would also double as a permission list? Then we could combine it with https://github.com/ioBroker/ioBroker.js-controller/issues/348 for example.

ioBroker could show the user which resources the adapter wants to access, so the user can decide whether he wants it or not. Or we could even store which permission a users wants to give by default, so he only needs to be asked again when a new adapter wants more.

Apollon77 commented 4 years ago

Hm ... in fact it is the "you configured it and so you want to use it " ... So I would see it as a implicit agreementlist already ... I do not see a point in allowing to decline the usage ?!

AlCalzone commented 4 years ago

Maybe I was unclear:

  1. We could show this information before installing, so the user can decide before he's going to install
  2. The user could configure that he wants to allow all adapters to access a certain path in the local filesystem, but that he wants to be asked before a new adapter needs internet access (see 1.). As long as no extra permissions are necessary, the user won't be asked.
Apollon77 commented 4 years ago

Puuhhh ... I think this is a complete different story, or?! And all Devs need to be very transparent for their adapters on what they use. It feels to me as an own issue