()
| 28 | ) |
| 29 | |
| 30 | func RegisterPrometheusCommand() *cobra.Command { |
| 31 | cmd := &cobra.Command{ |
| 32 | Use: "prometheus", |
| 33 | Short: "prometheus operation commands", |
| 34 | Run: func(cmd *cobra.Command, args []string) { |
| 35 | fmt.Printf("please run with 'cache | cleaner'.\n") |
| 36 | }, |
| 37 | } |
| 38 | |
| 39 | var t string |
| 40 | cacheCmd := &cobra.Command{ |
| 41 | Use: "cache", |
| 42 | Short: "pull prometheus cache data from deepflow-server", |
| 43 | Example: "deepflow-ctl prometheus cache -t metric-name", |
| 44 | Run: func(cmd *cobra.Command, args []string) { |
| 45 | if err := prometheusCache(cmd, t); err != nil { |
| 46 | fmt.Println(err) |
| 47 | } |
| 48 | }, |
| 49 | } |
| 50 | cacheCmd.Flags().StringVarP(&t, "type", "t", "all", "cache type, options: all, metric-name, label-name, "+ |
| 51 | "label-value, metric-and-app-layout, target, label, metric-label, metric-target") |
| 52 | cmd.AddCommand(cacheCmd) |
| 53 | |
| 54 | var expiredAt string |
| 55 | clearCmd := &cobra.Command{ |
| 56 | Use: "clear", |
| 57 | Short: "clear prometheus data in MySQL by deepflow-server, use with caution and not frequently!", |
| 58 | Example: "deepflow-ctl prometheus clear -e \"2006-01-02 15:04:05\"", |
| 59 | Run: func(cmd *cobra.Command, args []string) { |
| 60 | prometheusClear(cmd, expiredAt) |
| 61 | }, |
| 62 | } |
| 63 | clearCmd.Flags().StringVarP(&expiredAt, "expired-time", "e", "", "expired-time format: 2006-01-02 15:04:05") |
| 64 | cmd.AddCommand(clearCmd) |
| 65 | |
| 66 | return cmd |
| 67 | } |
| 68 | |
| 69 | func prometheusCache(cmd *cobra.Command, t string) error { |
| 70 | conn := getConn(cmd) |
no test coverage detected