Example #1
0
func main() {
	hsperfdata_path, err := hsperfdata.GetHSPerfDataPath(os.Args[1])
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("perfdata path: %s\n", hsperfdata_path)

	f, err := os.Open(hsperfdata_path)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()

	prologue, err := hsperfdata.ReadPrologue(f)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("Magic: 0x%x\n", prologue.Magic)
	fmt.Printf("ByteOrder: %d\n", prologue.ByteOrder)
	fmt.Printf("MajorVersion: %d\n", prologue.MajorVersion)
	fmt.Printf("MinorVersion: %d\n", prologue.MinorVersion)
	fmt.Printf("Accessible: %d\n", prologue.Accessible)
	fmt.Printf("Used: %d\n", prologue.Used)
	fmt.Printf("Overflow: %d\n", prologue.Overflow)
	fmt.Printf("ModTimeStamp: %d\n", prologue.ModTimeStamp)
	fmt.Printf("EntryOffset: %d\n", prologue.EntryOffset)
	fmt.Printf("NumEntries: %d\n", prologue.NumEntries)

	f.Seek(int64(prologue.EntryOffset), os.SEEK_SET)

	entries, err := hsperfdata.ReadPerfEntry(f, prologue)
	if err != nil {
		log.Fatal(err)
	}

	var i int32
	for i = 0; i < prologue.NumEntries; i++ {
		fmt.Printf("[%d]: %c %s\n", i, entries[i].DataType, entries[i].EntryName)

		if entries[i].DataType == 'B' {
			fmt.Printf("  -> \"%s\"\n", entries[i].StringValue)
		} else {
			fmt.Printf("  -> %d\n", entries[i].LongValue)
		}

	}

}
Example #2
0
func (this *HSBeat) getAndPublish(b *beat.Beat) error {
	f, err := os.Open(this.HSPerfDataPath)
	if err != nil {
		return err
	}
	defer f.Close()

	prologue, err := hsperfdata.ReadPrologue(f)
	if err != nil {
		return err
	}

	f.Seek(int64(prologue.EntryOffset), os.SEEK_SET)

	entries, err := hsperfdata.ReadPerfEntry(f, prologue)
	if err != nil {
		return err
	}

	var i int32
	timestamp := common.Time(time.Now())

	for i = 0; i < prologue.NumEntries; i++ {
		event := common.MapStr{"@timestamp": timestamp,
			"type": "hsbeat",
			"pid":  this.Pid}

		event["name"] = entries[i].EntryName
		event["data_type"] = entries[i].DataType
		event["val_string"] = entries[i].StringValue
		event["val_long"] = entries[i].LongValue

		b.Events.PublishEvent(event)
	}

	return nil
}