summaryrefslogtreecommitdiffstats
path: root/src/collectors/proc.plugin/proc_diskstats.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/collectors/proc.plugin/proc_diskstats.c (renamed from collectors/proc.plugin/proc_diskstats.c)41
1 files changed, 13 insertions, 28 deletions
diff --git a/collectors/proc.plugin/proc_diskstats.c b/src/collectors/proc.plugin/proc_diskstats.c
index 475d90835..4ff617ff9 100644
--- a/collectors/proc.plugin/proc_diskstats.c
+++ b/src/collectors/proc.plugin/proc_diskstats.c
@@ -213,7 +213,7 @@ static SIMPLE_PATTERN *excluded_disks = NULL;
static unsigned long long int bcache_read_number_with_units(const char *filename) {
char buffer[50 + 1];
- if(read_file(filename, buffer, 50) == 0) {
+ if(read_txt_file(filename, buffer, sizeof(buffer)) == 0) {
static int unknown_units_error = 10;
char *end = NULL;
@@ -547,9 +547,9 @@ static inline char *get_disk_model(char *device) {
char buffer[256 + 1];
snprintfz(path, sizeof(path) - 1, "%s/%s/device/model", path_to_sys_block, device);
- if(read_file(path, buffer, 256) != 0) {
+ if(read_txt_file(path, buffer, sizeof(buffer)) != 0) {
snprintfz(path, sizeof(path) - 1, "%s/%s/device/name", path_to_sys_block, device);
- if(read_file(path, buffer, 256) != 0)
+ if(read_txt_file(path, buffer, sizeof(buffer)) != 0)
return NULL;
}
@@ -565,7 +565,7 @@ static inline char *get_disk_serial(char *device) {
char buffer[256 + 1];
snprintfz(path, sizeof(path) - 1, "%s/%s/device/serial", path_to_sys_block, device);
- if(read_file(path, buffer, 256) != 0)
+ if(read_txt_file(path, buffer, sizeof(buffer)) != 0)
return NULL;
return strdupz(buffer);
@@ -778,7 +778,7 @@ static struct disk *get_disk(unsigned long major, unsigned long minor, char *dis
strncat(uuid_filename, "/dm/uuid", FILENAME_MAX - size);
char device_uuid[RRD_ID_LENGTH_MAX + 1];
- if (!read_file(uuid_filename, device_uuid, RRD_ID_LENGTH_MAX) && !strncmp(device_uuid, "LVM-", 4)) {
+ if (!read_txt_file(uuid_filename, device_uuid, sizeof(device_uuid)) && !strncmp(device_uuid, "LVM-", 4)) {
trim(device_uuid);
char chart_id[RRD_ID_LENGTH_MAX + 1];
@@ -1033,13 +1033,7 @@ static void add_labels_to_disk(struct disk *d, RRDSET *st) {
rrdlabels_add(st->rrdlabels, "device_type", get_disk_type_string(d->type), RRDLABEL_SRC_AUTO);
}
-static int diskstats_function_block_devices(BUFFER *wb, int timeout __maybe_unused, const char *function __maybe_unused,
- void *collector_data __maybe_unused,
- rrd_function_result_callback_t result_cb, void *result_cb_data,
- rrd_function_is_cancelled_cb_t is_cancelled_cb, void *is_cancelled_cb_data,
- rrd_function_register_canceller_cb_t register_canceller_cb __maybe_unused,
- void *register_canceller_cb_data __maybe_unused) {
-
+static int diskstats_function_block_devices(BUFFER *wb, const char *function __maybe_unused) {
buffer_flush(wb);
wb->content_type = CT_APPLICATION_JSON;
buffer_json_initialize(wb, "\"", "\"", 0, true, BUFFER_JSON_OPTIONS_DEFAULT);
@@ -1048,6 +1042,7 @@ static int diskstats_function_block_devices(BUFFER *wb, int timeout __maybe_unus
buffer_json_member_add_uint64(wb, "status", HTTP_RESP_OK);
buffer_json_member_add_string(wb, "type", "table");
buffer_json_member_add_time_t(wb, "update_every", 1);
+ buffer_json_member_add_boolean(wb, "has_history", false);
buffer_json_member_add_string(wb, "help", RRDFUNCTIONS_DISKSTATS_HELP);
buffer_json_member_add_array(wb, "data");
@@ -1318,16 +1313,7 @@ static int diskstats_function_block_devices(BUFFER *wb, int timeout __maybe_unus
buffer_json_member_add_time_t(wb, "expires", now_realtime_sec() + 1);
buffer_json_finalize(wb);
- int response = HTTP_RESP_OK;
- if(is_cancelled_cb && is_cancelled_cb(is_cancelled_cb_data)) {
- buffer_flush(wb);
- response = HTTP_RESP_CLIENT_CLOSED_REQUEST;
- }
-
- if(result_cb)
- result_cb(wb, response, result_cb_data);
-
- return response;
+ return HTTP_RESP_OK;
}
static void diskstats_cleanup_disks() {
@@ -1474,6 +1460,11 @@ int do_proc_diskstats(int update_every, usec_t dt) {
excluded_disks = simple_pattern_create(
config_get(CONFIG_SECTION_PLUGIN_PROC_DISKSTATS, "exclude disks", DEFAULT_EXCLUDED_DISKS), NULL,
SIMPLE_PATTERN_EXACT, true);
+
+ rrd_function_add_inline(localhost, NULL, "block-devices", 10,
+ RRDFUNCTIONS_PRIORITY_DEFAULT, RRDFUNCTIONS_DISKSTATS_HELP,
+ "top", HTTP_ACCESS_ANONYMOUS_DATA,
+ diskstats_function_block_devices);
}
// --------------------------------------------------------------------------
@@ -1488,12 +1479,6 @@ int do_proc_diskstats(int update_every, usec_t dt) {
ff = procfile_readall(ff);
if(unlikely(!ff)) return 0; // we return 0, so that we will retry to open it next time
- static bool add_func = true;
- if (add_func) {
- rrd_function_add(localhost, NULL, "block-devices", 10, RRDFUNCTIONS_DISKSTATS_HELP, true, diskstats_function_block_devices, NULL);
- add_func = false;
- }
-
size_t lines = procfile_lines(ff), l;
collected_number system_read_kb = 0, system_write_kb = 0;