wociscz / lxd-telegraf-stats

LXD containers metrics
24 stars 14 forks source link

Feature Request: Pull stats from lxc remote hosts #5

Open 10101010101010001 opened 3 years ago

10101010101010001 commented 3 years ago

Thanks for your work, I appreciate your efforts. I'm still learning python or I'd implement this myself but could you add the ability to gather the statistics of remote hosts attached to lxd?

$ lxc remote add hostname ip  #add remote host with lxc
$ lxc list hostname:  #list containers on remote host
wociscz commented 3 years ago

Hmm that's doable maybe. But lot of metrics are gathered from sysfs cgroups - and these can't be scraped remotely (imo). Didn't looked much to new api in 4.x lxd, so maybe it can be done. Will try. Purpose of this is to have telegraf & this script installed on all lxd hosts and single influx/grafana targe anywhere. I have influx&grafana in one of my lxd containers.

But I'll try to do something with this - don't know when.

10101010101010001 commented 3 years ago

@wociscz I was able to test this script with a remote host by modifying your script:

Here's the added code: import urllib3 urllib3.disable_warnings()

if __name__ == '__main__': from pylxd import Client

client = Client(endpoint='https://url.domain:8443',cert=('/home/user/clients/host/client.crt','/home/user/clients/host/client.key'), verify=False)

Note: Some of my remote hosts are running Ubuntu 16.04/18.04/20.04, some are running on Centos 7/8.

Error: output.append(header + ",metric=status running=" + str(metric['running']) + ",processes=" + str(metric['processes']) + ",cpuprio=" + str(metric['cpuprio'])) KeyError: 'cpuprio'