File: getdata24.c

package info (click to toggle)
rstatd 4.0.1-12
  • links: PTS
  • area: main
  • in suites: sid, trixie
  • size: 672 kB
  • sloc: ansic: 3,895; makefile: 733; sh: 697
file content (76 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
 * getdata24.c -- implementations of kernel 2.4 specific data retrieval functions
 *
 * software distributed under the GPL, for license terms see the file
 * COPYING in this directory
 *
 * (c) 2005 Dr. Andreas Mueller, Beratung und Entwicklung
 * $Id: getdata24.c,v 1.2 2005/09/19 07:20:33 afm Exp $
 */
#include "getdata24.h"
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>

/*
The 2.4 kernel keeps disk statistics information in /proc/partitions
in the following format:

major		device major number
minor		device minor number
#blocks		device size in blocks
name		device name (without /dev/ prefix)
rio		read io operations since boot
rmerge		read merges
rsect		sector reads
ruse		miliseconds the disk was in use
wio		write io operations since boot
wmerge		write merge operations since boot
wsect		sector writes since boot
wuse		time disk was in use for write operations
running		number of in flight operations
use		time in use (read and write)
aveq		average queue length (ms) = Integral of number of operations
		over time (in ms)

To compute the io statistics for a disk, use the rio and wio operations,
as they are closest to what we used to know as unix io operations. Use
the wsect and rsect numbers to report block reads/writes.

*/

void	get_disk24(struct statsusers *s) {
	FILE	*partitions;
	char	buffer[128];
	unsigned long long	rio;
	unsigned long long	wio;
	char	line[1024];
	char	device[128];
	int	diskno;

	/* open the /proc/partitions file */
	partitions = fopen("/proc/partitions", "r");
	if (NULL == partitions) {
		return;
	}

	/* skip two lines */
	fgets(buffer, sizeof(buffer), partitions);	/* 1. line */
	fgets(buffer, sizeof(buffer), partitions);	/* 2. line */

	/* accumulate all the io statistics */
	diskno = 0;
	while ((diskno < 4) && (line == fgets(line, sizeof(line), partitions))) {
		sscanf(line, " %*d %*d %*d %s "
			"%lld %*d %*d %*d "
			"%lld %*d %*d %*d "
			"%*d %*d %*d\n",
			device, &rio, &wio);
		if (isdisk(device)) {
			s->dk_xfer[diskno++] = rio + wio;
		}
	}

	/* close the file */
	fclose(partitions);
}