Skip to content

Commit

Permalink
Merge pull request #13 from sanity-io/master
Browse files Browse the repository at this point in the history
Added -monitoring.metrics-offset flag
  • Loading branch information
frodenas authored Sep 7, 2017
2 parents 34f2be2 + ce444d6 commit 518bf81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ If you are still using the legacy [Access scopes][access-scopes], the `https://w
| `google.project-id`<br />`STACKDRIVER_EXPORTER_GOOGLE_PROJECT_ID` | Yes | | Google Project ID |
| `monitoring.metrics-type-prefixes`<br />`STACKDRIVER_EXPORTER_MONITORING_METRICS_TYPE_PREFIXES` | Yes | | Comma separated Google Stackdriver Monitoring Metric Type prefixes (see [example][metrics-prefix-example] and [available metrics][metrics-list]) |
| `monitoring.metrics-interval`<br />`STACKDRIVER_EXPORTER_MONITORING_METRICS_INTERVAL` | No | `5m` | Metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API. Only the most recent data point is used |
| `monitoring.metrics-offset`<br />`STACKDRIVER_EXPORTER_MONITORING_METRICS_OFFSET` | No | `0s` | Offset (into the past) for the metric's timestamp interval to request from the Google Stackdriver Monitoring Metrics API, to handle latency in published metrics |
| `web.listen-address`<br />`STACKDRIVER_EXPORTER_WEB_LISTEN_ADDRESS` | No | `:9255` | Address to listen on for web interface and telemetry |
| `web.telemetry-path`<br />`STACKDRIVER_EXPORTER_WEB_TELEMETRY_PATH` | No | `/metrics` | Path under which to expose Prometheus metrics |

Expand Down
7 changes: 5 additions & 2 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type MonitoringCollector struct {
projectID string
metricsTypePrefixes []string
metricsInterval time.Duration
metricsOffset time.Duration
monitoringService *monitoring.Service
apiCallsTotalMetric prometheus.Counter
scrapesTotalMetric prometheus.Counter
Expand All @@ -32,6 +33,7 @@ func NewMonitoringCollector(
projectID string,
metricsTypePrefixes []string,
metricsInterval time.Duration,
metricsOffset time.Duration,
monitoringService *monitoring.Service,
) (*MonitoringCollector, error) {
apiCallsTotalMetric := prometheus.NewCounter(
Expand Down Expand Up @@ -98,6 +100,7 @@ func NewMonitoringCollector(
projectID: projectID,
metricsTypePrefixes: metricsTypePrefixes,
metricsInterval: metricsInterval,
metricsOffset: metricsOffset,
monitoringService: monitoringService,
apiCallsTotalMetric: apiCallsTotalMetric,
scrapesTotalMetric: scrapesTotalMetric,
Expand Down Expand Up @@ -153,8 +156,8 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri

errChannel := make(chan error, len(page.MetricDescriptors))

startTime := time.Now().UTC().Add(c.metricsInterval * -1)
endTime := time.Now().UTC()
startTime := time.Now().UTC().Add(c.metricsInterval * -1).Add(c.metricsOffset * -1)
endTime := time.Now().UTC().Add(c.metricsOffset * -1)

for _, metricDescriptor := range page.MetricDescriptors {
wg.Add(1)
Expand Down
8 changes: 7 additions & 1 deletion stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ var (
"Interval to request the Google Stackdriver Monitoring Metrics for. Only the most recent data point is used ($STACKDRIVER_EXPORTER_MONITORING_METRICS_INTERVAL).",
)

monitoringMetricsOffset = flag.Duration(
"monitoring.metrics-offset", 0*time.Second,
"Offset for the Google Stackdriver Monitoring Metrics interval into the past ($STACKDRIVER_EXPORTER_MONITORING_METRICS_OFFSET).",
)

listenAddress = flag.String(
"web.listen-address", ":9255",
"Address to listen on for web interface and telemetry ($STACKDRIVER_EXPORTER_WEB_LISTEN_ADDRESS).",
Expand All @@ -58,6 +63,7 @@ func overrideFlagsWithEnvVars() {
overrideWithEnvVar("STACKDRIVER_EXPORTER_GOOGLE_PROJECT_ID", projectID)
overrideWithEnvVar("STACKDRIVER_EXPORTER_MONITORING_METRICS_TYPE_PREFIXES", monitoringMetricsTypePrefixes)
overrideWithEnvDuration("STACKDRIVER_EXPORTER_MONITORING_METRICS_INTERVAL", monitoringMetricsInterval)
overrideWithEnvDuration("STACKDRIVER_EXPORTER_MONITORING_METRICS_OFFSET", monitoringMetricsOffset)
overrideWithEnvVar("STACKDRIVER_EXPORTER_WEB_LISTEN_ADDRESS", listenAddress)
overrideWithEnvVar("STACKDRIVER_EXPORTER_WEB_TELEMETRY_PATH", metricsPath)
}
Expand Down Expand Up @@ -125,7 +131,7 @@ func main() {
os.Exit(1)
}

monitoringCollector, err := collectors.NewMonitoringCollector(*projectID, metricsTypePrefixes, *monitoringMetricsInterval, monitoringService)
monitoringCollector, err := collectors.NewMonitoringCollector(*projectID, metricsTypePrefixes, *monitoringMetricsInterval, *monitoringMetricsOffset, monitoringService)
if err != nil {
log.Error(err)
os.Exit(1)
Expand Down

0 comments on commit 518bf81

Please sign in to comment.