99 "log"
1010 "net/http"
1111 "os"
12+ "strconv"
1213 "time"
1314
1415 "github.com/prometheus/client_golang/prometheus"
@@ -17,6 +18,7 @@ import (
1718)
1819
1920type NginxVts struct {
21+ HostName string `json:"hostName"`
2022 NginxVersion string `json:"nginxVersion"`
2123 LoadMsec int64 `json:"loadMsec"`
2224 NowMsec int64 `json:"nowMsec"`
@@ -141,6 +143,7 @@ type Cache struct {
141143type Exporter struct {
142144 URI string
143145
146+ infoMetric * prometheus.Desc
144147 serverMetrics , upstreamMetrics , filterMetrics , cacheMetrics map [string ]* prometheus.Desc
145148}
146149
@@ -174,7 +177,8 @@ func newCacheMetric(metricName string, docString string, labels []string) *prome
174177
175178func NewExporter (uri string ) * Exporter {
176179 return & Exporter {
177- URI : uri ,
180+ URI : uri ,
181+ infoMetric : newServerMetric ("info" , "nginx info" , []string {"hostName" , "nginxVersion" , "uptimeSec" }),
178182 serverMetrics : map [string ]* prometheus.Desc {
179183 "connections" : newServerMetric ("connections" , "nginx connections" , []string {"status" }),
180184 "requests" : newServerMetric ("requests" , "requests counter" , []string {"host" , "code" }),
@@ -237,6 +241,14 @@ func (e *Exporter) Collect(ch chan<- prometheus.Metric) {
237241 return
238242 }
239243
244+ // info
245+ uptime := nginxVtx .NowMsec - nginxVtx .LoadMsec
246+ up := 0.0
247+ if uptime > 0 {
248+ up = 1.0
249+ }
250+ ch <- prometheus .MustNewConstMetric (e .infoMetric , prometheus .GaugeValue , up , nginxVtx .HostName , nginxVtx .NginxVersion , strconv .FormatInt (uptime / 1000 , 10 ))
251+
240252 // connections
241253 ch <- prometheus .MustNewConstMetric (e .serverMetrics ["connections" ], prometheus .GaugeValue , float64 (nginxVtx .Connections .Active ), "active" )
242254 ch <- prometheus .MustNewConstMetric (e .serverMetrics ["connections" ], prometheus .GaugeValue , float64 (nginxVtx .Connections .Reading ), "reading" )
0 commit comments