]> granicus.if.org Git - icinga2/commitdiff
GraphiteWriter: Add support for customized metric prefix names
authorMichael Friedrich <michael.friedrich@gmail.com>
Sat, 11 Oct 2014 18:38:24 +0000 (20:38 +0200)
committerMichael Friedrich <michael.friedrich@gmail.com>
Sat, 11 Oct 2014 18:38:24 +0000 (20:38 +0200)
Allows to use runtime macros and global constants for setting
a custom metric prefix:

    const GraphiteEnv = "icinga.env1"

    object GraphiteWriter "graphite" {
      host_name_template = GraphiteEnv + ".$host.name$"
      service_name_template = GraphiteEnv + ".$host.name$.$service.name$"
    }

fixes #7334

components/perfdata/graphitewriter.cpp
components/perfdata/graphitewriter.ti
components/perfdata/perfdata-type.conf
doc/3-monitoring-basics.md
doc/6-configuring-icinga-2.md
tools/syntax/nano/icinga2.nanorc
tools/syntax/vim/syntax/icinga2.vim

index c0d6d3536688d76a08b150b336d1952441deef39..9e9dd8fe62b7c0b476cf9ea1e2f1fa5669151e29 100644 (file)
@@ -111,14 +111,27 @@ void GraphiteWriter::CheckResultHandler(const Checkable::Ptr& checkable, const C
 
        String prefix;
 
+       MacroProcessor::ResolverList resolvers;
+       if (service)
+               resolvers.push_back(std::make_pair("service", service));
+       resolvers.push_back(std::make_pair("host", host));
+       resolvers.push_back(std::make_pair("icinga", IcingaApplication::GetInstance()));
+
        if (service) {
                String serviceName = service->GetShortName();
                SanitizeMetric(serviceName);
-               prefix = "icinga." + hostName + "." + serviceName;
+
+               /* custom prefix or default pattern */
+               prefix = MacroProcessor::ResolveMacros(GetServiceNameTemplate(), resolvers, cr);
+               if (prefix.IsEmpty())
+                       prefix = "icinga." + hostName + "." + serviceName;
 
                SendMetric(prefix, "state", service->GetState());
        } else {
-               prefix = "icinga." + hostName;
+               /* custom prefix or default pattern */
+               prefix = MacroProcessor::ResolveMacros(GetHostNameTemplate(), resolvers, cr);
+               if (prefix.IsEmpty())
+                       prefix = "icinga." + hostName;
 
                SendMetric(prefix, "state", host->GetState());
        }
index 29311b44cdb566f9896d13f237010883e4bee269..b34a8eb9430f51d270871b73ad6e2844a073aa42 100644 (file)
@@ -11,6 +11,12 @@ class GraphiteWriter : DynamicObject
        [config] String port {
                default {{{ return "2003"; }}}
        };
+       [config] String host_name_template {
+               default {{{ return "icinga.$host.name$"; }}}
+       };
+       [config] String service_name_template {
+               default {{{ return "icinga.$host.name$.$service.name$"; }}}
+       };
 };
 
 }
index 69ecd334a9d9d821829d5ea92b9f49251045b7c4..011a881c1f337e3d9bb83ca1041e3319b4181d23 100644 (file)
@@ -30,4 +30,6 @@
 %type GraphiteWriter {
        %attribute %string "host",
        %attribute %string "port",
+       %attribute %string "host_name_template",
+       %attribute %string "service_name_template"
 }
index b904a1817dec7ca756865a7dd4319894cef5a6bc..2fa84054721dbff29019a88ac3c820970533ed0a 100644 (file)
@@ -1836,6 +1836,20 @@ The current naming schema is
     icinga.<hostname>.<metricname>
     icinga.<hostname>.<servicename>.<metricname>
 
+You can customize the metric prefix name by using the `host_name_template` and
+`service_name_template` configuration attributes.
+
+The example below uses [runtime macros](#runtime-macros) and a
+[global constant](#global-constants) named `GraphiteEnv`. The constant name
+is freely definable and should be put in the [constants.conf](#constants-conf) file.
+
+    const GraphiteEnv = "icinga.env1"
+
+    object GraphiteWriter "graphite" {
+      host_name_template = GraphiteEnv + ".$host.name$"
+      service_name_template = GraphiteEnv + ".$host.name$.$service.name$"
+    }
+
 To make sure Icinga 2 writes a valid label into Graphite some characters are replaced
 with `_` in the target name:
 
@@ -1854,6 +1868,7 @@ internal check statistic data to Graphite:
   current_attempt    | current check attempt
   max_check_attempts | maximum check attempts until the hard state is reached
   reachable          | checked object is reachable
+  downtime_depth     | number of downtimes this object is in
   execution_time     | check execution time
   latency            | check latency
   state              | current state of the checked object
index 42b51112b4a16aa2233b03116c7f57d2efc3ca3c..44ad75605773b40699cb75c04166f25b4d6a8fa0 100644 (file)
@@ -1300,10 +1300,21 @@ Example:
 
 Attributes:
 
-  Name            |Description
-  ----------------|----------------
-  host            |**Optional.** Graphite Carbon host address. Defaults to '127.0.0.1'.
-  port            |**Optional.** Graphite Carbon port. Defaults to 2003.
+  Name                 |Description
+  ----------------------|----------------------
+  host                 |**Optional.** Graphite Carbon host address. Defaults to '127.0.0.1'.
+  port                 |**Optional.** Graphite Carbon port. Defaults to 2003.
+  host_name_template   |**Optional.** Metric prefix for host name. Defaults to "icinga.$host.name$".
+  service_name_template |**Optional.** Metric prefix for service name. Defaults to "icinga.$host.name$.$service.name$".
+
+Metric prefix names can be modified using [runtime macros](#runtime-macros).
+
+Example with your custom [global constant](#global-constants) `GraphiteEnv`:
+
+    const GraphiteEnv = "icinga.env1"
+
+    host_name_template = GraphiteEnv + ".$host.name$"
+    service_name_template = GraphiteEnv + ".$host.name$.$service.name$"
 
 ### <a id="objecttype-idomysqlconnection"></a> IdoMySqlConnection
 
index bd3281dfc38f0f4c0648d0047a12f35c7cefac47..c36710e75b056022abfa81d02e66a93db252b698 100644 (file)
@@ -26,12 +26,12 @@ icolor red          "(^|^\s+)(comment|compat_log_path|crl_path|database|disable_checks|
 icolor red             "(^|^\s+)(display_name|duration|email|enable_active_checks|enable_event_handler)"
 icolor red             "(^|^\s+)(enable_flapping|enable_ha|enable_notifications|enable_passive_checks|enable_perfdata)"
 icolor red             "(^|^\s+)(endpoints|env|event_command|failover_timeout|fixed|flapping_threshold|groups|host)"
-icolor red             "(^|^\s+)(host_format_template|host_name|host_perfdata_path|host_temp_path|icon_image)"
+icolor red             "(^|^\s+)(host_format_template|host_name|host_name_template|host_perfdata_path|host_temp_path|icon_image)"
 icolor red             "(^|^\s+)(icon_image_alt|instance_description|instance_name|interval|key_path|log_dir)"
 icolor red             "(^|^\s+)(log_duration|max_check_attempts|methods|name|notes|notes_url|objects_path)"
 icolor red             "(^|^\s+)(pager|parent|parent_host_name|parent_service_name|password|path|period)"
 icolor red             "(^|^\s+)(port|ranges|retry_interval|rotation_interval|rotation_method)"
-icolor red             "(^|^\s+)(service_format_template|service_name|service_perfdata_path|service_temp_path)"
+icolor red             "(^|^\s+)(service_format_template|service_name|service_name_template|service_perfdata_path|service_temp_path)"
 icolor red             "(^|^\s+)(severity|socket_path|socket_type|spool_dir|states|status_path|table_prefix)"
 icolor red             "(^|^\s+)(timeout|times|types|update_interval|user|user_groups|users|volatile)"
 icolor red             "(^|^\s+)(vars\.\w+)"
index 109d075139c65d28aa776ad64fa4247098bc1d3c..3ea37488aeb7cdd4dcee67e38f76100887d8ad0d 100644 (file)
@@ -69,12 +69,12 @@ syn keyword         icinga2ObjAttr          contained       comment compat_log_path crl_path database
 syn keyword            icinga2ObjAttr          contained       display_name duration email enable_active_checks enable_event_handler
 syn keyword            icinga2ObjAttr          contained       enable_flapping enable_ha enable_notifications enable_passive_checks enable_perfdata
 syn keyword            icinga2ObjAttr          contained       endpoints env event_command failover_timeout fixed flapping_threshold groups host
-syn keyword            icinga2ObjAttr          contained       host_format_template host_name host_perfdata_path host_temp_path icon_image
+syn keyword            icinga2ObjAttr          contained       host_format_template host_name host_name_template host_perfdata_path host_temp_path icon_image
 syn keyword            icinga2ObjAttr          contained       icon_image_alt instance_description instance_name interval key_path log_dir
 syn keyword            icinga2ObjAttr          contained       log_duration max_check_attempts methods name notes notes_url objects_path
 syn keyword            icinga2ObjAttr          contained       pager parent parent_host_name parent_service_name password path period
 syn keyword            icinga2ObjAttr          contained       port ranges retry_interval rotation_interval rotation_method
-syn keyword            icinga2ObjAttr          contained       service_format_template service_name service_perfdata_path service_temp_path
+syn keyword            icinga2ObjAttr          contained       service_format_template service_name service_name_template service_perfdata_path service_temp_path
 syn keyword            icinga2ObjAttr          contained       severity socket_path socket_type spool_dir states status_path table_prefix
 syn keyword            icinga2ObjAttr          contained       timeout times types update_interval user user_groups users volatile
 syn match              icinga2ObjAttr          contained       "\(vars.\w\+\)"