Example #1
0
static void top(void)
{
	xenstat_domain **domains;
	unsigned int i, num_domains = 0;

	/* Now get the node information */
	if (prev_node != NULL)
		xenstat_free_node(prev_node);
	prev_node = cur_node;
	cur_node = xenstat_get_node(xhandle, XENSTAT_ALL);
	if (cur_node == NULL)
		fail("Failed to retrieve statistics from libxenstat\n");

	/* dump summary top information */
	if (!batch)
		do_summary();

	/* Count the number of domains for which to report data */
	num_domains = xenstat_node_num_domains(cur_node);

	domains = calloc(num_domains, sizeof(xenstat_domain *));
	if(domains == NULL)
		fail("Failed to allocate memory\n");

	for (i=0; i < num_domains; i++)
		domains[i] = xenstat_node_domain_by_index(cur_node, i);

	/* Sort */
	qsort(domains, num_domains, sizeof(xenstat_domain *),
	      (int(*)(const void *, const void *))compare_domains);

	if(first_domain_index >= num_domains)
		first_domain_index = num_domains-1;

	for (i = first_domain_index; i < num_domains; i++) {
		if(!batch && current_row() == lines()-1)
			break;
		if (i == first_domain_index || repeat_header)
			do_header();
		do_domain(domains[i]);
		if (show_vcpus)
			do_vcpu(domains[i]);
		if (show_networks)
			do_network(domains[i]);
		if (show_vbds)
			do_vbd(domains[i]);
		if (show_tmem)
			do_tmem(domains[i]);
	}

	if (!batch)
		do_bottom_line();

	free(domains);
}
Example #2
0
/* Prints the top summary, above the domain table */
void do_summary(void)
{
#define TIME_STR_LEN 9
	const char *TIME_STR_FORMAT = "%H:%M:%S";
	char time_str[TIME_STR_LEN];
	const char *ver_str;
	unsigned run = 0, block = 0, pause = 0,
	         crash = 0, dying = 0, shutdown = 0;
	unsigned i, num_domains = 0;
	unsigned long long used = 0;
	long freeable_mb = 0;
	xenstat_domain *domain;
	time_t curt;

	/* Print program name, current time, and number of domains */
	curt = curtime.tv_sec;
	strftime(time_str, TIME_STR_LEN, TIME_STR_FORMAT, localtime(&curt));
	num_domains = xenstat_node_num_domains(cur_node);
	ver_str = xenstat_node_xen_version(cur_node);
	print("xentop - %s   Xen %s\n", time_str, ver_str);

	/* Tabulate what states domains are in for summary */
	for (i=0; i < num_domains; i++) {
		domain = xenstat_node_domain_by_index(cur_node,i);
		if (xenstat_domain_running(domain)) run++;
		else if (xenstat_domain_blocked(domain)) block++;
		else if (xenstat_domain_paused(domain)) pause++;
		else if (xenstat_domain_shutdown(domain)) shutdown++;
		else if (xenstat_domain_crashed(domain)) crash++;
		else if (xenstat_domain_dying(domain)) dying++;
	}

	print("%u domains: %u running, %u blocked, %u paused, "
	      "%u crashed, %u dying, %u shutdown \n",
	      num_domains, run, block, pause, crash, dying, shutdown);

	used = xenstat_node_tot_mem(cur_node)-xenstat_node_free_mem(cur_node);
	freeable_mb = xenstat_node_freeable_mb(cur_node);

	/* Dump node memory and cpu information */
	if ( freeable_mb <= 0 )
	     print("Mem: %lluk total, %lluk used, %lluk free    ",
	      xenstat_node_tot_mem(cur_node)/1024, used/1024,
	      xenstat_node_free_mem(cur_node)/1024);
	else
	     print("Mem: %lluk total, %lluk used, %lluk free, %ldk freeable, ",
	      xenstat_node_tot_mem(cur_node)/1024, used/1024,
	      xenstat_node_free_mem(cur_node)/1024, freeable_mb*1024);
	print("CPUs: %u @ %lluMHz\n",
	      xenstat_node_num_cpus(cur_node),
	      xenstat_node_cpu_hz(cur_node)/1000000);
}
Example #3
0
int main(void) {
	xenstat_handle *handle = xenstat_init();
	if(!handle) {
		fputs("Internal error in xenstats, failed to initialize handle\n", stderr);
		exit(1);
	}

	xenstat_node *node = xenstat_get_node(handle, XENSTAT_ALL); 
	if(!node) {
		fputs("Failed to get statistics from libxenlight\n", stderr);
		exit(2);
	}

	printf("<<<xen_info>>>\n"); 
	printf("version\t%s\n", xenstat_node_xen_version(node));
	printf("total_memory\t%llu\n", xenstat_node_tot_mem(node));
	printf("free_memory\t%llu\n", xenstat_node_free_mem(node));
//	printf("freeable_memory\t%li\n", xenstat_node_freeable_mb(node));
	printf("cpu_amount\t%i\n", xenstat_node_num_cpus(node));
	printf("cpu_speed\t%llu\n", xenstat_node_cpu_hz(node));

	int domains_amount = xenstat_node_num_domains(node);
	if(!domains_amount) exit(0);
	printf("domains\t%i\n", domains_amount);

	xenstat_domain** domains = malloc(sizeof(xenstat_domain*) * domains_amount);
	

	for(int i=0; i<domains_amount; i++) {
		xenstat_domain* domain = xenstat_node_domain_by_index(node, i);
		if(xenstat_domain_id(domain)) {
			printf("<<<<%s>>>>\n", xenstat_domain_name(domain));
		} else{ printf("<<<<>>>>\n"); }
		printf("<<<xen_domain>>>\n");
		printf("id\t%u\n", xenstat_domain_id(domain));
	}

	return 0;
}