name fixes
Costa Tsaousis (ktsaou) committed
May 9, 2014 at 03:27 UTC
c8dafecdea9166eb6e3677c6352ad6d88602f2e7
1 file changed
+35
-14
netdata.c
+35
-14
@@ -924,6 +924,8 @@ struct rrd_stats {
924
unsigned long hash; // a simple hash on the id, to speed up searching
925
// we first compare hashes, and only if the hashes are equal we do string comparisons
926
927
+ unsigned long hash_name; // a simple hash on the name
928
+
929
char *type; // the type of graph RRD_TYPE_* (a category, for determining graphing options)
930
char *family; // the family of this data set (for grouping them together)
931
char *title; // title shown to user
@@ -959,6 +961,28 @@ typedef struct rrd_stats RRD_STATS;
961
RRD_STATS *root = NULL;
962
pthread_mutex_t root_mutex = PTHREAD_MUTEX_INITIALIZER;
963
964
+char *rrd_stats_strncpy_name(char *to, const char *from, int length)
965
+{
966
+ int i;
967
+ for(i = 0; i < length && from[i] ;i++) {
968
+ if(from[i] == '.' || isalpha(from[i]) || isdigit(from[i])) to[i] = from[i];
969
+ else to[i] = '_';
970
+ }
971
+ if(i < length) to[i] = '\0';
972
+ to[length - 1] = '\0';
973
+
974
+ return to;
975
+}
976
+
977
+void rrd_stats_set_name(RRD_STATS *st, const char *name)
978
+{
979
+ char b[CONFIG_MAX_VALUE+1];
980
+
981
+ rrd_stats_strncpy_name(b, name, CONFIG_MAX_VALUE);
982
+ st->name = config_get(st->id, "name", b);
983
+ st->hash_name = simple_hash(st->name);
984
+}
985
+
986
RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name, const char *family, const char *title, const char *units, long priority, int update_every, int chart_type)
987
{
988
RRD_STATS *st = NULL;
@@ -979,12 +1003,8 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
1003
snprintf(st->id, RRD_STATS_NAME_MAX, "%s.%s", type, id);
1004
st->hash = simple_hash(st->id);
1005
982
- if(name && *name) {
983
- char varvalue[CONFIG_MAX_VALUE + 1];
984
- snprintf(varvalue, CONFIG_MAX_VALUE, "%s.%s", type?type:"", name);
985
- st->name = config_get(st->id, "name", varvalue);
986
- }
987
- else st->name = config_get(st->id, "name", st->id);
1006
+ if(name && *name) rrd_stats_set_name(st, name);
1007
+ else rrd_stats_set_name(st, st->id);
1008
1009
{
1010
char varvalue[CONFIG_MAX_VALUE + 1];
@@ -1025,12 +1045,6 @@ RRD_STATS *rrd_stats_create(const char *type, const char *id, const char *name,
1045
return(st);
1046
}
1047
1028
-void rrd_stats_set_name(RRD_STATS *st, const char *name)
1029
-{
1030
- config_get(st->id, "name", name);
1031
-}
1032
-
1033
-
1048
RRD_DIMENSION *rrd_stats_dimension_add(RRD_STATS *st, const char *id, const char *name, long multiplier, long divisor, int algorithm)
1049
{
1050
char varname[CONFIG_MAX_NAME + 1];
@@ -1129,12 +1143,16 @@ RRD_STATS *rrd_stats_find_bytype(const char *type, const char *id)
1143
1144
RRD_STATS *rrd_stats_find_byname(const char *name)
1145
{
1146
+ char b[CONFIG_MAX_VALUE + 1];
1147
+
1148
pthread_mutex_lock(&root_mutex);
1149
1134
- RRD_STATS *st = root;
1150
+ rrd_stats_strncpy_name(b, name, CONFIG_MAX_VALUE);
1151
+ unsigned long hash = simple_hash(b);
1152
1153
+ RRD_STATS *st = root;
1154
for ( ; st ; st = st->next ) {
1137
- if(strcmp(st->name, name) == 0) break;
1155
+ if(hash == st->hash_name && strcmp(st->name, b) == 0) break;
1156
}
1157
1158
pthread_mutex_unlock(&root_mutex);
@@ -5962,6 +5980,9 @@ void *pluginsd_main(void *ptr)
5980
struct dirent *file = NULL;
5981
struct plugind *cd;
5982
5983
+ // enable the apps plugin by default
5984
+ config_get_boolean("plugins", "apps", 1);
5985
+
5986
if(scan_frequency < 1) scan_frequency = 1;
5987
5988
while(1) {