NetXMS Support Forum

Please login or register.

Login with username, password and session length

Author Topic: Total disk space in use of all servers  (Read 277 times)

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Total disk space in use of all servers
« on: June 04, 2019, 05:39:30 am »

We are planning a move to cloud based servers and I need to gather information about how much disk space is used in total on all disks on all of my servers.

I have been able to add a DCI as a template that uses FileSystem.Used({instance}) as the parameter and queries the FileSystem.MountPoints Agent list to add a DCI to every server that enumerates the filesystems and produces the used space in bytes.

My ultimate goal is to run this as a DCI summary table on all servers at once, but I have two issues:
  • The DCI I built and applied only works on Windows servers, it doesn't show up for the Linux servers, although the Linux servers do show the system-generated DCIs of "File system: used space on /", etc.
  • The DCI Summary table won't take {instance} as you can with the DCI.
Even if it's just something like this, I can work with that and just total everything up in Excel, but it would be nice if I could do this all at once.

Server 1 drive c: xxx bytes
Server 1 drive d: xxx bytes
Server 2 drive / xxx bytes
Server 2 drive /etc xxx bytes

What is the best way to accomplish what I need?

Thanks for a great product!
Logged

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6589
    • View Profile
Re: Total disk space in use of all servers
« Reply #1 on: June 06, 2019, 10:04:29 am »

Hi!

If you need just one number for total disk space then best approach would be script DCI that will enumerate all servers and add up used disk space. Possible script implementation is following:

Code: [Select]
// Find "Entire Network" object and start enumeration from it
global TOTAL = 0;
EnumerateNodes(FindObject(1));
return TOTAL;
 
// This function walks object tree recursively starting from given root
sub EnumerateNodes(rootObject)
{
// Walk all child objects
foreach(o : GetObjectChildren(rootObject))
{
if (classof(o) == "Node")
{
// Process node object
            for(d : FindAllDCIs(o, "FileSystem.Used(*)"))
            {
                v = GetDCIValue(o, d->id);
                if (v != null)
                {
                    TOTAL += v;
                }
            }
}
else
{
// For all other objects, go down the tree
EnumerateNodes(o);
}
}
}

You should select right top level object for enumeration. Also this script does not check if same node encountered multiple times - so you either have to pass such rot object under which each node bound exactly once, ar add additional check to avoid duplicates.

Best regards,
Victor
Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #2 on: June 06, 2019, 06:02:27 pm »

Thanks Victor!

Where would I put this?  Does this go in the script library?

Also, every time I use FileSystem.Used(*) it never works to enumerate all the instances.  I thought it had to be FileSystem.Used({instance})?
Logged

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6589
    • View Profile
Re: Total disk space in use of all servers
« Reply #3 on: June 08, 2019, 12:39:59 pm »

Yes, you create script in library and then create script DCI specifying this script as parameter name. For testing you can select any container, right click and select "execute server script". You can also add print or trace calls to provide diagnostic. You have to use * as wildcard in FindAllDCIs call.

Best regards,
Victor
Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #4 on: June 10, 2019, 09:35:08 pm »

Thanks Victor.

When I try to run it against a node, I get this:

Error 14 in line 10: Function or operation argument is not an object

The server in question has the DCI FileSystem.Used on it and shows all the drives.

Also, how do I create a script DCI?  Where do I create that?

Thanks
Logged

Tursiops

  • Sr. Member
  • ****
  • Posts: 403
    • View Profile
Re: Total disk space in use of all servers
« Reply #5 on: June 11, 2019, 12:17:34 am »

Script works fine on my system. Did you copy&paste or type it?
The reason the script uses FileSystem.Used(*) is because the * in the script is a wildcard, so it catches all such DCIs. It is not the same as an actual DCI on a node.

To create a script DCI, create a new DCI and select Script under Origin. As Parameter you use the name of the script in your Script Library (see attached example for a script called "DCI::GetIPAddresses", obviously yours will be called something else).
Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #6 on: June 11, 2019, 01:03:06 am »

Thanks!

What node do I create the DCI on?  Am I just missing something?

I did just copy & paste it into a new script.
« Last Edit: June 11, 2019, 01:13:28 am by blairmc96 »
Logged

Tursiops

  • Sr. Member
  • ****
  • Posts: 403
    • View Profile
Re: Total disk space in use of all servers
« Reply #7 on: June 11, 2019, 06:47:48 am »

As you are using a script DCI that goes through every single node in your installation, you can put that DCI on any node, really.
You could create a dummy node, e.g. "AWS" and create the DCI on there.

Based on your error, it doesn't like something (the rootObject?) in line
Code: [Select]
foreach(o : GetObjectChildren(rootObject))
As per the script, initially that'd get the object children of object 1 (which is "Entire Network") and then move down the tree.
I wouldn't think this could break unless there is a typo in the script (direct copy&paste without a single change worked without any issues for me on two different installs) or some kind of database corruption. But Victor might have an idea.

Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #8 on: June 11, 2019, 04:19:22 pm »

Thanks, I just tried copying & pasting again but got the same error, see attached.  One of the machines I'm testing on has the FileSystem.Used({instance}) enumerated on it just fine and last values reports the data correctly.

I'm not sure what I'm doing wrong.
« Last Edit: June 11, 2019, 04:21:22 pm by blairmc96 »
Logged

Tursiops

  • Sr. Member
  • ****
  • Posts: 403
    • View Profile
Re: Total disk space in use of all servers
« Reply #9 on: June 12, 2019, 01:58:14 am »

When you click on "Entire Network", what's the ID of the Object?
It should (and the script expects it to) be "1" but if for some odd reason it isn't, that'd be a problem.
Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #10 on: June 12, 2019, 06:03:03 am »

I can confirm it is indeed 1.
Logged

Victor Kirhenshtein

  • Lead Developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 6589
    • View Profile
Re: Total disk space in use of all servers
« Reply #11 on: June 12, 2019, 10:55:00 am »

Check server configuration variable CheckTrustedNodes - it should be set to 0 (false).

Best regards,
Victor
Logged

blairmc96

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Total disk space in use of all servers
« Reply #12 on: June 12, 2019, 08:41:15 pm »

It was set to 1.  I have no idea how it got set that way.

I set it to 0 and restarted, and it produced results!

Is there somewhere in the documentation about scripting that I missed?

Thank you for your help!


*** FINISHED ***

Result: 27706007919104
Logged