Skip to content

Commit d719302

Browse files
committed
#29 #55 add server info metric
1 parent 82382ed commit d719302

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ _testmain.go
2222
*.exe
2323
*.test
2424
*.prof
25+
26+
nginx-vts-exporter

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ For grafana dashboard please see [nginx-vts-exporter dashboard](https://grafana.
9090

9191
Nginx data | Name | Exposed informations
9292
------------------ | ------------------------------- | ------------------------
93+
**Info** | `{NAMESPACE}_server_info` | hostName, nginxVersion, uptimeSec |
9394
**Connections** | `{NAMESPACE}_server_connections`| status [active, reading, writing, waiting, accepted, handled]
9495

9596
**Metrics output example**
9697

9798
``` txt
99+
# Server Info
100+
nginx_server_info{hostName="localhost", nginxVersion="1.11.1", uptimeSec="9527"} 1
98101
# Server Connections
99102
nginx_server_connections{status="accepted"} 70606
100103
```

nginx_vts_exporter.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
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

1920
type 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 {
141143
type 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

175178
func 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

Comments
 (0)