Metrics.NET icon indicating copy to clipboard operation
Metrics.NET copied to clipboard

Is there any build in support for differentiation of metrics collected from different service nodes?

Open LeonidVasilyev opened this issue 10 years ago • 4 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

LeonidVasilyev avatar Aug 12 '15 12:08 LeonidVasilyev

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);

LeonidVasilyev avatar Aug 14 '15 13:08 LeonidVasilyev

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.

mnadel avatar Nov 18 '15 18:11 mnadel

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.

solmetricchris avatar Dec 04 '15 21:12 solmetricchris

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.

solmetricchris avatar Dec 04 '15 21:12 solmetricchris