mikejihbe / metrics

A metrics library for Node.js
574 stars 58 forks source link

Gauge not working with graphite reporter #64

Closed ankitchiplunkar closed 5 years ago

ankitchiplunkar commented 5 years ago

The gauge metric is not working with the graphite_reporter.

To recreate the issue:

  1. Run graphite container:

    docker run \
    -d \
    --name graphite \
    --restart=always \
    --network host\
    -p 80:80 \
    -p 8080:8080 \
    -p 2003-2004:2003-2004 \
    -p 2023-2024:2023-2024 \
    -p 8125:8125/udp \
    -p 8126:8126 \
    -v /tmp/data/graphite/configs:/opt/graphite/conf \
    -v /tmp/data/graphite/data:/opt/graphite/storage \
    -v /tmp/data/graphite/statsd:/opt/statsd \
    graphiteapp/graphite-statsd
  2. Send some metrics to the graphite container, using getSampleReport from helper.js in test/usint:

    
    const metrics = require("metrics"),
    Report = metrics.Report,
    Counter = metrics.Counter,
    Timer = metrics.Timer,
    Meter = metrics.Meter,
    Histogram = metrics.Histogram,
    CachedGauge = metrics.CachedGauge

function getSampleReport() { var counter = new Counter(); counter.inc(5); var timer = new Timer(); for (var i = 1; i <= 100; i++) { timer.update(i); } var meter = new Meter(); meter.mark(10); var hist = new Histogram(); for (var i = 1; i <= 100; i++) { hist.update(i*2); } var gauge = new CachedGauge(function () { return 0.8 }, 10000); var report = new Report(); report.addMetric("basicCount", counter); report.addMetric("myapp.Meter", meter); report.addMetric("myapp.Timer", timer); report.addMetric("myapp.Histogram", hist); report.addMetric("myapp.Gauge", gauge); return report; }

const report = getSampleReport(); const reporter = new metrics.GraphiteReporter(report, "test", "localhost", 2003); reporter.start(1000);


3. Run the test and send data to graphite

node test.js



4. Checkout graphite browser at `localhost:8080`

![image](https://user-images.githubusercontent.com/5904910/49378668-76871580-f70d-11e8-8d30-3a9b46bc97d0.png)

The Gauge folder is missing from graphite, i.e. gauge data was not sent to graphite container
tolbertam commented 5 years ago

Fixed by #65 and released in v0.1.20, thank you!