From: Florian Forster Date: Mon, 14 Jun 2010 10:47:25 +0000 (+0200) Subject: action graph: Remove unused functions. X-Git-Tag: v4.0.0~284 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=b2db68ebb7acdb345c07985fcdb35dcfbb36d4aa;p=collection4.git action graph: Remove unused functions. The get_random_color() function has been moved to common.[ch]. --- diff --git a/action_graph.c b/action_graph.c index 585a49a..b5b3163 100644 --- a/action_graph.c +++ b/action_graph.c @@ -42,198 +42,6 @@ struct graph_def_s }; typedef struct graph_def_s graph_def_t; -static void graph_def_free (graph_def_t *gd) /* {{{ */ -{ - size_t i; - - if (gd == NULL) - return; - - for (i = 0; i < gd->data_sources_num; i++) - { - free (gd->data_sources[i].file); - free (gd->data_sources[i].name); - free (gd->data_sources[i].legend); - } - free (gd->data_sources); - free (gd); -} /* }}} void graph_def_free */ - -static int hsv_to_rgb (double *hsv, double *rgb) /* {{{ */ -{ - double c = hsv[2] * hsv[1]; - double h = hsv[0] / 60.0; - double x = c * (1.0 - fabs (fmod (h, 2.0) - 1)); - double m = hsv[2] - c; - - rgb[0] = 0.0; - rgb[1] = 0.0; - rgb[2] = 0.0; - - if ((0.0 <= h) && (h < 1.0)) { rgb[0] = 1.0; rgb[1] = x; rgb[2] = 0.0; } - else if ((1.0 <= h) && (h < 2.0)) { rgb[0] = x; rgb[1] = 1.0; rgb[2] = 0.0; } - else if ((2.0 <= h) && (h < 3.0)) { rgb[0] = 0.0; rgb[1] = 1.0; rgb[2] = x; } - else if ((3.0 <= h) && (h < 4.0)) { rgb[0] = 0.0; rgb[1] = x; rgb[2] = 1.0; } - else if ((4.0 <= h) && (h < 5.0)) { rgb[0] = x; rgb[1] = 0.0; rgb[2] = 1.0; } - else if ((5.0 <= h) && (h < 6.0)) { rgb[0] = 1.0; rgb[1] = 0.0; rgb[2] = x; } - - rgb[0] += m; - rgb[1] += m; - rgb[2] += m; - - return (0); -} /* }}} int hsv_to_rgb */ - -static uint32_t rgb_to_uint32 (double *rgb) /* {{{ */ -{ - uint8_t r; - uint8_t g; - uint8_t b; - - r = (uint8_t) (255.0 * rgb[0]); - g = (uint8_t) (255.0 * rgb[1]); - b = (uint8_t) (255.0 * rgb[2]); - - return ((((uint32_t) r) << 16) - | (((uint32_t) g) << 8) - | ((uint32_t) b)); -} /* }}} uint32_t rgb_to_uint32 */ - -static uint32_t get_random_color (void) /* {{{ */ -{ - double hsv[3] = { 0.0, 1.0, 1.0 }; - double rgb[3] = { 0.0, 0.0, 0.0 }; - - hsv[0] = 360.0 * ((double) rand ()) / (((double) RAND_MAX) + 1.0); - - hsv_to_rgb (hsv, rgb); - - return (rgb_to_uint32 (rgb)); -} /* }}} uint32_t get_random_color */ - -static int graph_def_add_ds (graph_def_t *gd, /* {{{ */ - const char *file, const char *ds_name) -{ - data_source_t *ds; - - ds = realloc (gd->data_sources, sizeof (*ds) * (gd->data_sources_num + 1)); - if (ds == NULL) - return (ENOMEM); - gd->data_sources = ds; - - ds = gd->data_sources + gd->data_sources_num; - memset (ds, 0, sizeof (*ds)); - - ds->file = strdup (file); - if (ds->file == NULL) - return (ENOMEM); - - ds->name = strdup (ds_name); - if (ds->name == NULL) - { - free (ds->file); - return (ENOMEM); - } - - ds->legend = NULL; - ds->color = get_random_color (); - - gd->data_sources_num++; - - return (0); -} /* }}} int graph_def_add_ds */ - -static graph_def_t *graph_def_from_rrd_file (char *file) /* {{{ */ -{ - graph_def_t *gd; - char **dses = NULL; - size_t dses_num = 0; - int status; - size_t i; - - gd = malloc (sizeof (*gd)); - if (gd == NULL) - return (NULL); - memset (gd, 0, sizeof (*gd)); - gd->data_sources = NULL; - - status = ds_list_from_rrd_file (file, &dses_num, &dses); - if (status != 0) - { - free (gd); - return (NULL); - } - - for (i = 0; i < dses_num; i++) - { - graph_def_add_ds (gd, file, dses[i]); - free (dses[i]); - } - - free (dses); - - return (gd); -} /* }}} graph_def_t *graph_def_from_rrd_file */ - -static graph_def_t *graph_def_from_gl (const graph_list_t *gl) /* {{{ */ -{ - char rrd_file[PATH_MAX]; - - if ((gl->plugin_instance == NULL) && (gl->type_instance == NULL)) - snprintf (rrd_file, sizeof (rrd_file), "%s/%s/%s/%s.rrd", - DATA_DIR, gl->host, gl->plugin, gl->type); - else if (gl->type_instance == NULL) - snprintf (rrd_file, sizeof (rrd_file), "%s/%s/%s-%s/%s.rrd", - DATA_DIR, gl->host, gl->plugin, gl->plugin_instance, gl->type); - else if (gl->plugin_instance == NULL) - snprintf (rrd_file, sizeof (rrd_file), "%s/%s/%s/%s-%s.rrd", - DATA_DIR, gl->host, gl->plugin, gl->type, gl->type_instance); - else - snprintf (rrd_file, sizeof (rrd_file), "%s/%s/%s-%s/%s-%s.rrd", - DATA_DIR, gl->host, gl->plugin, gl->plugin_instance, - gl->type, gl->type_instance); - rrd_file[sizeof (rrd_file) - 1] = 0; - - return (graph_def_from_rrd_file (rrd_file)); -} /* }}} graph_def_t *graph_def_from_gl */ - -static int draw_graph_ds (graph_def_t *gd, /* {{{ */ - size_t index, str_array_t *args) -{ - data_source_t *ds; - - assert (index < gd->data_sources_num); - - ds = gd->data_sources + index; - - /* CDEFs */ - array_append_format (args, "DEF:def_%04zu_min=%s:%s:MIN", - index, ds->file, ds->name); - array_append_format (args, "DEF:def_%04zu_avg=%s:%s:AVERAGE", - index, ds->file, ds->name); - array_append_format (args, "DEF:def_%04zu_max=%s:%s:MAX", - index, ds->file, ds->name); - /* VDEFs */ - array_append_format (args, "VDEF:vdef_%04zu_min=def_%04zu_min,MINIMUM", - index, index); - array_append_format (args, "VDEF:vdef_%04zu_avg=def_%04zu_avg,AVERAGE", - index, index); - array_append_format (args, "VDEF:vdef_%04zu_max=def_%04zu_max,MAXIMUM", - index, index); - array_append_format (args, "VDEF:vdef_%04zu_lst=def_%04zu_avg,LAST", - index, index); - - /* Graph part */ - array_append_format (args, "LINE1:def_%04zu_avg#%06x:%s", index, ds->color, - (ds->legend != NULL) ? ds->legend : ds->name); - array_append_format (args, "GPRINT:vdef_%04zu_min:%%lg min,", index); - array_append_format (args, "GPRINT:vdef_%04zu_avg:%%lg avg,", index); - array_append_format (args, "GPRINT:vdef_%04zu_max:%%lg max,", index); - array_append_format (args, "GPRINT:vdef_%04zu_lst:%%lg last\\l", index); - - return (0); -} /* }}} int draw_graph_ds */ - static void emulate_graph (int argc, char **argv) /* {{{ */ { int i; @@ -294,39 +102,6 @@ static int output_graph (rrd_info_t *info) /* {{{ */ return (0); \ } while (0) -static int init_gl (graph_list_t *gl) /* {{{ */ -{ - gl->host = param ("host"); - gl->plugin = param ("plugin"); - gl->plugin_instance = param ("plugin_instance"); - gl->type = param ("type"); - gl->type_instance = param ("type_instance"); - - if ((gl->host == NULL) - || (gl->plugin == NULL) - || (gl->type == NULL)) - return (EINVAL); - - if ((gl->host[0] == 0) || (gl->host[0] == '.') - || (gl->plugin[0] == 0) || (gl->plugin[0] == '.') - || (gl->type[0] == 0) || (gl->type[0] == '.')) - return (EINVAL); - - if ((strchr (gl->plugin, '-') != NULL) - || (strchr (gl->type, '-') != NULL)) - return (EINVAL); - - if ((gl->plugin_instance != NULL) - && (gl->plugin_instance[0] == 0)) - gl->plugin_instance = NULL; - - if ((gl->type_instance != NULL) - && (gl->type_instance[0] == 0)) - gl->type_instance = NULL; - - return (0); -} /* }}} int init_gl */ - int action_graph (void) /* {{{ */ { str_array_t *args; diff --git a/common.c b/common.c index 5d2a67d..dab0b70 100644 --- a/common.c +++ b/common.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -7,6 +9,7 @@ #include #include #include +#include #include @@ -245,4 +248,56 @@ int ds_list_from_rrd_file (char *file, /* {{{ */ return (0); } /* }}} int ds_list_from_rrd_file */ +static int hsv_to_rgb (double *hsv, double *rgb) /* {{{ */ +{ + double c = hsv[2] * hsv[1]; + double h = hsv[0] / 60.0; + double x = c * (1.0 - fabs (fmod (h, 2.0) - 1)); + double m = hsv[2] - c; + + rgb[0] = 0.0; + rgb[1] = 0.0; + rgb[2] = 0.0; + + if ((0.0 <= h) && (h < 1.0)) { rgb[0] = 1.0; rgb[1] = x; rgb[2] = 0.0; } + else if ((1.0 <= h) && (h < 2.0)) { rgb[0] = x; rgb[1] = 1.0; rgb[2] = 0.0; } + else if ((2.0 <= h) && (h < 3.0)) { rgb[0] = 0.0; rgb[1] = 1.0; rgb[2] = x; } + else if ((3.0 <= h) && (h < 4.0)) { rgb[0] = 0.0; rgb[1] = x; rgb[2] = 1.0; } + else if ((4.0 <= h) && (h < 5.0)) { rgb[0] = x; rgb[1] = 0.0; rgb[2] = 1.0; } + else if ((5.0 <= h) && (h < 6.0)) { rgb[0] = 1.0; rgb[1] = 0.0; rgb[2] = x; } + + rgb[0] += m; + rgb[1] += m; + rgb[2] += m; + + return (0); +} /* }}} int hsv_to_rgb */ + +static uint32_t rgb_to_uint32 (double *rgb) /* {{{ */ +{ + uint8_t r; + uint8_t g; + uint8_t b; + + r = (uint8_t) (255.0 * rgb[0]); + g = (uint8_t) (255.0 * rgb[1]); + b = (uint8_t) (255.0 * rgb[2]); + + return ((((uint32_t) r) << 16) + | (((uint32_t) g) << 8) + | ((uint32_t) b)); +} /* }}} uint32_t rgb_to_uint32 */ + +uint32_t get_random_color (void) /* {{{ */ +{ + double hsv[3] = { 0.0, 1.0, 1.0 }; + double rgb[3] = { 0.0, 0.0, 0.0 }; + + hsv[0] = 360.0 * ((double) rand ()) / (((double) RAND_MAX) + 1.0); + + hsv_to_rgb (hsv, rgb); + + return (rgb_to_uint32 (rgb)); +} /* }}} uint32_t get_random_color */ + /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/common.h b/common.h index 8aa1a53..d61b0a2 100644 --- a/common.h +++ b/common.h @@ -1,6 +1,9 @@ #ifndef COMMON_H #define COMMON_H 1 +#include +#include + #define DATA_DIR "/var/lib/collectd/rrd" #include "graph_list.h" @@ -20,5 +23,7 @@ size_t c_strlcat (char *dst, const char *src, size_t size); int ds_list_from_rrd_file (char *file, size_t *ret_dses_num, char ***ret_dses); +uint32_t get_random_color (void); + #endif /* COMMON_H */ /* vim: set sw=2 sts=2 et fdm=marker : */ diff --git a/graph_list.c b/graph_list.c index a07ed5c..3b634f5 100644 --- a/graph_list.c +++ b/graph_list.c @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include @@ -791,13 +793,36 @@ int gl_ident_get_rrdargs (graph_config_t *cfg, /* {{{ */ for (i = 0; i < dses_num; i++) { - int id; + int index; GL_DEBUG ("gl_ident_get_rrdargs: ds[%lu] = %s;\n", (unsigned long) i, dses[i]); - id = array_argc (args); - array_append_format (args, "DEF:avg%i=%s:%s:AVERAGE", id, file, dses[i]); - array_append_format (args, "LINE1:avg%i#ff0000:%s\\l", id, file); + index = array_argc (args); + + /* CDEFs */ + array_append_format (args, "DEF:def_%04i_min=%s:%s:MIN", + index, file, dses[i]); + array_append_format (args, "DEF:def_%04i_avg=%s:%s:AVERAGE", + index, file, dses[i]); + array_append_format (args, "DEF:def_%04i_max=%s:%s:MAX", + index, file, dses[i]); + /* VDEFs */ + array_append_format (args, "VDEF:vdef_%04i_min=def_%04i_min,MINIMUM", + index, index); + array_append_format (args, "VDEF:vdef_%04i_avg=def_%04i_avg,AVERAGE", + index, index); + array_append_format (args, "VDEF:vdef_%04i_max=def_%04i_max,MAXIMUM", + index, index); + array_append_format (args, "VDEF:vdef_%04i_lst=def_%04i_avg,LAST", + index, index); + + /* Graph part */ + array_append_format (args, "LINE1:def_%04i_avg#%06"PRIx32":%s", + index, get_random_color (), dses[i]); + array_append_format (args, "GPRINT:vdef_%04i_min:%%lg min,", index); + array_append_format (args, "GPRINT:vdef_%04i_avg:%%lg avg,", index); + array_append_format (args, "GPRINT:vdef_%04i_max:%%lg max,", index); + array_append_format (args, "GPRINT:vdef_%04i_lst:%%lg last\\l", index); free (dses[i]); }