VMware {code} Community
Sandeep_Patil
Enthusiast
Enthusiast

How to fetch the data metric called swapped (Amount in kB of memory that is swapped) ?

How to fetch the data metric swapped, swaptarget, swapin, swapout using VC 2.x(vim) and VC 1.x (vma)API ?

Is there any direct method provided to get these values in VC2.x and VC 1.x API ?

Thanks,

Sandeep

Reply
0 Kudos
2 Replies
admin
Immortal
Immortal

These Metrics are basically counters of group memory and can be fetched using the QueryPerf method, where query spec is passed. The metricId property of this spec should hold the performance metric id's be retrieved.

While creating the queryperfspec, Iterating through Performance Manager -> perfCounter array,

we can look for counters with nameInfo->key matching "swapped", "swaptarget", "swapin", "swapout"

When creating QueryPerfSpec, pass the performance metric id's retrieved above.

e.g. The example shown below used memory ->"swapused" property.

sub get_perf_metric_ids {

my %args = @_;

my $perfmgr_view = $args{perfmgr_view};

my $entity = $args;

my $type = $args;

my $perfCounterInfo = $perfmgr_view->perfCounter;

my $availmetricid = $perfmgr_view->QueryAvailablePerfMetric(entity => $entity);

foreach (@$perfCounterInfo) {

if($_->nameInfo->key eq "swapused")

{

my $key = $_->key;

$all_counters->{ $key } = $_;

my $group_info = $_->groupInfo;

if ($group_info->key eq "mem") {

$counters->{ $key } = $_;

}

}

}

foreach (@$availmetricid) {

if (exists $counters->{$_->counterId}) {

#push @filtered_list, $_;

my $metric = PerfMetricId->new (counterId => $_->counterId,

instance => (Opts::get_option('instance') || ''));

push @filtered_list, $metric;

}

}

return \@filtered_list;

}

$perf_query_spec = PerfQuerySpec->new(entity => $host,

metricId => @perf_metric_ids,

'format' => 'csv',

intervalId => Opts::get_option('interval'),

maxSample => Opts::get_option('samples'));

$perf_data = $perfmgr_view->QueryPerf( querySpec => $perf_query_spec);

foreach (@$perf_data) {

print_log("Performance data for: " . $host->name . "\n");

my $time_stamps = $_->sampleInfoCSV;

my $values = $_->value;

foreach (@$values) {

print_counter_info($_->id->counterId, $_->id->instance);

print_log("Sample info : " . $time_stamps);

print_log("Value: " . $_->value . "\n");

}

}

You can also refer viperformance.pl shipped with the vi perl toolkit. Another article of interest to you, could be the following link:

It lists the statistic collection level at which historical records for the metrics are kept.

Reply
0 Kudos
Sandeep_Patil
Enthusiast
Enthusiast

Hi dkaur,

Can you help me with the java code for the same ?

Thanks,

Sandeep

Reply
0 Kudos