Is there any build in support for differentiation of metrics collected from different service nodes?
LeonidVasilyev opened this issue · comments
I'm using graphite to store metrics and I want to be able to differentiate metrics that came from different service nodes and different environment.
For example:
production.service.node_1.cpu
production.service.node_2.cpu
staging.service.node_1.cpu
Am I correct that the best way to do so is to set <add key="Metrics.GlobalContextName" value="production"/>
in config file and identify machine within the code? Like this:
var service = "service";
var machine = RoleEnvironment.IsAvailable ?
RoleEnvironment.DeploymentId : Environment.MachineName;
var meter = Metric.Context(service).Context(machine).Meter("requests", Unit.Requests);
You can also use tags. On second thought, it'll depend on how the Graphite report is implemented, and on a casual look, it doesn't look like they're being utilized.
Is there anyway to programmatically do the .Context("servicename"). thing on global level ?
ie not via messing with the config ?
I'd rather have the effect every where than to have to initialize each Timer with that long builder and possibly have them get out of sync.
A bit hacky, but this is what I did:
Note, this code needs to be run before you initially config your Metrics, so that the value will get used.
string root = System.Configuration.ConfigurationManager.AppSettings["Metrics.GlobalContextName"];
System.Configuration.ConfigurationManager.AppSettings["Metrics.GlobalContextName"] = root + "." + Environment.MachineName;
and it more or less seems to work.