From c0f9d8d2ffeef895eb9849d8226dd2c20910b118 Mon Sep 17 00:00:00 2001 From: Unbit Date: Mon, 14 Oct 2013 19:19:05 +0200 Subject: [PATCH] prepare for file as metric source --- core/metrics.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++-- core/uwsgi.c | 1 + uwsgi.h | 9 ++++ 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/core/metrics.c b/core/metrics.c index f20ab2b7..7854a941 100644 --- a/core/metrics.c +++ b/core/metrics.c @@ -72,6 +72,41 @@ extern struct uwsgi_server uwsgi; */ +int64_t uwsgi_metric_get_from_file(char *filename, int split_pos) { + char buf[4096]; + int64_t ret = 0; + int fd = open(filename, O_RDONLY); + if (fd < 0) { + uwsgi_error_open(filename); + return 0; + } + + ssize_t rlen = read(fd, buf, 4096); + if (rlen <= 0) goto end; + + char *ptr = buf; + ssize_t i; + int pos = 0; + for(i=0;i