@ -43,31 +43,31 @@ const serviceLoadRetryTime = 1 * time.Minute
const minCacheTTL = 30
const minCacheTTL = 30
var (
var (
flag_t est = flag . Bool ( "test" , false , "print all available metrics to stdout" )
flagT est = flag . Bool ( "test" , false , "print all available metrics to stdout" )
flag_luat est = flag . Bool ( "testLua" , false , "read luaTest.json file make all contained calls and dump results" )
flagLuaT est = flag . Bool ( "testLua" , false , "read luaTest.json file make all contained calls and dump results" )
flag_c ollect = flag . Bool ( "collect" , false , "print configured metrics to stdout and exit" )
flagC ollect = flag . Bool ( "collect" , false , "print configured metrics to stdout and exit" )
flag_jsono ut = flag . String ( "json-out" , "" , "store metrics also to JSON file when running test" )
flagJSONO ut = flag . String ( "json-out" , "" , "store metrics also to JSON file when running test" )
flag_addr = flag . String ( "listen-address" , "127.0.0.1:9042" , "The address to listen on for HTTP requests." )
flagAddr = flag . String ( "listen-address" , "127.0.0.1:9042" , "The address to listen on for HTTP requests." )
flag_metrics_file = flag . String ( "metrics-file" , "metrics.json" , "The JSON file with the metric definitions." )
flagMetricsFile = flag . String ( "metrics-file" , "metrics.json" , "The JSON file with the metric definitions." )
flag_disable_lua = flag . Bool ( "nolua" , false , "disable collecting lua metrics" )
flagDisableLua = flag . Bool ( "nolua" , false , "disable collecting lua metrics" )
flag_lua_metrics_f ile = flag . String ( "lua-metrics-file" , "metrics-lua.json" , "The JSON file with the lua metric definitions." )
flagLuaMetricsF ile = flag . String ( "lua-metrics-file" , "metrics-lua.json" , "The JSON file with the lua metric definitions." )
flag_gateway_url = flag . String ( "gateway-url" , "http://fritz.box:49000" , "The URL of the FRITZ!Box" )
flagGatewayURL = flag . String ( "gateway-url" , "http://fritz.box:49000" , "The URL of the FRITZ!Box" )
flag_gateway_luaurl = flag . String ( "gateway-luaurl" , "http://fritz.box" , "The URL of the FRITZ!Box UI" )
flagGatewayLuaURL = flag . String ( "gateway-luaurl" , "http://fritz.box" , "The URL of the FRITZ!Box UI" )
flag_gateway_username = flag . String ( "username" , "" , "The user for the FRITZ!Box UPnP service" )
flagUsername = flag . String ( "username" , "" , "The user for the FRITZ!Box UPnP service" )
flag_gateway_password = flag . String ( "password" , "" , "The password for the FRITZ!Box UPnP service" )
flagPassword = flag . String ( "password" , "" , "The password for the FRITZ!Box UPnP service" )
)
)
var (
var (
collect_e rrors = prometheus . NewCounter ( prometheus . CounterOpts {
collectE rrors = prometheus . NewCounter ( prometheus . CounterOpts {
Name : "fritzbox_exporter_collect_e rrors" ,
Name : "fritzbox_exporter_collectE rrors" ,
Help : "Number of collection errors." ,
Help : "Number of collection errors." ,
} )
} )
)
)
var (
var (
lua_collect_e rrors = prometheus . NewCounter ( prometheus . CounterOpts {
luaCollectE rrors = prometheus . NewCounter ( prometheus . CounterOpts {
Name : "fritzbox_exporter_lua_collect_e rrors" ,
Name : "fritzbox_exporter_luaCollectE rrors" ,
Help : "Number of lua collection errors." ,
Help : "Number of lua collection errors." ,
} )
} )
)
)
@ -92,13 +92,15 @@ var collectUpnpResultsLoaded = prometheus.NewCounter(prometheus.CounterOpts{
ConstLabels : prometheus . Labels { "Cache" : "UPNP" } ,
ConstLabels : prometheus . Labels { "Cache" : "UPNP" } ,
} )
} )
type JSON_PromDesc struct {
// JSONPromDesc metric description loaded from JSON
type JSONPromDesc struct {
FqName string ` json:"fqName" `
FqName string ` json:"fqName" `
Help string ` json:"help" `
Help string ` json:"help" `
VarLabels [ ] string ` json:"varLabels" `
VarLabels [ ] string ` json:"varLabels" `
FixedLabels map [ string ] string ` json:"fixedLabels" `
FixedLabels map [ string ] string ` json:"fixedLabels" `
}
}
// ActionArg argument for upnp action
type ActionArg struct {
type ActionArg struct {
Name string ` json:"Name" `
Name string ` json:"Name" `
IsIndex bool ` json:"IsIndex" `
IsIndex bool ` json:"IsIndex" `
@ -106,42 +108,46 @@ type ActionArg struct {
Value string ` json:"Value" `
Value string ` json:"Value" `
}
}
// Metric upnp metric
type Metric struct {
type Metric struct {
// initialized loading JSON
// initialized loading JSON
Service string ` json:"service" `
Service string ` json:"service" `
Action string ` json:"action" `
Action string ` json:"action" `
ActionArgument * ActionArg ` json:"actionArgument" `
ActionArgument * ActionArg ` json:"actionArgument" `
Result string ` json:"result" `
Result string ` json:"result" `
OkValue string ` json:"okValue" `
OkValue string ` json:"okValue" `
PromDesc JSON_ PromDesc ` json:"promDesc" `
PromDesc JSONPromDesc ` json:"promDesc" `
PromType string ` json:"promType" `
PromType string ` json:"promType" `
CacheEntryTTL int64 ` json:"cacheEntryTTL" `
CacheEntryTTL int64 ` json:"cacheEntryTTL" `
// initialized at startup
// initialized at startup
Desc * prometheus . Desc
Desc * prometheus . Desc
MetricType prometheus . ValueType
MetricType prometheus . ValueType
}
}
// LuaTest JSON struct for API tests
type LuaTest struct {
type LuaTest struct {
Path string ` json:"path" `
Path string ` json:"path" `
Params string ` json:"params" `
Params string ` json:"params" `
}
}
// LuaLabelRename struct
type LuaLabelRename struct {
type LuaLabelRename struct {
MatchRegex string ` json:"matchRegex" `
MatchRegex string ` json:"matchRegex" `
RenameLabel string ` json:"renameLabel" `
RenameLabel string ` json:"renameLabel" `
}
}
// LuaMetric struct
type LuaMetric struct {
type LuaMetric struct {
// initialized loading JSON
// initialized loading JSON
Path string ` json:"path" `
Path string ` json:"path" `
Params string ` json:"params" `
Params string ` json:"params" `
ResultPath string ` json:"resultPath" `
ResultPath string ` json:"resultPath" `
ResultKey string ` json:"resultKey" `
ResultKey string ` json:"resultKey" `
OkValue string ` json:"okValue" `
OkValue string ` json:"okValue" `
PromDesc JSON_ PromDesc ` json:"promDesc" `
PromDesc JSONPromDesc ` json:"promDesc" `
PromType string ` json:"promType" `
PromType string ` json:"promType" `
CacheEntryTTL int64 ` json:"cacheEntryTTL" `
CacheEntryTTL int64 ` json:"cacheEntryTTL" `
// initialized at startup
// initialized at startup
Desc * prometheus . Desc
Desc * prometheus . Desc
@ -150,28 +156,30 @@ type LuaMetric struct {
LuaMetricDef lua . LuaMetricValueDefinition
LuaMetricDef lua . LuaMetricValueDefinition
}
}
// LuaMetricsFile json struct
type LuaMetricsFile struct {
type LuaMetricsFile struct {
LabelRenames [ ] LuaLabelRename ` json:"labelRenames" `
LabelRenames [ ] LuaLabelRename ` json:"labelRenames" `
Metrics [ ] * LuaMetric ` json:"metrics" `
Metrics [ ] * LuaMetric ` json:"metrics" `
}
}
type U pnpCacheEntry struct {
type u pnpCacheEntry struct {
Timestamp int64
Timestamp int64
Result * upnp . Result
Result * upnp . Result
}
}
type L uaCacheEntry struct {
type l uaCacheEntry struct {
Timestamp int64
Timestamp int64
Result * map [ string ] interface { }
Result * map [ string ] interface { }
}
}
var metrics [ ] * Metric
var metrics [ ] * Metric
var luaMetrics [ ] * LuaMetric
var luaMetrics [ ] * LuaMetric
var upnpCache map [ string ] * U pnpCacheEntry
var upnpCache map [ string ] * u pnpCacheEntry
var luaCache map [ string ] * L uaCacheEntry
var luaCache map [ string ] * l uaCacheEntry
// FritzboxCollector main struct
type FritzboxCollector struct {
type FritzboxCollector struct {
Url string
URL string
Gateway string
Gateway string
Username string
Username string
Password string
Password string
@ -185,32 +193,32 @@ type FritzboxCollector struct {
}
}
// simple ResponseWriter to collect output
// simple ResponseWriter to collect output
type T estResponseWriter struct {
type t estResponseWriter struct {
header http . Header
header http . Header
statusCode int
statusCode int
body bytes . Buffer
body bytes . Buffer
}
}
func ( w * T estResponseWriter) Header ( ) http . Header {
func ( w * t estResponseWriter) Header ( ) http . Header {
return w . header
return w . header
}
}
func ( w * T estResponseWriter) Write ( b [ ] byte ) ( int , error ) {
func ( w * t estResponseWriter) Write ( b [ ] byte ) ( int , error ) {
return w . body . Write ( b )
return w . body . Write ( b )
}
}
func ( w * T estResponseWriter) WriteHeader ( statusCode int ) {
func ( w * t estResponseWriter) WriteHeader ( statusCode int ) {
w . statusCode = statusCode
w . statusCode = statusCode
}
}
func ( w * T estResponseWriter) String ( ) string {
func ( w * t estResponseWriter) String ( ) string {
return w . body . String ( )
return w . body . String ( )
}
}
// LoadServices tries to load the service information. Retries until success.
// LoadServices tries to load the service information. Retries until success.
func ( fc * FritzboxCollector ) LoadServices ( ) {
func ( fc * FritzboxCollector ) LoadServices ( ) {
for {
for {
root , err := upnp . LoadServices ( fc . Url , fc . Username , fc . Password )
root , err := upnp . LoadServices ( fc . URL , fc . Username , fc . Password )
if err != nil {
if err != nil {
fmt . Printf ( "cannot load services: %s\n" , err )
fmt . Printf ( "cannot load services: %s\n" , err )
@ -227,18 +235,19 @@ func (fc *FritzboxCollector) LoadServices() {
}
}
}
}
// Describe describe metric
func ( fc * FritzboxCollector ) Describe ( ch chan <- * prometheus . Desc ) {
func ( fc * FritzboxCollector ) Describe ( ch chan <- * prometheus . Desc ) {
for _ , m := range metrics {
for _ , m := range metrics {
ch <- m . Desc
ch <- m . Desc
}
}
}
}
func ( fc * FritzboxCollector ) R eportMetric( ch chan <- prometheus . Metric , m * Metric , result upnp . Result ) {
func ( fc * FritzboxCollector ) r eportMetric( ch chan <- prometheus . Metric , m * Metric , result upnp . Result ) {
val , ok := result [ m . Result ]
val , ok := result [ m . Result ]
if ! ok {
if ! ok {
fmt . Printf ( "%s.%s has no result %s" , m . Service , m . Action , m . Result )
fmt . Printf ( "%s.%s has no result %s" , m . Service , m . Action , m . Result )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
return
return
}
}
@ -260,7 +269,7 @@ func (fc *FritzboxCollector) ReportMetric(ch chan<- prometheus.Metric, m *Metric
}
}
default :
default :
fmt . Println ( "unknown type" , val )
fmt . Println ( "unknown type" , val )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
return
return
}
}
@ -291,7 +300,7 @@ func (fc *FritzboxCollector) ReportMetric(ch chan<- prometheus.Metric, m *Metric
labels ... )
labels ... )
}
}
func ( fc * FritzboxCollector ) G etActionResult( metric * Metric , actionName string , actionArg * upnp . ActionArgument ) ( upnp . Result , error ) {
func ( fc * FritzboxCollector ) g etActionResult( metric * Metric , actionName string , actionArg * upnp . ActionArgument ) ( upnp . Result , error ) {
key := metric . Service + "|" + actionName
key := metric . Service + "|" + actionName
@ -304,7 +313,7 @@ func (fc *FritzboxCollector) GetActionResult(metric *Metric, actionName string,
cacheEntry := upnpCache [ key ]
cacheEntry := upnpCache [ key ]
if cacheEntry == nil {
if cacheEntry == nil {
cacheEntry = & U pnpCacheEntry{ }
cacheEntry = & u pnpCacheEntry{ }
upnpCache [ key ] = cacheEntry
upnpCache [ key ] = cacheEntry
} else if now - cacheEntry . Timestamp > metric . CacheEntryTTL {
} else if now - cacheEntry . Timestamp > metric . CacheEntryTTL {
cacheEntry . Result = nil
cacheEntry . Result = nil
@ -337,6 +346,7 @@ func (fc *FritzboxCollector) GetActionResult(metric *Metric, actionName string,
return * cacheEntry . Result , nil
return * cacheEntry . Result , nil
}
}
// Collect collect upnp metrics
func ( fc * FritzboxCollector ) Collect ( ch chan <- prometheus . Metric ) {
func ( fc * FritzboxCollector ) Collect ( ch chan <- prometheus . Metric ) {
fc . Lock ( )
fc . Lock ( )
root := fc . Root
root := fc . Root
@ -355,11 +365,11 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
value = aa . Value
value = aa . Value
if aa . ProviderAction != "" {
if aa . ProviderAction != "" {
provRes , err := fc . G etActionResult( m , aa . ProviderAction , nil )
provRes , err := fc . g etActionResult( m , aa . ProviderAction , nil )
if err != nil {
if err != nil {
fmt . Printf ( "Error getting provider action %s result for %s.%s: %s\n" , aa . ProviderAction , m . Service , m . Action , err . Error ( ) )
fmt . Printf ( "Error getting provider action %s result for %s.%s: %s\n" , aa . ProviderAction , m . Service , m . Action , err . Error ( ) )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
continue
continue
}
}
@ -367,7 +377,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
value , ok = provRes [ aa . Value ] // Value contains the result name for provider actions
value , ok = provRes [ aa . Value ] // Value contains the result name for provider actions
if ! ok {
if ! ok {
fmt . Printf ( "provider action %s for %s.%s has no result" , m . Service , m . Action , aa . Value )
fmt . Printf ( "provider action %s for %s.%s has no result" , m . Service , m . Action , aa . Value )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
continue
continue
}
}
}
}
@ -377,21 +387,21 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
count , err := strconv . Atoi ( sval )
count , err := strconv . Atoi ( sval )
if err != nil {
if err != nil {
fmt . Println ( err . Error ( ) )
fmt . Println ( err . Error ( ) )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
continue
continue
}
}
for i := 0 ; i < count ; i ++ {
for i := 0 ; i < count ; i ++ {
actArg = & upnp . ActionArgument { Name : aa . Name , Value : i }
actArg = & upnp . ActionArgument { Name : aa . Name , Value : i }
result , err := fc . G etActionResult( m , m . Action , actArg )
result , err := fc . g etActionResult( m , m . Action , actArg )
if err != nil {
if err != nil {
fmt . Println ( err . Error ( ) )
fmt . Println ( err . Error ( ) )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
continue
continue
}
}
fc . R eportMetric( ch , m , result )
fc . r eportMetric( ch , m , result )
}
}
continue
continue
@ -400,15 +410,15 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) {
}
}
}
}
result , err := fc . G etActionResult( m , m . Action , actArg )
result , err := fc . g etActionResult( m , m . Action , actArg )
if err != nil {
if err != nil {
fmt . Println ( err . Error ( ) )
fmt . Println ( err . Error ( ) )
collect_e rrors . Inc ( )
collectE rrors . Inc ( )
continue
continue
}
}
fc . R eportMetric( ch , m , result )
fc . r eportMetric( ch , m , result )
}
}
// if lua is enabled now also collect metrics
// if lua is enabled now also collect metrics
@ -426,7 +436,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric) {
cacheEntry := luaCache [ key ]
cacheEntry := luaCache [ key ]
if cacheEntry == nil {
if cacheEntry == nil {
cacheEntry = & L uaCacheEntry{ }
cacheEntry = & l uaCacheEntry{ }
luaCache [ key ] = cacheEntry
luaCache [ key ] = cacheEntry
} else if now - cacheEntry . Timestamp > lm . CacheEntryTTL {
} else if now - cacheEntry . Timestamp > lm . CacheEntryTTL {
cacheEntry . Result = nil
cacheEntry . Result = nil
@ -437,7 +447,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric) {
if err != nil {
if err != nil {
fmt . Printf ( "Error loading %s for %s.%s: %s\n" , lm . Path , lm . ResultPath , lm . ResultKey , err . Error ( ) )
fmt . Printf ( "Error loading %s for %s.%s: %s\n" , lm . Path , lm . ResultPath , lm . ResultKey , err . Error ( ) )
lua_collect_e rrors . Inc ( )
luaCollectE rrors . Inc ( )
continue
continue
}
}
@ -445,7 +455,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric) {
data , err = lua . ParseJSON ( pageData )
data , err = lua . ParseJSON ( pageData )
if err != nil {
if err != nil {
fmt . Printf ( "Error parsing JSON from %s for %s.%s: %s\n" , lm . Path , lm . ResultPath , lm . ResultKey , err . Error ( ) )
fmt . Printf ( "Error parsing JSON from %s for %s.%s: %s\n" , lm . Path , lm . ResultPath , lm . ResultKey , err . Error ( ) )
lua_collect_e rrors . Inc ( )
luaCollectE rrors . Inc ( )
continue
continue
}
}
@ -460,7 +470,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric) {
if err != nil {
if err != nil {
fmt . Printf ( "Error getting metric values for %s.%s: %s\n" , lm . ResultPath , lm . ResultKey , err . Error ( ) )
fmt . Printf ( "Error getting metric values for %s.%s: %s\n" , lm . ResultPath , lm . ResultKey , err . Error ( ) )
lua_collect_e rrors . Inc ( )
luaCollectE rrors . Inc ( )
continue
continue
}
}
@ -500,7 +510,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu
}
}
func test ( ) {
func test ( ) {
root , err := upnp . LoadServices ( * flag_gateway_url , * flag_gateway_username , * flag_gateway_p assword )
root , err := upnp . LoadServices ( * flagGatewayURL , * flagUsername , * flagP assword )
if err != nil {
if err != nil {
panic ( err )
panic ( err )
}
}
@ -516,7 +526,7 @@ func test() {
sort . Strings ( serviceKeys )
sort . Strings ( serviceKeys )
for _ , k := range serviceKeys {
for _ , k := range serviceKeys {
s := root . Services [ k ]
s := root . Services [ k ]
fmt . Printf ( "Service: %s (Url: %s)\n" , k , s . ControlUrl )
fmt . Printf ( "Service: %s (Url: %s)\n" , k , s . ControlURL )
actionKeys := [ ] string { }
actionKeys := [ ] string { }
for l := range s . Actions {
for l := range s . Actions {
@ -571,10 +581,10 @@ func test() {
json . WriteString ( "\n]" )
json . WriteString ( "\n]" )
if * flag_jsono ut != "" {
if * flagJSONO ut != "" {
err := ioutil . WriteFile ( * flag_jsono ut , json . Bytes ( ) , 0644 )
err := ioutil . WriteFile ( * flagJSONO ut , json . Bytes ( ) , 0644 )
if err != nil {
if err != nil {
fmt . Printf ( "Failed writing JSON file '%s': %s\n" , * flag_jsono ut , err . Error ( ) )
fmt . Printf ( "Failed writing JSON file '%s': %s\n" , * flagJSONO ut , err . Error ( ) )
}
}
}
}
}
}
@ -595,7 +605,7 @@ func testLua() {
}
}
// create session struct and init params
// create session struct and init params
luaSession := lua . LuaSession { BaseURL : * flag_gateway_luaurl , Username : * flag_gateway_u sername , Password : * flag_gateway_p assword }
luaSession := lua . LuaSession { BaseURL : * flagGatewayLuaURL , Username : * flagU sername , Password : * flagP assword }
for _ , test := range luaTests {
for _ , test := range luaTests {
fmt . Printf ( "TESTING: %s (%s)\n" , test . Path , test . Params )
fmt . Printf ( "TESTING: %s (%s)\n" , test . Path , test . Params )
@ -609,7 +619,8 @@ func testLua() {
fmt . Println ( string ( pageData ) )
fmt . Println ( string ( pageData ) )
}
}
fmt . Println ( "\n" )
fmt . Println ( )
fmt . Println ( )
}
}
}
}
@ -629,24 +640,24 @@ func getValueType(vt string) prometheus.ValueType {
func main ( ) {
func main ( ) {
flag . Parse ( )
flag . Parse ( )
u , err := url . Parse ( * flag_gateway_url )
u , err := url . Parse ( * flagGatewayURL )
if err != nil {
if err != nil {
fmt . Println ( "invalid URL:" , err )
fmt . Println ( "invalid URL:" , err )
return
return
}
}
if * flag_t est {
if * flagT est {
test ( )
test ( )
return
return
}
}
if * flag_luat est {
if * flagLuaT est {
testLua ( )
testLua ( )
return
return
}
}
// read metrics
// read metrics
jsonData , err := ioutil . ReadFile ( * flag_metrics_f ile )
jsonData , err := ioutil . ReadFile ( * flagMetricsF ile )
if err != nil {
if err != nil {
fmt . Println ( "error reading metric file:" , err )
fmt . Println ( "error reading metric file:" , err )
return
return
@ -659,12 +670,12 @@ func main() {
}
}
// create a map for caching results
// create a map for caching results
upnpCache = make ( map [ string ] * U pnpCacheEntry)
upnpCache = make ( map [ string ] * u pnpCacheEntry)
var luaSession * lua . LuaSession
var luaSession * lua . LuaSession
var luaLabelRenames * [ ] lua . LabelRename
var luaLabelRenames * [ ] lua . LabelRename
if ! * flag_disable_l ua {
if ! * flagDisableL ua {
jsonData , err := ioutil . ReadFile ( * flag_lua_metrics_f ile )
jsonData , err := ioutil . ReadFile ( * flagLuaMetricsF ile )
if err != nil {
if err != nil {
fmt . Println ( "error reading lua metric file:" , err )
fmt . Println ( "error reading lua metric file:" , err )
return
return
@ -678,7 +689,7 @@ func main() {
}
}
// create a map for caching results
// create a map for caching results
luaCache = make ( map [ string ] * L uaCacheEntry)
luaCache = make ( map [ string ] * l uaCacheEntry)
// init label renames
// init label renames
lblRen := make ( [ ] lua . LabelRename , 0 )
lblRen := make ( [ ] lua . LabelRename , 0 )
@ -727,9 +738,9 @@ func main() {
}
}
luaSession = & lua . LuaSession {
luaSession = & lua . LuaSession {
BaseURL : * flag_gateway_luaurl ,
BaseURL : * flagGatewayLuaURL ,
Username : * flag_gateway_u sername ,
Username : * flagU sername ,
Password : * flag_gateway_p assword ,
Password : * flagP assword ,
}
}
}
}
@ -753,28 +764,28 @@ func main() {
}
}
collector := & FritzboxCollector {
collector := & FritzboxCollector {
Url : * flag_gateway_url ,
URL : * flagGatewayURL ,
Gateway : u . Hostname ( ) ,
Gateway : u . Hostname ( ) ,
Username : * flag_gateway_u sername ,
Username : * flagU sername ,
Password : * flag_gateway_p assword ,
Password : * flagP assword ,
LuaSession : luaSession ,
LuaSession : luaSession ,
LabelRenames : luaLabelRenames ,
LabelRenames : luaLabelRenames ,
}
}
if * flag_c ollect {
if * flagC ollect {
collector . LoadServices ( )
collector . LoadServices ( )
prometheus . MustRegister ( collector )
prometheus . MustRegister ( collector )
prometheus . MustRegister ( collect_e rrors )
prometheus . MustRegister ( collectE rrors )
if luaSession != nil {
if luaSession != nil {
prometheus . MustRegister ( lua_collect_e rrors )
prometheus . MustRegister ( luaCollectE rrors )
}
}
fmt . Println ( "collecting metrics via http" )
fmt . Println ( "collecting metrics via http" )
// simulate HTTP request without starting actual http server
// simulate HTTP request without starting actual http server
writer := T estResponseWriter{ header : http . Header { } }
writer := t estResponseWriter{ header : http . Header { } }
request := http . Request { }
request := http . Request { }
promhttp . Handler ( ) . ServeHTTP ( & writer , & request )
promhttp . Handler ( ) . ServeHTTP ( & writer , & request )
@ -786,18 +797,18 @@ func main() {
go collector . LoadServices ( )
go collector . LoadServices ( )
prometheus . MustRegister ( collector )
prometheus . MustRegister ( collector )
prometheus . MustRegister ( collect_e rrors )
prometheus . MustRegister ( collectE rrors )
prometheus . MustRegister ( collectUpnpResultsCached )
prometheus . MustRegister ( collectUpnpResultsCached )
prometheus . MustRegister ( collectUpnpResultsLoaded )
prometheus . MustRegister ( collectUpnpResultsLoaded )
if luaSession != nil {
if luaSession != nil {
prometheus . MustRegister ( lua_collect_e rrors )
prometheus . MustRegister ( luaCollectE rrors )
prometheus . MustRegister ( collectLuaResultsCached )
prometheus . MustRegister ( collectLuaResultsCached )
prometheus . MustRegister ( collectLuaResultsLoaded )
prometheus . MustRegister ( collectLuaResultsLoaded )
}
}
http . Handle ( "/metrics" , promhttp . Handler ( ) )
http . Handle ( "/metrics" , promhttp . Handler ( ) )
fmt . Printf ( "metrics available at http://%s/metrics\n" , * flag_a ddr )
fmt . Printf ( "metrics available at http://%s/metrics\n" , * flagA ddr )
log . Fatal ( http . ListenAndServe ( * flag_a ddr , nil ) )
log . Fatal ( http . ListenAndServe ( * flagA ddr , nil ) )
}
}