Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions cmd/scollector/collectors/fastly.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import (
"net/http"
"net/url"
"reflect"
"regexp"
"strconv"
"time"

"bosun.org/cmd/scollector/conf"
"bosun.org/metadata"
"bosun.org/opentsdb"
"bosun.org/slog"
"github.com/bosun-monitor/statusio"
)

func init() {
Expand All @@ -34,6 +36,15 @@ func init() {
name: "c_fastly_billing",
Interval: time.Minute * 5,
})
if f.StatusBaseAddr != "" {
collectors = append(collectors, &IntervalCollector{
F: func() (opentsdb.MultiDataPoint, error) {
return c_fastly_status(f.StatusBaseAddr)
},
name: "c_fastly_status",
Interval: time.Minute * 1,
})
}
}
})
}
Expand All @@ -50,8 +61,89 @@ const (
fastlyBillingBeforeDiscountDesc = "The total incurred cost plus extras cost this month."
fastlyBillingDiscountDesc = "The calculated discount rate this month."
fastlyBillingCostDesc = "The final amount to be paid this month."

fastlyStatusPrefix = "fastly.status."
fastlyComponentStatusDesc = "The current status of the %v. 0: Operational, 1: Degraded Performance, 2: Partial Outage, 3: Major Outage." // see iota for statusio.ComponentStatus
fastlyScheduledMaintDesc = "The number of currently scheduled maintenances. Does not include maintenance that is current active"
fastlyActiveScheduledMaintDesc = "The number of currently scheduled maintenances currently in progress. Includes the 'in_progress' and 'verifying'"
fastlyActiveIncidentDesc = "The number of currently active incidents. Includes the 'investingating', 'identified', and 'monitoring' states."
)

var (
fastlyStatusPopRegex = regexp.MustCompile(`(.*)\(([A-Z]{3})\)`) // i.e. Miami (MIA)
)

func c_fastly_status(baseAddr string) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
c := statusio.NewClient(baseAddr)
summary, err := c.GetSummary()
if err != nil {
return md, err
}

// Process Components (Pops, Support Systems)
for _, comp := range summary.Components {
match := fastlyStatusPopRegex.FindAllStringSubmatch(comp.Name, 1)
if len(match) != 0 && len(match[0]) == 3 { // We have a pop
//name := match[0][1]
code := match[0][2]
tagSet := opentsdb.TagSet{"code": code}
Add(&md, fastlyStatusPrefix+"pop", int(comp.Status), tagSet, metadata.Gauge, metadata.StatusCode, fmt.Sprintf(fastlyComponentStatusDesc, "pop"))
continue
}
// Must be service component
tagSet := opentsdb.TagSet{"service": comp.Name}
Add(&md, fastlyStatusPrefix+"service", int(comp.Status), tagSet, metadata.Gauge, metadata.StatusCode, fmt.Sprintf(fastlyComponentStatusDesc, "service"))
}

// Scheduled Maintenance
scheduledMaintByImpact := make(map[statusio.StatusIndicator]int)
activeScheduledMaintByImpact := make(map[statusio.StatusIndicator]int)
// Make Maps
for _, si := range statusio.StatusIndicatorValues {
scheduledMaintByImpact[si] = 0
activeScheduledMaintByImpact[si] = 0
}
// Group by scheduled vs inprogress/verifying
for _, maint := range summary.ScheduledMaintenances {
switch maint.Status {
case statusio.Scheduled:
scheduledMaintByImpact[maint.Impact]++
case statusio.InProgress, statusio.Verifying:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth logging in a default case? What happens if they add a new status?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the unmarshal will err since it maps to the enum
On May 16, 2016 11:50 AM, "Craig Peterson" [email protected] wrote:

In cmd/scollector/collectors/fastly.go
#1735 (comment):

  • }
  • // Scheduled Maintenance
  • scheduledMaintByImpact := make(map[statusio.StatusIndicator]int)
  • activeScheduledMaintByImpact := make(map[statusio.StatusIndicator]int)
  • // Make Maps
  • for _, si := range statusio.StatusIndicatorValues {
  •   scheduledMaintByImpact[si] = 0
    
  •   activeScheduledMaintByImpact[si] = 0
    
  • }
  • // Group by scheduled vs inprogress/verifying
  • for _, maint := range summary.ScheduledMaintenances {
  •   switch maint.Status {
    
  •   case statusio.Scheduled:
    
  •       scheduledMaintByImpact[maint.Impact]++
    
  •   case statusio.InProgress, statusio.Verifying:
    

Is it worth logging in a default case? What happens if they add a new
status?


You are receiving this because you authored the thread.
Reply to this email directly or view it on GitHub
https://github.com/bosun-monitor/bosun/pull/1735/files/4140b74063d86880349236feeea6458422e69be5#r63375879

activeScheduledMaintByImpact[maint.Impact]++
}
}
for impact, count := range scheduledMaintByImpact {
tagSet := opentsdb.TagSet{"impact": fmt.Sprint(impact)}
Add(&md, fastlyStatusPrefix+"scheduled_maint_count", count, tagSet, metadata.Gauge, metadata.Count, fastlyScheduledMaintDesc)
}
for impact, count := range activeScheduledMaintByImpact {
tagSet := opentsdb.TagSet{"impact": fmt.Sprint(impact)}
Add(&md, fastlyStatusPrefix+"in_progress_maint_count", count, tagSet, metadata.Gauge, metadata.Count, fastlyActiveScheduledMaintDesc)
}

// Incidents
// Make Map
incidentsByImpact := make(map[statusio.StatusIndicator]int)
for _, si := range statusio.StatusIndicatorValues {
incidentsByImpact[si] = 0
}
for _, incident := range summary.Incidents {
switch incident.Status {
case statusio.Investigating, statusio.Identified, statusio.Monitoring:
incidentsByImpact[incident.Impact]++
default:
continue
}
}
for impact, count := range incidentsByImpact {
tagSet := opentsdb.TagSet{"impact": fmt.Sprint(impact)}
Add(&md, fastlyStatusPrefix+"active_incident_count", count, tagSet, metadata.Gauge, metadata.Incident, fastlyActiveIncidentDesc)
}

return md, nil
}

func c_fastly_billing(c fastlyClient) (opentsdb.MultiDataPoint, error) {
var md opentsdb.MultiDataPoint
now := time.Now().UTC()
Expand Down
3 changes: 2 additions & 1 deletion cmd/scollector/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ type GoogleAnalytics struct {
}

type Fastly struct {
Key string
Key string
StatusBaseAddr string
}

type GoogleAnalyticsSite struct {
Expand Down
1 change: 1 addition & 0 deletions metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
Fraction = "fraction"
Get = "gets"
GetExists = "get exists"
Incident = "incidents"
Interupt = "interupts"
InProgress = "in progress"
Item = "items"
Expand Down
21 changes: 21 additions & 0 deletions vendor/github.com/bosun-monitor/statusio/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading