Sam pro custom metric

RubyB
Tera Contributor

I have a requirement to create a custom metric that returns the socket count by calculating cores divided by 64 and rounding up to the nearest greater integer for the servers. Any help

3 REPLIES 3

Nilesh Pol
Tera Guru

@RubyB 

Hope you have already create matric definition under licensing.

Configure field, matric type = Custom, Applies to= Server/device ie. cmdb_ci_server, Scripted matric = checked.

finally in the script field user below code:

(function(server) {
// Assume 'core_count' is the field on the CI record (e.g., cmdb_ci_server)
var cores = parseInt(server.core_count, 10);

if (isNaN(cores) || cores <= 0) {
return 0; // or 1 if you always want at least one socket
}

var sockets = Math.ceil(cores / 64);
return sockets;
})(current);

 

 

Test this by Attaching it to your software model or entitlement where it's used for license calculation. and Run the License Reconciliation job and verify socket counts on test servers.

 

if this response helds you then hit like and accept as solution.

 

Hi @Nilesh Pol,

please keep in mind, the CI core field is the value for a single cpu and needs to multiplied by the amount cpus to get the total count.

 

Best, Dennis

Should my response prove helpful, please consider marking it as the Accepted Solution/Helpful to assist closing this thread.

dreinhardt
Tera Sage

Hi @RubyB,

the out of the box example script for custom metrics looks like a good start for you.

 

		// set the rights on the machine total CPU count / 64
		deviceCpuCount= deviceRecord.getValue('cpu_count');
		deviceCoreCount = deviceRecord.getValue('cpu_core_count');
		totalCoreCount = deviceCpuCount * deviceCoreCount;
		rightsForDevice = Math.ceil(totalCoreCount / 64) ;
	}
	return rightsForDevice;

 

// Use this script to set the rights used by a device
// The function must return the number of rights.
// Note: A rightsForDevice of -1 means the device will be skipped and any installs will not 
//        be licensed.
// 
// The following variables are available:
// - entity:  sys_id of the device
// - encoded_query_for_installs:  query string for the unreconciled software installations
// 
// An example scenario and script:
// A device uses rights equal to the amount of RAM on the machine
// Software installed on the device will be licensed if enough rights are available.
getRightsForDevice();
function getRightsForDevice(){
var rightsForDevice = -1;
	var deviceRecord = new GlideRecord('cmdb_ci_computer');
	// query the computer record for the entity
	if(deviceRecord.get(entity)){
		// set the rights as the amount of ram on the machine
		rightsForDevice = deviceRecord.getValue('ram');
	}
	return rightsForDevice;
}

 

Should my response prove helpful, please consider marking it as the Accepted Solution/Helpful to assist closing this thread.