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
|
#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "scrape.h"
#include "util.h"
// size of input buffer for paths and lines
#define BUF_SIZE 256
static void pressure_collect(scrape_req *req, void *ctx);
const struct collector pressure_collector = {
.name = "pressure",
.collect = pressure_collect,
};
static void pressure_collect(scrape_req *req, void *ctx) {
(void) ctx;
FILE *f;
long long ms;
if ((f = fopen("/proc/pressure/cpu", "r"))) {
if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1)
scrape_write(req, "node_cpu_waiting_seconds_total", 0, ms / 1e6);
fclose(f);
}
if ((f = fopen("/proc/pressure/memory", "r"))) {
if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1)
scrape_write(req, "memory_waiting_seconds_total", 0, ms / 1e6);
if (fscanf(f, "full %*[^t]total=%lld\n", &ms) == 1)
scrape_write(req, "memory_stalled_seconds_total", 0, ms / 1e6);
fclose(f);
}
if ((f = fopen("/proc/pressure/io", "r"))) {
if (fscanf(f, "some %*[^t]total=%lld\n", &ms) == 1)
scrape_write(req, "io_waiting_seconds_total", 0, ms / 1e6);
if (fscanf(f, "full %*[^t]total=%lld\n", &ms) == 1)
scrape_write(req, "io_stalled_seconds_total", 0, ms / 1e6);
fclose(f);
}
}
|