Projet

Général

Profil

Révision 81e9ffca

ID81e9ffca942112b092d5cc7d187222b4dfb088f5
Parent a70f7e48
Enfant 9ac74f8d

Ajouté par Steve Schnepp il y a plus de 10 ans

plugins: adding C version of multicpu1sec

Voir les différences:

plugins/system/multicpu1sec/multicpu1sec-c.c
1
/*
2
 * multicpu1sec C plugin
3
 */
4
#include <stdio.h>
5
#include <string.h>
6

  
7
#define PROC_STAT "/proc/stat"
8

  
9
int fail(char* msg) {
10
	perror(msg);
11

  
12
	return 1;
13
}
14

  
15
int config() {
16
	/* Get the number of CPU */
17
	FILE* f;
18
	if ( !(f=fopen(PROC_STAT, "r")) ) {
19
		return fail("cannot open " PROC_STAT);
20
	}
21

  
22
	// Starting with -1, since the first line is the "global cpu line"
23
	int ncpu = -1;
24
	while (! feof(f)) {
25
		char buffer[1024];
26
		if (fgets(buffer, 1024, f) == 0) {
27
			break;
28
		}
29

  
30
		if (! strncmp(buffer, "cpu", 3)) ncpu ++;
31
	}
32

  
33
	fclose(f);
34

  
35
	printf(
36
		"graph_title multicpu1sec\n"
37
		"graph_category system::1sec\n"
38
		"graph_vlabel average cpu use %\n"
39
		"graph_scale no\n"
40
		"graph_total All CPUs\n"
41
		"update_rate 1\n"
42
		"graph_data_size custom 1d, 10s for 1w, 1m for 1t, 5m for 1y\n"
43
	);
44

  
45
	int i;
46
	for (i = 0; i < ncpu; i++) {
47
		printf("cpu%d.label CPU %d\n", i, i);
48
		printf("cpu%d.draw %s\n", i, "AREASTACK");
49
		printf("cpu%d.min 0\n", i);
50
	}
51

  
52

  
53
}
54

  
55
int acquire() {
56
	printf("acquire()\n");
57
}
58

  
59
int fetch() {
60
	printf("fetch()\n");
61
}
62

  
63
int main(int argc, char **argv) {
64
	if (argc > 1) {
65
		char* first_arg = argv[1];
66
		if (! strcmp(first_arg, "config")) {
67
			return config();
68
		}
69

  
70
		if (! strcmp(first_arg, "acquire")) {
71
			return acquire();
72
		}
73
	}
74

  
75
	return fetch();
76
}

Formats disponibles : Unified diff