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());
}
[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$"; }}}
+ };
};
}
%type GraphiteWriter {
%attribute %string "host",
%attribute %string "port",
+ %attribute %string "host_name_template",
+ %attribute %string "service_name_template"
}
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:
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
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
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+)"
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\+\)"