summaryrefslogtreecommitdiff
path: root/src/collectl2pcp/disk.c
blob: 6ea8940eae6554c7698f0fa518d49a633aca7378 (plain)
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
/*
 * Copyright (c) 2013 Red Hat Inc.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * Handler for disk.dev
 *
 * disk    8       0 sda 13911739 267073 1248592592 58081804 4912190 5603474 382020376 181762699 0 53315955 240138732
 */

#include "metrics.h"

int
disk_handler(handler_t *h, fields_t *f)
{
    char *inst;
    pmInDom indom = pmInDom_build(LINUX_DOMAIN, DISK_INDOM);

    if (f->nfields != 15)
    	return -1;

    /* disk.dev.* */
    inst = f->fields[3]; /* diskname */

    put_str_value("disk.dev.read", indom, inst, f->fields[4]);
    put_str_value("disk.dev.read_merge", indom, inst, f->fields[5]);
    put_str_value("disk.dev.blkread", indom, inst, f->fields[6]);
    /* skip read_ticks at f->fields[7] */
    put_str_value("disk.dev.write", indom, inst, f->fields[8]);
    put_str_value("disk.dev.write_merge", indom, inst, f->fields[9]);
    put_str_value("disk.dev.blkwrite", indom, inst, f->fields[10]);
    /* skip write_ticks at f->fields[11] */
    /* skip in_flight at f->fields[12] */
    put_str_value("disk.dev.avactive", indom, inst, f->fields[13]);
    put_str_value("disk.dev.aveq", indom, inst, f->fields[14]);

    /* derived values */
    put_ull_value("disk.dev.write_bytes", indom, inst, strtoull(f->fields[10], NULL, 0) / 2);
    put_ull_value("disk.dev.read_bytes", indom, inst, strtoull(f->fields[6], NULL, 0) / 2);
    put_ull_value("disk.dev.total_bytes", indom, inst,
    	strtoull(f->fields[6], NULL, 0) + strtoull(f->fields[10], NULL, 0));

    return 0;
}