|
@ -21,8 +21,8 @@ import ( |
|
|
"github.com/namsral/flag" |
|
|
"github.com/namsral/flag" |
|
|
"github.com/prometheus/client_golang/prometheus" |
|
|
"github.com/prometheus/client_golang/prometheus" |
|
|
"github.com/prometheus/client_golang/prometheus/promhttp" |
|
|
"github.com/prometheus/client_golang/prometheus/promhttp" |
|
|
|
|
|
"github.com/sirupsen/logrus" |
|
|
"io/ioutil" |
|
|
"io/ioutil" |
|
|
"log" |
|
|
|
|
|
"net/http" |
|
|
"net/http" |
|
|
"net/url" |
|
|
"net/url" |
|
|
"regexp" |
|
|
"regexp" |
|
@ -56,6 +56,8 @@ var ( |
|
|
flagGatewayLuaURL = 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") |
|
|
flagUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service") |
|
|
flagUsername = flag.String("username", "", "The user for the FRITZ!Box UPnP service") |
|
|
flagPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service") |
|
|
flagPassword = flag.String("password", "", "The password for the FRITZ!Box UPnP service") |
|
|
|
|
|
|
|
|
|
|
|
flagLogLevel = flag.String("log-level", "info", "The logging level. Can be error, warn, info, debug or trace") |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var ( |
|
|
var ( |
|
@ -220,13 +222,13 @@ 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) |
|
|
logrus.Errorf("cannot load services: %s", err) |
|
|
|
|
|
|
|
|
time.Sleep(serviceLoadRetryTime) |
|
|
time.Sleep(serviceLoadRetryTime) |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fmt.Printf("services loaded\n") |
|
|
logrus.Info("services loaded") |
|
|
|
|
|
|
|
|
fc.Lock() |
|
|
fc.Lock() |
|
|
fc.Root = root |
|
|
fc.Root = root |
|
@ -246,7 +248,7 @@ func (fc *FritzboxCollector) reportMetric(ch chan<- prometheus.Metric, m *Metric |
|
|
|
|
|
|
|
|
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) |
|
|
logrus.Debugf("%s.%s has no result %s", m.Service, m.Action, m.Result) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -268,7 +270,7 @@ func (fc *FritzboxCollector) reportMetric(ch chan<- prometheus.Metric, m *Metric |
|
|
floatval = 0 |
|
|
floatval = 0 |
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
fmt.Println("unknown type", val) |
|
|
logrus.Warnf("unknown type: %s", val) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -280,7 +282,7 @@ func (fc *FritzboxCollector) reportMetric(ch chan<- prometheus.Metric, m *Metric |
|
|
} else { |
|
|
} else { |
|
|
lval, ok := result[l] |
|
|
lval, ok := result[l] |
|
|
if !ok { |
|
|
if !ok { |
|
|
fmt.Printf("%s.%s has no resul for label %s", m.Service, m.Action, l) |
|
|
logrus.Warnf("%s.%s has no resul for label %s", m.Service, m.Action, l) |
|
|
lval = "" |
|
|
lval = "" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -296,7 +298,7 @@ func (fc *FritzboxCollector) reportMetric(ch chan<- prometheus.Metric, m *Metric |
|
|
// check for duplicate labels to prevent collection failure
|
|
|
// check for duplicate labels to prevent collection failure
|
|
|
key := m.PromDesc.FqName + ":" + m.PromDesc.fixedLabelValues + strings.Join(labels, ",") |
|
|
key := m.PromDesc.FqName + ":" + m.PromDesc.fixedLabelValues + strings.Join(labels, ",") |
|
|
if dupCache[key] { |
|
|
if dupCache[key] { |
|
|
fmt.Printf("%s.%s reported before as: %s\n", m.Service, m.Action, key) |
|
|
logrus.Debugf("%s.%s reported before as: %s\n", m.Service, m.Action, key) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -304,7 +306,7 @@ func (fc *FritzboxCollector) reportMetric(ch chan<- prometheus.Metric, m *Metric |
|
|
|
|
|
|
|
|
metric, err := prometheus.NewConstMetric(m.Desc, m.MetricType, floatval, labels...) |
|
|
metric, err := prometheus.NewConstMetric(m.Desc, m.MetricType, floatval, labels...) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf("Error creating metric %s.%s: %s", m.Service, m.Action, err.Error()) |
|
|
logrus.Errorf("Can not create metric %s.%s: %s", m.Service, m.Action, err.Error()) |
|
|
} else { |
|
|
} else { |
|
|
ch <- metric |
|
|
ch <- metric |
|
|
} |
|
|
} |
|
@ -381,7 +383,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { |
|
|
provRes, err := fc.getActionResult(m, aa.ProviderAction, nil) |
|
|
provRes, err := fc.getActionResult(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()) |
|
|
logrus.Warnf("Error getting provider action %s result for %s.%s: %s", aa.ProviderAction, m.Service, m.Action, err.Error()) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -389,7 +391,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { |
|
|
var ok bool |
|
|
var ok bool |
|
|
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) |
|
|
logrus.Warnf("provider action %s for %s.%s has no result", m.Service, m.Action, aa.Value) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -399,7 +401,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { |
|
|
sval := fmt.Sprintf("%v", value) |
|
|
sval := fmt.Sprintf("%v", value) |
|
|
count, err := strconv.Atoi(sval) |
|
|
count, err := strconv.Atoi(sval) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err.Error()) |
|
|
logrus.Warn(err.Error()) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -409,7 +411,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { |
|
|
result, err := fc.getActionResult(m, m.Action, actArg) |
|
|
result, err := fc.getActionResult(m, m.Action, actArg) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err.Error()) |
|
|
logrus.Error("Can not get result for %s: %s", m.Action, err) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -426,7 +428,7 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { |
|
|
result, err := fc.getActionResult(m, m.Action, actArg) |
|
|
result, err := fc.getActionResult(m, m.Action, actArg) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err.Error()) |
|
|
logrus.Warnf("can not collect metrics: %s", err) |
|
|
collectErrors.Inc() |
|
|
collectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -459,7 +461,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric, dupCache ma |
|
|
pageData, err := fc.LuaSession.LoadData(lm.LuaPage) |
|
|
pageData, err := fc.LuaSession.LoadData(lm.LuaPage) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf("Error loading %s for %s.%s: %s\n", lm.Path, lm.ResultPath, lm.ResultKey, err.Error()) |
|
|
logrus.Errorf("Can not load %s for %s.%s: %s", lm.Path, lm.ResultPath, lm.ResultKey, err.Error()) |
|
|
luaCollectErrors.Inc() |
|
|
luaCollectErrors.Inc() |
|
|
fc.LuaSession.SID = "" // clear SID in case of error, so force reauthentication
|
|
|
fc.LuaSession.SID = "" // clear SID in case of error, so force reauthentication
|
|
|
continue |
|
|
continue |
|
@ -468,7 +470,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric, dupCache ma |
|
|
var data map[string]interface{} |
|
|
var data map[string]interface{} |
|
|
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()) |
|
|
logrus.Errorf("Can not parse JSON from %s for %s.%s: %s", lm.Path, lm.ResultPath, lm.ResultKey, err.Error()) |
|
|
luaCollectErrors.Inc() |
|
|
luaCollectErrors.Inc() |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
@ -483,7 +485,7 @@ func (fc *FritzboxCollector) collectLua(ch chan<- prometheus.Metric, dupCache ma |
|
|
metricVals, err := lua.GetMetrics(fc.LabelRenames, *cacheEntry.Result, lm.LuaMetricDef) |
|
|
metricVals, err := lua.GetMetrics(fc.LabelRenames, *cacheEntry.Result, lm.LuaMetricDef) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf("Error getting metric values for %s.%s: %s\n", lm.ResultPath, lm.ResultKey, err.Error()) |
|
|
logrus.Errorf("Can not get metric values for %s.%s: %s", lm.ResultPath, lm.ResultKey, err.Error()) |
|
|
luaCollectErrors.Inc() |
|
|
luaCollectErrors.Inc() |
|
|
cacheEntry.Result = nil // don't use invalid results for cache
|
|
|
cacheEntry.Result = nil // don't use invalid results for cache
|
|
|
continue |
|
|
continue |
|
@ -504,7 +506,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu |
|
|
} else { |
|
|
} else { |
|
|
lval, ok := value.Labels[l] |
|
|
lval, ok := value.Labels[l] |
|
|
if !ok { |
|
|
if !ok { |
|
|
fmt.Printf("%s.%s from %s?%s has no resul for label %s", lm.ResultPath, lm.ResultKey, lm.Path, lm.Params, l) |
|
|
logrus.Warnf("%s.%s from %s?%s has no resul for label %s", lm.ResultPath, lm.ResultKey, lm.Path, lm.Params, l) |
|
|
lval = "" |
|
|
lval = "" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -520,7 +522,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu |
|
|
// check for duplicate labels to prevent collection failure
|
|
|
// check for duplicate labels to prevent collection failure
|
|
|
key := lm.PromDesc.FqName + ":" + lm.PromDesc.fixedLabelValues + strings.Join(labels, ",") |
|
|
key := lm.PromDesc.FqName + ":" + lm.PromDesc.fixedLabelValues + strings.Join(labels, ",") |
|
|
if dupCache[key] { |
|
|
if dupCache[key] { |
|
|
fmt.Printf("%s.%s reported before as: %s\n", lm.ResultPath, lm.ResultPath, key) |
|
|
logrus.Errorf("%s.%s reported before as: %s\n", lm.ResultPath, lm.ResultPath, key) |
|
|
luaCollectErrors.Inc() |
|
|
luaCollectErrors.Inc() |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -528,7 +530,7 @@ func (fc *FritzboxCollector) reportLuaMetric(ch chan<- prometheus.Metric, lm *Lu |
|
|
|
|
|
|
|
|
metric, err := prometheus.NewConstMetric(lm.Desc, lm.MetricType, value.Value, labels...) |
|
|
metric, err := prometheus.NewConstMetric(lm.Desc, lm.MetricType, value.Value, labels...) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf("Error creating metric %s.%s: %s", lm.ResultPath, lm.ResultPath, err.Error()) |
|
|
logrus.Errorf("Can not create metric %s.%s: %s", lm.ResultPath, lm.ResultPath, err.Error()) |
|
|
} else { |
|
|
} else { |
|
|
ch <- metric |
|
|
ch <- metric |
|
|
} |
|
|
} |
|
@ -540,7 +542,7 @@ func test() { |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var newEntry bool = false |
|
|
var newEntry = false |
|
|
var json bytes.Buffer |
|
|
var json bytes.Buffer |
|
|
json.WriteString("[\n") |
|
|
json.WriteString("[\n") |
|
|
|
|
|
|
|
@ -551,7 +553,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) |
|
|
logrus.Infof("Service: %s (Url: %s)\n", k, s.ControlURL) |
|
|
|
|
|
|
|
|
actionKeys := []string{} |
|
|
actionKeys := []string{} |
|
|
for l := range s.Actions { |
|
|
for l := range s.Actions { |
|
@ -560,14 +562,14 @@ func test() { |
|
|
sort.Strings(actionKeys) |
|
|
sort.Strings(actionKeys) |
|
|
for _, l := range actionKeys { |
|
|
for _, l := range actionKeys { |
|
|
a := s.Actions[l] |
|
|
a := s.Actions[l] |
|
|
fmt.Printf(" %s - arguments: variable [direction] (soap name, soap type)\n", a.Name) |
|
|
logrus.Debugf("%s - arguments: variable [direction] (soap name, soap type)", a.Name) |
|
|
for _, arg := range a.Arguments { |
|
|
for _, arg := range a.Arguments { |
|
|
sv := arg.StateVariable |
|
|
sv := arg.StateVariable |
|
|
fmt.Printf(" %s [%s] (%s, %s)\n", arg.RelatedStateVariable, arg.Direction, arg.Name, sv.DataType) |
|
|
logrus.Debugf("%s [%s] (%s, %s)", arg.RelatedStateVariable, arg.Direction, arg.Name, sv.DataType) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if !a.IsGetOnly() { |
|
|
if !a.IsGetOnly() { |
|
|
fmt.Printf(" %s - not calling, since arguments required or no output\n", a.Name) |
|
|
logrus.Debugf("%s - not calling, since arguments required or no output", a.Name) |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -590,16 +592,16 @@ func test() { |
|
|
json.WriteString("\"\n\t}") |
|
|
json.WriteString("\"\n\t}") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fmt.Printf(" %s - calling - results: variable: value\n", a.Name) |
|
|
logrus.Debugf("%s - calling - results: variable: value", a.Name) |
|
|
res, err := a.Call(nil) |
|
|
res, err := a.Call(nil) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf(" FAILED:%s\n", err.Error()) |
|
|
logrus.Warnf("FAILED:%s", err) |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for _, arg := range a.Arguments { |
|
|
for _, arg := range a.Arguments { |
|
|
fmt.Printf(" %s: %v\n", arg.RelatedStateVariable, res[arg.StateVariable.Name]) |
|
|
logrus.Debugf("%s: %v", arg.RelatedStateVariable, res[arg.StateVariable.Name]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -609,7 +611,7 @@ func test() { |
|
|
if *flagJSONOut != "" { |
|
|
if *flagJSONOut != "" { |
|
|
err := ioutil.WriteFile(*flagJSONOut, json.Bytes(), 0644) |
|
|
err := ioutil.WriteFile(*flagJSONOut, json.Bytes(), 0644) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Printf("Failed writing JSON file '%s': %s\n", *flagJSONOut, err.Error()) |
|
|
logrus.Warnf("Failed writing JSON file '%s': %s\n", *flagJSONOut, err.Error()) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -618,14 +620,14 @@ func testLua() { |
|
|
|
|
|
|
|
|
jsonData, err := ioutil.ReadFile("luaTest.json") |
|
|
jsonData, err := ioutil.ReadFile("luaTest.json") |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error reading luaTest.json:", err) |
|
|
logrus.Error("Can not read luaTest.json: ", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var luaTests []LuaTest |
|
|
var luaTests []LuaTest |
|
|
err = json.Unmarshal(jsonData, &luaTests) |
|
|
err = json.Unmarshal(jsonData, &luaTests) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error parsing luaTest JSON:", err) |
|
|
logrus.Error("Can not parse luaTest JSON: ", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -633,19 +635,14 @@ func testLua() { |
|
|
luaSession := lua.LuaSession{BaseURL: *flagGatewayLuaURL, Username: *flagUsername, Password: *flagPassword} |
|
|
luaSession := lua.LuaSession{BaseURL: *flagGatewayLuaURL, Username: *flagUsername, Password: *flagPassword} |
|
|
|
|
|
|
|
|
for _, test := range luaTests { |
|
|
for _, test := range luaTests { |
|
|
fmt.Printf("TESTING: %s (%s)\n", test.Path, test.Params) |
|
|
|
|
|
|
|
|
|
|
|
page := lua.LuaPage{Path: test.Path, Params: test.Params} |
|
|
page := lua.LuaPage{Path: test.Path, Params: test.Params} |
|
|
pageData, err := luaSession.LoadData(page) |
|
|
pageData, err := luaSession.LoadData(page) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println(err.Error()) |
|
|
logrus.Errorf("Testing %s (%s) failed: %s", test.Path, test.Params, err.Error()) |
|
|
} else { |
|
|
} else { |
|
|
fmt.Println(string(pageData)) |
|
|
logrus.Infof("Testing %s(%s) successful: %s", test.Path, test.Params, string(pageData)) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fmt.Println() |
|
|
|
|
|
fmt.Println() |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -664,10 +661,16 @@ func getValueType(vt string) prometheus.ValueType { |
|
|
|
|
|
|
|
|
func main() { |
|
|
func main() { |
|
|
flag.Parse() |
|
|
flag.Parse() |
|
|
|
|
|
level, e := logrus.ParseLevel(*flagLogLevel) |
|
|
|
|
|
if e != nil { |
|
|
|
|
|
logrus.Warnf("Can not parse log level: %s use INFO", e) |
|
|
|
|
|
level = logrus.InfoLevel |
|
|
|
|
|
} |
|
|
|
|
|
logrus.SetLevel(level) |
|
|
|
|
|
|
|
|
u, err := url.Parse(*flagGatewayURL) |
|
|
u, err := url.Parse(*flagGatewayURL) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("invalid URL:", err) |
|
|
logrus.Errorf("invalid URL:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -684,13 +687,13 @@ func main() { |
|
|
// read metrics
|
|
|
// read metrics
|
|
|
jsonData, err := ioutil.ReadFile(*flagMetricsFile) |
|
|
jsonData, err := ioutil.ReadFile(*flagMetricsFile) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error reading metric file:", err) |
|
|
logrus.Errorf("error reading metric file:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
err = json.Unmarshal(jsonData, &metrics) |
|
|
err = json.Unmarshal(jsonData, &metrics) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error parsing JSON:", err) |
|
|
logrus.Errorf("error parsing JSON:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -702,14 +705,14 @@ func main() { |
|
|
if !*flagDisableLua { |
|
|
if !*flagDisableLua { |
|
|
jsonData, err := ioutil.ReadFile(*flagLuaMetricsFile) |
|
|
jsonData, err := ioutil.ReadFile(*flagLuaMetricsFile) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error reading lua metric file:", err) |
|
|
logrus.Error("error reading lua metric file:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var lmf *LuaMetricsFile |
|
|
var lmf *LuaMetricsFile |
|
|
err = json.Unmarshal(jsonData, &lmf) |
|
|
err = json.Unmarshal(jsonData, &lmf) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error parsing lua JSON:", err) |
|
|
logrus.Error("error parsing lua JSON:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -722,7 +725,7 @@ func main() { |
|
|
regex, err := regexp.Compile(ren.MatchRegex) |
|
|
regex, err := regexp.Compile(ren.MatchRegex) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
fmt.Println("error compiling lua rename regex:", err) |
|
|
logrus.Error("error compiling lua rename regex:", err) |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -819,14 +822,14 @@ func main() { |
|
|
prometheus.MustRegister(luaCollectErrors) |
|
|
prometheus.MustRegister(luaCollectErrors) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fmt.Println("collecting metrics via http") |
|
|
logrus.Infof("collecting metrics via http") |
|
|
|
|
|
|
|
|
// simulate HTTP request without starting actual http server
|
|
|
// simulate HTTP request without starting actual http server
|
|
|
writer := testResponseWriter{header: http.Header{}} |
|
|
writer := testResponseWriter{header: http.Header{}} |
|
|
request := http.Request{} |
|
|
request := http.Request{} |
|
|
promhttp.Handler().ServeHTTP(&writer, &request) |
|
|
promhttp.Handler().ServeHTTP(&writer, &request) |
|
|
|
|
|
|
|
|
fmt.Println(writer.String()) |
|
|
logrus.Infof("Response:\n\n%s", writer.String()) |
|
|
|
|
|
|
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
@ -845,7 +848,7 @@ func main() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
http.Handle("/metrics", promhttp.Handler()) |
|
|
http.Handle("/metrics", promhttp.Handler()) |
|
|
fmt.Printf("metrics available at http://%s/metrics\n", *flagAddr) |
|
|
logrus.Infof("metrics available at http://%s/metrics", *flagAddr) |
|
|
|
|
|
|
|
|
log.Fatal(http.ListenAndServe(*flagAddr, nil)) |
|
|
logrus.Error(http.ListenAndServe(*flagAddr, nil)) |
|
|
} |
|
|
} |
|
|