-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ralfonso-directnic
committed
May 13, 2020
0 parents
commit 95a8e46
Showing
7 changed files
with
879 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# cPanel Exporter for Prometheus | ||
|
||
|
||
Exports cPanel metrics to prometheus | ||
|
||
|
||
## Flags | ||
|
||
There are no flags at this time | ||
|
||
|
||
## Collectors | ||
|
||
``` | ||
# HELP cpanel_bandwidth cPanel Metadata | ||
# TYPE cpanel_bandwidth gauge | ||
cpanel_bandwidth{user="aaaa"} 5.248831472e+10 | ||
# HELP cpanel_domains_configured Current Domains and Subdomains setup | ||
# TYPE cpanel_domains_configured gauge | ||
cpanel_domains_configured 375 | ||
# HELP cpanel_ftp_accounts cPanel FTP Accounts | ||
# TYPE cpanel_ftp_accounts gauge | ||
cpanel_ftp_accounts 119 | ||
# HELP cpanel_mailboxes_configured cPanel Mailboxes | ||
# TYPE cpanel_mailboxes_configured gauge | ||
cpanel_mailboxes_configured 27 | ||
# HELP cpanel_meta cPanel Metadata | ||
# TYPE cpanel_meta counter | ||
cpanel_meta{release="release",version="86.0 (build 19)"} 0 | ||
# HELP cpanel_plans cPanel Metadata | ||
# TYPE cpanel_plans gauge | ||
cpanel_plans{plan="DELUXE"} 9 | ||
cpanel_plans{plan="LITE"} 5 | ||
cpanel_plans{plan="PRO"} 3 | ||
# HELP cpanel_quota cPanel Disk Quota Percent | ||
# TYPE cpanel_quota gauge | ||
cpanel_quota{user="aaaa"} 8 | ||
cpanel_quota{user="bbbb"} 100 | ||
# HELP cpanel_sessions_email cPanel webmail session | ||
# TYPE cpanel_sessions_email gauge | ||
cpanel_sessions_email 17 | ||
# HELP cpanel_sessions_web cPanel session | ||
# TYPE cpanel_sessions_web gauge | ||
cpanel_sessions_web 10 | ||
# HELP cpanel_users_active Current Active Users | ||
# TYPE cpanel_users_active gauge | ||
cpanel_users_active 17 | ||
# HELP cpanel_users_suspended Current Active Users | ||
# TYPE cpanel_users_suspended gauge | ||
cpanel_users_suspended 6 | ||
``` | ||
|
||
|
||
|
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
package main | ||
|
||
import( | ||
"net/http" | ||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
"github.com/prometheus/client_golang/prometheus/promhttp" | ||
"time" | ||
"flag" | ||
"path/filepath" | ||
"log" | ||
|
||
) | ||
|
||
|
||
|
||
var port string | ||
|
||
|
||
var ( | ||
//reg = prometheus.NewRegistry() | ||
|
||
// reg.MustRegister(version.NewCollector("cpanel_exporter")) | ||
// if err := r.Register(nc); err != nil { | ||
// return nil, fmt.Errorf("couldn't register node collector: %s", err)// | ||
// } | ||
|
||
//factory = promauto.With(reg) | ||
|
||
activeUsers = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "cpanel_users_active", | ||
Help: "Current Active Users", | ||
}) | ||
|
||
suspendedUsers = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "cpanel_users_suspended", | ||
Help: "Current Active Users", | ||
}) | ||
|
||
domainsConfigured = promauto.NewGauge(prometheus.GaugeOpts{ | ||
Name: "cpanel_domains_configured", | ||
Help: "Current Domains and Subdomains setup", | ||
}) | ||
|
||
|
||
//requestCount.WithLabelValues().Add | ||
//requestCount.With(prometheus.Labels{"type": "delete", "user": "alice"}).Inc() | ||
|
||
cpanelMeta = promauto.NewCounterVec( | ||
prometheus.CounterOpts{ | ||
Name: "cpanel_meta", | ||
Help: "cPanel Metadata", | ||
}, | ||
[]string{"version","release"}, | ||
) | ||
|
||
|
||
|
||
|
||
cpanelPlans = promauto.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_plans", | ||
Help: "cPanel Plans Configured", | ||
}, | ||
[]string{"plan"}, | ||
) | ||
|
||
|
||
cpanelBandwidth = promauto.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_bandwidth", | ||
Help: "cPanel Bandwidth Used", | ||
}, | ||
[]string{"user"}, | ||
) | ||
|
||
cpanelQuota = promauto.NewGaugeVec( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_quota", | ||
Help: "cPanel Quota Percent Used", | ||
}, | ||
[]string{"user"}, | ||
) | ||
|
||
cpanelMailboxes = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_mailboxes_configured", | ||
Help: "cPanel Mailboxes", | ||
}, | ||
) | ||
|
||
cpanelFTP = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_ftp_accounts", | ||
Help: "cPanel FTP Accounts", | ||
}, | ||
) | ||
|
||
cpanelSessionsEmail = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_sessions_email", | ||
Help: "cPanel Webmail Session", | ||
}, | ||
|
||
) | ||
|
||
cpanelSessionsWeb = promauto.NewGauge( | ||
prometheus.GaugeOpts{ | ||
Name: "cpanel_sessions_web", | ||
Help: "cPanel Admin Sessions", | ||
}, | ||
|
||
) | ||
) | ||
|
||
|
||
func fetchMetrics(){ | ||
|
||
for _ = range time.Tick(1*time.Minute) { | ||
|
||
runMetrics() | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
func fetchUapiMetrics() { | ||
|
||
|
||
for _ = range time.Tick(15*time.Minute) { | ||
|
||
|
||
//these are heavier | ||
runUapiMetrics() | ||
|
||
} | ||
} | ||
|
||
func runUapiMetrics(){ | ||
|
||
|
||
for _,u := range getUsernames() { | ||
|
||
us := filepath.Base(u) | ||
|
||
bw := getBandwidth(us) | ||
|
||
cpanelBandwidth.With(prometheus.Labels{"user": us }).Set(float64(bw)) | ||
|
||
_,_,perc := getQuota(us) | ||
|
||
cpanelQuota.With(prometheus.Labels{"user": us }).Set(perc) | ||
} | ||
|
||
} | ||
|
||
func runMetrics(){ | ||
|
||
users := getUsers("") | ||
|
||
suspended := getUsers("suspended") | ||
|
||
vers := cpanelVersion() | ||
|
||
plans := getPlans() | ||
|
||
domains := getDomains() | ||
|
||
domains_ct := len(domains) | ||
|
||
wsess := getSessions("web") | ||
|
||
esess := getSessions("email") | ||
|
||
emails := getEmails() | ||
|
||
domainsConfigured.Set(float64(domains_ct)) | ||
|
||
cpanelFTP.Set(float64(len(getFTP()))) | ||
|
||
activeUsers.Set(float64(users)) | ||
|
||
cpanelMailboxes.Set(float64(len(emails))) | ||
|
||
suspendedUsers.Set(float64(suspended)) | ||
|
||
cpanelMeta.With(prometheus.Labels{"version": vers, "release": getRelease() }) | ||
|
||
cpanelSessionsEmail.Set(float64(esess)) | ||
cpanelSessionsWeb.Set(float64(wsess)) | ||
|
||
for p,ct := range plans { | ||
|
||
cpanelPlans.With(prometheus.Labels{"plan": p }).Set(float64(ct)) | ||
} | ||
|
||
|
||
|
||
} | ||
|
||
|
||
func main(){ | ||
|
||
log.SetFlags(log.LstdFlags | log.Lshortfile) | ||
|
||
flag.StringVar(&port, "port", "59117", "Metrics Port") | ||
flag.Parse() | ||
|
||
go runMetrics() | ||
go runUapiMetrics() | ||
|
||
go fetchMetrics() | ||
go fetchUapiMetrics() | ||
|
||
http.Handle("/metrics", promhttp.Handler()) | ||
http.ListenAndServe(":"+port, nil) | ||
|
||
} |
Oops, something went wrong.