()
| 686 | } |
| 687 | |
| 688 | func ExampleNewMetricWithTimestamp() { |
| 689 | desc := prometheus.NewDesc( |
| 690 | "temperature_kelvin", |
| 691 | "Current temperature in Kelvin.", |
| 692 | nil, nil, |
| 693 | ) |
| 694 | |
| 695 | // Create a constant gauge from values we got from an external |
| 696 | // temperature reporting system. Those values are reported with a slight |
| 697 | // delay, so we want to add the timestamp of the actual measurement. |
| 698 | temperatureReportedByExternalSystem := 298.15 |
| 699 | timeReportedByExternalSystem := time.Date(2009, time.November, 10, 23, 0, 0, 12345678, time.UTC) |
| 700 | s := prometheus.NewMetricWithTimestamp( |
| 701 | timeReportedByExternalSystem, |
| 702 | prometheus.MustNewConstMetric( |
| 703 | desc, prometheus.GaugeValue, temperatureReportedByExternalSystem, |
| 704 | ), |
| 705 | ) |
| 706 | |
| 707 | // Just for demonstration, let's check the state of the gauge by |
| 708 | // (ab)using its Write method (which is usually only used by Prometheus |
| 709 | // internally). |
| 710 | metric := &dto.Metric{} |
| 711 | s.Write(metric) |
| 712 | fmt.Println(toNormalizedJSON(metric)) |
| 713 | |
| 714 | // Output: |
| 715 | // {"gauge":{"value":298.15},"timestampMs":"1257894000012"} |
| 716 | } |
| 717 | |
| 718 | func ExampleNewConstMetricWithCreatedTimestamp() { |
| 719 | // Here we have a metric that is reported by an external system. |
nothing calls this directly
no test coverage detected