Пример #1
0
func NmonListMeasurement(c *cli.Context) {
	// parsing parameters
	params := ParseParameters(c)

	influxdb := influxdbclient.NewInfluxDB(params.Server, params.Port, params.Db, params.User, params.Password)
	influxdb.SetDebug(params.Debug)
	influxdb.Connect()

	filters := new(influxdbclient.Filters)

	if len(params.Host) > 0 {
		filters.Add("host", params.Host, "text")
	}

	measurements, _ := influxdb.ListMeasurement(filters)
	if measurements != nil {
		fmt.Printf("%s\n", measurements.Name)
		for _, value := range measurements.Datas {
			if len(params.Filter) == 0 {
				fmt.Printf("%s\n", value)
				continue
			}
			matched, _ := regexp.MatchString(params.Filter, value)
			if matched {
				fmt.Printf("%s\n", value)
			}
		}
	}
}
Пример #2
0
func NmonStat(c *cli.Context) {
	// parsing parameters
	params := ParseStatsParameters(c)

	if len(params.Metric) == 0 {
		fmt.Printf("No metric specified ! Use -h option for help !\n")
		os.Exit(1)
	}

	influxdb := influxdbclient.NewInfluxDB(params.Server, params.Port, params.Db, params.User, params.Password)
	influxdb.SetDebug(params.Debug)
	influxdb.Connect()

	metric := params.Metric

	filters := new(influxdbclient.Filters)

	filters.Add("host", params.StatsHost, "text")

	if len(params.Filter) > 0 {
		filters.Add("name", params.Filter, "regexp")
	}
	fromUnix, _ := ConvertTimeStamp(params.From, params.TZ)
	fromTime := fromUnix.Format(querytimeformat)
	toUnix, _ := ConvertTimeStamp(params.To, params.TZ)
	toTime := toUnix.Format(querytimeformat)
	result, err := influxdb.ReadPoints("value", filters, "name", metric, fromTime, toTime, "")
	if err != nil {
		check(err)
	}

	//generate stats
	stats := influxdbclient.BuildStats(result)

	DisplayStats(&stats, params.Sort, params.Limit)
}